- [+] bug: constant redraws when walking in dark levels.
- [+] it is because makelitradius is calling setlosdirty. and when you do setlosdirty(player), it redraws! - [+] solution: disable all redraws during calclight(), then afterward reenable them!! - [+] found two maps. read the first one. now reading the second one doesn't identify it (make because isknown is now true!) - [+] plants still being counted as "helpless" - [+] combine all save data into 1 file - [+] gamesave.dat - [+] mapxxx.dat - [+] regions.dat - [+] rename elf to "Selnor"
This commit is contained in:
parent
584d1e8681
commit
3a671253a1
2
data.c
2
data.c
|
@ -7400,7 +7400,7 @@ void initrace(void) {
|
||||||
addflag(lastrace->flags, F_WANTSOBFLAG, F_GEM, NA, NA, NULL);
|
addflag(lastrace->flags, F_WANTSOBFLAG, F_GEM, NA, NA, NULL);
|
||||||
|
|
||||||
|
|
||||||
addrace(R_ELF, "elf", 60, '@', C_GREEN, MT_FLESH, RC_HUMANOID, "Elves are slender, graceful beings around human-sized but far nimbler. They have high intelligence and magical affinity, but a lack of physical strength. Elves meditate instead of sleeping, thus maintaining basic awareness.");
|
addrace(R_ELF, "selnor", 60, '@', C_GREEN, MT_FLESH, RC_HUMANOID, "The Selnor race are slender, graceful beings around human-sized but far nimbler. They have high intelligence and magical affinity, but lack physical strength. The Selnor meditate instead of sleeping, thus maintaining basic awareness.");
|
||||||
setbodytype(lastrace, BT_HUMANOID);
|
setbodytype(lastrace, BT_HUMANOID);
|
||||||
addflag(lastrace->flags, F_PLAYABLE, B_TRUE, NA, NA, NULL);
|
addflag(lastrace->flags, F_PLAYABLE, B_TRUE, NA, NA, NULL);
|
||||||
addflag(lastrace->flags, F_STARTATT, A_STR, AT_LTAVERAGE, NA, NULL);
|
addflag(lastrace->flags, F_STARTATT, A_STR, AT_LTAVERAGE, NA, NULL);
|
||||||
|
|
1
defs.h
1
defs.h
|
@ -304,7 +304,6 @@ enum TRADEINFOTYPE {
|
||||||
#define MAXPNAMELEN 12 // max player name length
|
#define MAXPNAMELEN 12 // max player name length
|
||||||
// file i/o
|
// file i/o
|
||||||
#define DATADIR "data"
|
#define DATADIR "data"
|
||||||
#define MAPDIR "data/maps"
|
|
||||||
#define SAVEDIR "data/save"
|
#define SAVEDIR "data/save"
|
||||||
#define VAULTDIR "vaults"
|
#define VAULTDIR "vaults"
|
||||||
// rank, score, name, job, killer
|
// rank, score, name, job, killer
|
||||||
|
|
2
lf.c
2
lf.c
|
@ -11029,7 +11029,7 @@ int ishelplessvictim(lifeform_t *victim, lifeform_t *attacker, enum HELPLESSTYPE
|
||||||
if (isfleeing(victim)) {
|
if (isfleeing(victim)) {
|
||||||
if (how) *how = HL_FLEEING;
|
if (how) *how = HL_FLEEING;
|
||||||
return B_TRUE;
|
return B_TRUE;
|
||||||
} else if (!cansee(victim, attacker)) {
|
} else if (!cansee(victim, attacker) && (getraceclass(victim) != RC_PLANT)) {
|
||||||
if (how) *how = HL_CANTSEE;
|
if (how) *how = HL_CANTSEE;
|
||||||
return B_TRUE;
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
|
|
32
map.c
32
map.c
|
@ -45,6 +45,7 @@ extern enum ERROR reason;
|
||||||
extern enum GAMEMODE gamemode;
|
extern enum GAMEMODE gamemode;
|
||||||
|
|
||||||
extern int needredraw;
|
extern int needredraw;
|
||||||
|
extern int noredraw;
|
||||||
|
|
||||||
extern long curtime;
|
extern long curtime;
|
||||||
|
|
||||||
|
@ -702,6 +703,14 @@ region_t *addregion(enum REGIONTYPE rtype, region_t *parent, int outlineid, int
|
||||||
|
|
||||||
regionoutline_t *addregionoutline(enum REGIONTYPE rtype) {
|
regionoutline_t *addregionoutline(enum REGIONTYPE rtype) {
|
||||||
regionoutline_t *a;
|
regionoutline_t *a;
|
||||||
|
int nextid;
|
||||||
|
|
||||||
|
// calculate next region outline id
|
||||||
|
if (!lastregionoutline) { // ie. this is the first one to be created
|
||||||
|
nextid = 0;
|
||||||
|
} else {
|
||||||
|
nextid = lastregionoutline->id + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// add to the end of the list
|
// add to the end of the list
|
||||||
if (firstregionoutline == NULL) {
|
if (firstregionoutline == NULL) {
|
||||||
|
@ -719,11 +728,7 @@ regionoutline_t *addregionoutline(enum REGIONTYPE rtype) {
|
||||||
a->next = NULL;
|
a->next = NULL;
|
||||||
|
|
||||||
// props
|
// props
|
||||||
if (a == firstregionoutline) {
|
a->id = nextid;
|
||||||
a->id = 0;
|
|
||||||
} else {
|
|
||||||
a->id = lastregionoutline->id + 1;
|
|
||||||
}
|
|
||||||
a->rtype = findregiontype(rtype);
|
a->rtype = findregiontype(rtype);
|
||||||
a->nthings = 0;
|
a->nthings = 0;
|
||||||
return a;
|
return a;
|
||||||
|
@ -1683,6 +1688,9 @@ void calclight(map_t *map) {
|
||||||
cell_t *c;
|
cell_t *c;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
// disable screen redraws
|
||||||
|
noredraw = B_TRUE;
|
||||||
|
|
||||||
// remember lit values for cells in player's los
|
// remember lit values for cells in player's los
|
||||||
if (gamemode == GM_GAMESTARTED) {
|
if (gamemode == GM_GAMESTARTED) {
|
||||||
for (i = 0; i < player->nlos; i++) {
|
for (i = 0; i < player->nlos; i++) {
|
||||||
|
@ -1743,7 +1751,10 @@ void calclight(map_t *map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
// re-enable screen redraws
|
||||||
|
noredraw = B_FALSE;
|
||||||
|
|
||||||
// did any lit values within player's los change?
|
// did any lit values within player's los change?
|
||||||
if (gamemode == GM_GAMESTARTED) {
|
if (gamemode == GM_GAMESTARTED) {
|
||||||
int dolos = B_FALSE;
|
int dolos = B_FALSE;
|
||||||
|
@ -1757,7 +1768,8 @@ void calclight(map_t *map) {
|
||||||
setlosdirty(player);
|
setlosdirty(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int calcroompos(map_t *map, int w, int h, int xmargin, int ymargin, int *bx, int *by, int force) {
|
int calcroompos(map_t *map, int w, int h, int xmargin, int ymargin, int *bx, int *by, int force) {
|
||||||
|
@ -6015,7 +6027,6 @@ object_t *hastrailof(obpile_t *op, lifeform_t *lf, enum OBTYPE oid, flag_t **tfl
|
||||||
|
|
||||||
|
|
||||||
void initmap(void) {
|
void initmap(void) {
|
||||||
int vx[4],vy[4],i;
|
|
||||||
// habitats
|
// habitats
|
||||||
// thingchance, obchance, vaultchance, maxvisrange
|
// thingchance, obchance, vaultchance, maxvisrange
|
||||||
addhabitat(H_DUNGEON, "dungeon", CT_CORRIDOR, CT_WALL, 3, 50, 30, 6);
|
addhabitat(H_DUNGEON, "dungeon", CT_CORRIDOR, CT_WALL, 3, 50, 30, 6);
|
||||||
|
@ -6060,6 +6071,11 @@ void initmap(void) {
|
||||||
addregiontype(RG_SEWER, "A Sewer", B_FALSE, H_SEWER, 1, 0, D_NONE, B_FALSE, 2);
|
addregiontype(RG_SEWER, "A Sewer", B_FALSE, H_SEWER, 1, 0, D_NONE, B_FALSE, 2);
|
||||||
addregiontype(RG_STOMACH, "A Stomach", B_FALSE, H_STOMACH, 1, 0, D_NONE, B_FALSE, 0);
|
addregiontype(RG_STOMACH, "A Stomach", B_FALSE, H_STOMACH, 1, 0, D_NONE, B_FALSE, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initmaplayout(void) {
|
||||||
|
int vx[4],vy[4],i;
|
||||||
// MAPMAPMAPMAP
|
// MAPMAPMAPMAP
|
||||||
// region definitions (outlines)
|
// region definitions (outlines)
|
||||||
addregionoutline(RG_WORLDMAP);
|
addregionoutline(RG_WORLDMAP);
|
||||||
|
|
1
map.h
1
map.h
|
@ -125,6 +125,7 @@ int hasknownobject(cell_t *c);
|
||||||
int hasobject(cell_t *c);
|
int hasobject(cell_t *c);
|
||||||
object_t *hastrailof(obpile_t *op, lifeform_t *lf, enum OBTYPE oid, flag_t **tflag, lifeform_t *viewer);
|
object_t *hastrailof(obpile_t *op, lifeform_t *lf, enum OBTYPE oid, flag_t **tflag, lifeform_t *viewer);
|
||||||
void initmap(void);
|
void initmap(void);
|
||||||
|
void initmaplayout(void);
|
||||||
int isadjacent(cell_t *src, cell_t *dst);
|
int isadjacent(cell_t *src, cell_t *dst);
|
||||||
int isdark(cell_t *c);
|
int isdark(cell_t *c);
|
||||||
int isdiggable(cell_t *c);
|
int isdiggable(cell_t *c);
|
||||||
|
|
17
nexus.c
17
nexus.c
|
@ -120,6 +120,7 @@ int main(int argc, char **argv) {
|
||||||
char welcomemsg[BUFLEN];
|
char welcomemsg[BUFLEN];
|
||||||
int ch;
|
int ch;
|
||||||
FILE *playerfile = NULL;
|
FILE *playerfile = NULL;
|
||||||
|
int foundsavegame = B_FALSE;
|
||||||
int x,y,i;
|
int x,y,i;
|
||||||
cell_t *c,*targc;
|
cell_t *c,*targc;
|
||||||
vault_t *v;
|
vault_t *v;
|
||||||
|
@ -151,8 +152,8 @@ int main(int argc, char **argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load whatever maps are available
|
// load savegame, if available
|
||||||
loadall();
|
foundsavegame = loadall();
|
||||||
|
|
||||||
// init graphics
|
// init graphics
|
||||||
initgfx();
|
initgfx();
|
||||||
|
@ -174,8 +175,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if no player (ie. didn't load a game), add them
|
// if we didn't load a game, add the player
|
||||||
if (!player) {
|
if (!foundsavegame) {
|
||||||
char *user,pname[BUFLEN],buf[BUFLEN];
|
char *user,pname[BUFLEN],buf[BUFLEN];
|
||||||
job_t *j = NULL;
|
job_t *j = NULL;
|
||||||
race_t *startrace = NULL;
|
race_t *startrace = NULL;
|
||||||
|
@ -187,6 +188,9 @@ int main(int argc, char **argv) {
|
||||||
region_t *wregion, *dregion,*hregion;
|
region_t *wregion, *dregion,*hregion;
|
||||||
map_t *dmap,*surfmap;
|
map_t *dmap,*surfmap;
|
||||||
|
|
||||||
|
// create the dungeon layout
|
||||||
|
initmaplayout();
|
||||||
|
|
||||||
// populate scroll, potion, etc names
|
// populate scroll, potion, etc names
|
||||||
genhiddennames();
|
genhiddennames();
|
||||||
|
|
||||||
|
@ -479,7 +483,6 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// start game - this will cause debug messages to now
|
// start game - this will cause debug messages to now
|
||||||
// go to the log file instead of stdout.
|
// go to the log file instead of stdout.
|
||||||
|
|
||||||
timeleft = 0; // reset game timer
|
timeleft = 0; // reset game timer
|
||||||
|
|
||||||
enteringmap = B_FALSE; // no time passes for lfs on a different map to the player.
|
enteringmap = B_FALSE; // no time passes for lfs on a different map to the player.
|
||||||
|
@ -1147,14 +1150,12 @@ int init(void) {
|
||||||
initskills();
|
initskills();
|
||||||
initjobs();
|
initjobs();
|
||||||
initrace();
|
initrace();
|
||||||
|
initmap();
|
||||||
|
|
||||||
// open log file (want to do this before digging the first map)
|
// open log file (want to do this before digging the first map)
|
||||||
logfile = fopen("log.txt","wt");
|
logfile = fopen("log.txt","wt");
|
||||||
fprintf(logfile, "\n\n\n====== NEW LOGFILE ====\n");
|
fprintf(logfile, "\n\n\n====== NEW LOGFILE ====\n");
|
||||||
|
|
||||||
// create the dungeon layout
|
|
||||||
initmap();
|
|
||||||
|
|
||||||
validatehiddennames();
|
validatehiddennames();
|
||||||
|
|
||||||
|
|
||||||
|
|
13
objects.c
13
objects.c
|
@ -1255,6 +1255,10 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes
|
||||||
god = getrandomgod();
|
god = getrandomgod();
|
||||||
if (god) {
|
if (god) {
|
||||||
addflag(o->flags, F_LINKGOD, god->race->id, NA, NA, NULL);
|
addflag(o->flags, F_LINKGOD, god->race->id, NA, NA, NULL);
|
||||||
|
} else {
|
||||||
|
if (gamemode == GM_GAMESTARTED) {
|
||||||
|
msg("DB: created abandoned temple"); more();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10438,9 +10442,10 @@ int readsomething(lifeform_t *lf, object_t *o) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isknown(o) && willid) {
|
if (willid &&
|
||||||
|
(!isknown(o) || ((o->type->id == OT_MAP) && !isidentified(o)) ) ) {
|
||||||
// id the object
|
// id the object
|
||||||
if (o->type->obclass->id == OC_BOOK) {
|
if ((o->type->obclass->id == OC_BOOK) || (o->type->id == OT_MAP)) {
|
||||||
identify(o);
|
identify(o);
|
||||||
} else {
|
} else {
|
||||||
makeknown(o->type->id);
|
makeknown(o->type->id);
|
||||||
|
@ -10457,9 +10462,9 @@ int readsomething(lifeform_t *lf, object_t *o) {
|
||||||
|
|
||||||
if (ismagical(o)) {
|
if (ismagical(o)) {
|
||||||
pleasemagicgod = B_TRUE;
|
pleasemagicgod = B_TRUE;
|
||||||
///... we might change this back to false later
|
///... this might be changed back to false later
|
||||||
// if a scroll causes us to cast a spell, so that we
|
// if a scroll causes us to cast a spell, so that we
|
||||||
// dont double up the god bonus.
|
// dont double up the god bonus for using magic.
|
||||||
}
|
}
|
||||||
|
|
||||||
// special scrolls
|
// special scrolls
|
||||||
|
|
237
save.c
237
save.c
|
@ -32,55 +32,24 @@ extern long curtime, gamedays, gamesecs;
|
||||||
|
|
||||||
extern enum GAMEMODE gamemode;
|
extern enum GAMEMODE gamemode;
|
||||||
|
|
||||||
|
// returns TRUE if we successfully loaded a save file
|
||||||
int loadall(void) {
|
int loadall(void) {
|
||||||
DIR *dir;
|
//int db = B_FALSE;
|
||||||
struct dirent *ent;
|
int foundsavegame = B_FALSE;
|
||||||
int db = B_FALSE;
|
|
||||||
region_t *heavenregion;
|
region_t *heavenregion;
|
||||||
|
|
||||||
gamemode = GM_LOADING;
|
gamemode = GM_LOADING;
|
||||||
|
|
||||||
dir = opendir(MAPDIR);
|
if (loadsavegame()) {
|
||||||
if (!dir) {
|
// update fixed region pointers
|
||||||
dblog("Could not open map directory '%s'",MAPDIR);
|
heavenregion = findregionbytype(RG_HEAVEN);
|
||||||
return B_TRUE;
|
heaven = findregionmap(heavenregion->id, 1);
|
||||||
|
foundsavegame = B_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// load region outlines
|
|
||||||
if (loadregions()) {
|
|
||||||
// this isn't an error - just means no savegames
|
|
||||||
if (db) dblog("No region data found.");
|
|
||||||
return B_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// for each map file in directory
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
|
||||||
char *p;
|
|
||||||
// ie. start of 4 char prefix
|
|
||||||
p = ent->d_name + strlen(ent->d_name) - 4;
|
|
||||||
// load this map
|
|
||||||
if (!strcmp(p, ".map") ) {
|
|
||||||
if (!loadmap(ent->d_name)) {
|
|
||||||
printf("Error loading map from file '%s'",ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
// remove this map
|
|
||||||
unlink(ent->d_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
// update fixed region pointers
|
|
||||||
heavenregion = findregionbytype(RG_HEAVEN);
|
|
||||||
heaven = findregionmap(heavenregion->id, 1);
|
|
||||||
|
|
||||||
loadsavegame();
|
|
||||||
|
|
||||||
gamemode = GM_LOADED;
|
gamemode = GM_LOADED;
|
||||||
|
|
||||||
return B_FALSE;
|
return foundsavegame;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadflagpile(FILE *f, flagpile_t *fp) {
|
int loadflagpile(FILE *f, flagpile_t *fp) {
|
||||||
|
@ -323,9 +292,7 @@ lifeform_t *loadlf(FILE *f, cell_t *where) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
map_t *loadmap(char *basefile) {
|
map_t *loadmap(FILE *f) {
|
||||||
FILE *f;
|
|
||||||
char filename[BUFLEN];
|
|
||||||
char buf[BUFLEN];
|
char buf[BUFLEN];
|
||||||
int obcount;
|
int obcount;
|
||||||
int i;
|
int i;
|
||||||
|
@ -339,10 +306,6 @@ map_t *loadmap(char *basefile) {
|
||||||
cell_t *dummycell;
|
cell_t *dummycell;
|
||||||
int regionid;
|
int regionid;
|
||||||
|
|
||||||
if (db) dblog("Loading map from %s...",basefile);
|
|
||||||
snprintf(filename, BUFLEN, "%s/%s",MAPDIR,basefile);
|
|
||||||
f = fopen(filename, "rt");
|
|
||||||
|
|
||||||
// create map
|
// create map
|
||||||
m = addmap();
|
m = addmap();
|
||||||
dummycell = malloc(sizeof(cell_t));
|
dummycell = malloc(sizeof(cell_t));
|
||||||
|
@ -351,7 +314,7 @@ map_t *loadmap(char *basefile) {
|
||||||
dummycell->type = (celltype_t *)DUMMYCELLTYPE; // for debugging
|
dummycell->type = (celltype_t *)DUMMYCELLTYPE; // for debugging
|
||||||
|
|
||||||
if (!m) {
|
if (!m) {
|
||||||
dblog("Error creating map while loading file '%s'",filename);
|
printf("Error creating map while loading.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,7 +501,7 @@ map_t *loadmap(char *basefile) {
|
||||||
// load flags
|
// load flags
|
||||||
loadflagpile(f, m->flags);
|
loadflagpile(f, m->flags);
|
||||||
|
|
||||||
fclose(f);
|
// we are now finished loading from the file.
|
||||||
|
|
||||||
// move lifeforms to their proper locations
|
// move lifeforms to their proper locations
|
||||||
for (l = m->lf ; l ; l = l->next) {
|
for (l = m->lf ; l ; l = l->next) {
|
||||||
|
@ -555,9 +518,6 @@ map_t *loadmap(char *basefile) {
|
||||||
|
|
||||||
free(dummycell);
|
free(dummycell);
|
||||||
|
|
||||||
// successful load - kill the map now
|
|
||||||
unlink(filename);
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,20 +616,13 @@ int loadob(FILE *f, obpile_t *op, long *id) {
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadregions(void) {
|
int loadregions(FILE *f) {
|
||||||
FILE *f;
|
|
||||||
char filename[BUFLEN];
|
|
||||||
int rtid,nthings,i,n;
|
int rtid,nthings,i,n;
|
||||||
int numoutlines,numregions;
|
int numoutlines,numregions;
|
||||||
int db = B_FALSE;
|
int db = B_TRUE;
|
||||||
int depthmod;
|
int depthmod;
|
||||||
|
|
||||||
// TODO: check that map dir exists
|
fscanf(f, "start_regions\n");
|
||||||
snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR);
|
|
||||||
f = fopen(filename, "rt");
|
|
||||||
if (!f) {
|
|
||||||
return B_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
fscanf(f, "numoutlines:%d\n",&numoutlines);
|
fscanf(f, "numoutlines:%d\n",&numoutlines);
|
||||||
if (db) dblog("Found %d region outlines.\n",numoutlines);
|
if (db) dblog("Found %d region outlines.\n",numoutlines);
|
||||||
|
@ -703,7 +656,7 @@ int loadregions(void) {
|
||||||
if (db) dblog("Loaded regionoutline #%d / %d",n+1, numoutlines);
|
if (db) dblog("Loaded regionoutline #%d / %d",n+1, numoutlines);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now save out the actual region->outline mappings
|
// now load in the actual region->outline mappings
|
||||||
fscanf(f, "numregions:%d\n",&numregions);
|
fscanf(f, "numregions:%d\n",&numregions);
|
||||||
if (db) dblog("Found %d regions.\n",numregions);
|
if (db) dblog("Found %d regions.\n",numregions);
|
||||||
for (n = 0; n < numregions; n++) {
|
for (n = 0; n < numregions; n++) {
|
||||||
|
@ -712,7 +665,7 @@ int loadregions(void) {
|
||||||
int rid;
|
int rid;
|
||||||
int outlineid,parentid,nthings;
|
int outlineid,parentid,nthings;
|
||||||
fscanf(f, "startregion\n");
|
fscanf(f, "startregion\n");
|
||||||
fscanf(f, " id:%d\n",(int *)&rid);
|
fscanf(f, " rid:%d\n",(int *)&rid);
|
||||||
fscanf(f, " rtypeid:%d\n",(int *)&rtid);
|
fscanf(f, " rtypeid:%d\n",(int *)&rtid);
|
||||||
fscanf(f, " outline:%d\n",&outlineid);
|
fscanf(f, " outline:%d\n",&outlineid);
|
||||||
fscanf(f, " parentregion:%d\n",&parentid);
|
fscanf(f, " parentregion:%d\n",&parentid);
|
||||||
|
@ -725,68 +678,68 @@ int loadregions(void) {
|
||||||
if (db) dblog("Loaded region #%d / %d",n+1, numregions);
|
if (db) dblog("Loaded region #%d / %d",n+1, numregions);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fscanf(f, "end_regions\n");
|
||||||
|
|
||||||
// successful load - kill the file now
|
|
||||||
unlink(filename);
|
|
||||||
|
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns TRUE if there was a savegame file.
|
||||||
int loadsavegame(void) {
|
int loadsavegame(void) {
|
||||||
DIR *dir;
|
|
||||||
struct dirent *ent;
|
|
||||||
char filename[BUFLEN];
|
char filename[BUFLEN];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
int mapcount,i;
|
||||||
|
|
||||||
// now see if there is a savegame...
|
// check for a save file...
|
||||||
dir = opendir(SAVEDIR);
|
snprintf(filename, BUFLEN, "%s/game.sav",SAVEDIR);
|
||||||
if (!dir) {
|
f = fopen(filename, "rt");
|
||||||
dblog("Could not open savegame directory '%s'",SAVEDIR);
|
if (!f) {
|
||||||
return B_TRUE;
|
// this isn't an error - just means no savegames
|
||||||
|
dblog("No savegame found.");
|
||||||
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ent = readdir(dir);
|
// load region outlines
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
if (loadregions(f)) {
|
||||||
char *p;
|
printf("No region data found in savegame file!");
|
||||||
// ie. start of 4 char prefix
|
exit(1);
|
||||||
p = ent->d_name + strlen(ent->d_name) - 4;
|
}
|
||||||
// load this savegame
|
|
||||||
if (!strcmp(p, ".sav") ) {
|
|
||||||
snprintf(filename, BUFLEN, "%s/%s",SAVEDIR,ent->d_name);
|
|
||||||
dblog("Trying to load from %s\n",filename);
|
|
||||||
f = fopen(filename, "rt");
|
|
||||||
if (!f) {
|
|
||||||
printf("Error opening savegame file '%s'",ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
// load world data
|
|
||||||
if (loadworlddata(f)) {
|
|
||||||
printf("Error load world data from file '%s'", ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (!loadlf(f, NULL)) {
|
|
||||||
printf("Error loading player from file '%s'",ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (loadknowledge(f)) {
|
|
||||||
printf("Error loading knowledge from file '%s'",ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (loadvars(f)) {
|
|
||||||
printf("Error loading game variables from file '%s'",ent->d_name);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
// successful load - kill the savegame now
|
// load maps
|
||||||
unlink(filename);
|
fscanf(f, "start_maps:%d\n",&mapcount);
|
||||||
break;
|
for (i = 0; i < mapcount; i++) {
|
||||||
|
if (!loadmap(f)) {
|
||||||
|
printf("Error loading map %d of %d!", i+1, mapcount);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir(dir);
|
fscanf(f, "end_maps\n");
|
||||||
|
|
||||||
return B_FALSE;
|
// load world data
|
||||||
|
if (loadworlddata(f)) {
|
||||||
|
printf("Error load world data from save file.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// load player
|
||||||
|
if (!loadlf(f, NULL)) {
|
||||||
|
printf("Error loading player from save file.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// load knowledge
|
||||||
|
if (loadknowledge(f)) {
|
||||||
|
printf("Error loading knowledge from save file.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
// load game variables
|
||||||
|
if (loadvars(f)) {
|
||||||
|
printf("Error loading game variables from save file.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// successful load - close and kill the savegame file
|
||||||
|
fclose(f);
|
||||||
|
unlink(filename);
|
||||||
|
|
||||||
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int savevars(FILE *f) {
|
int savevars(FILE *f) {
|
||||||
|
@ -916,50 +869,53 @@ int savegame(void) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char buf[BUFLEN];
|
char buf[BUFLEN];
|
||||||
int rv;
|
int rv;
|
||||||
|
int mapcount = 0;
|
||||||
|
|
||||||
rv = saveregions();
|
snprintf(buf, BUFLEN, "%s/game.sav",SAVEDIR);
|
||||||
|
f = fopen(buf, "wt");
|
||||||
|
if (!f) {
|
||||||
|
msg("Could not open save file!");
|
||||||
|
return B_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = saveregions(f);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
msg("Could not save region data.");
|
msg("Could not save region data.");
|
||||||
return B_TRUE;
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (m = firstmap; m ; m = m->next) {
|
||||||
|
mapcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "start_maps:%d\n",mapcount);
|
||||||
for (m = firstmap; m ; m = m->next) {
|
for (m = firstmap; m ; m = m->next) {
|
||||||
// save world
|
// save world
|
||||||
rv = savemap(m);
|
rv = savemap(f, m);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
msg("Could not save map '%s'",m->name);
|
msg("Could not save map '%s'",m->name);
|
||||||
return B_TRUE;
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
// save player + their objects
|
|
||||||
snprintf(buf, BUFLEN, "%s/game.sav",SAVEDIR);
|
|
||||||
f = fopen(buf, "wt");
|
|
||||||
if (!f) {
|
|
||||||
msg("Could not open save file!");
|
|
||||||
return B_TRUE;
|
|
||||||
}
|
|
||||||
saveworlddata(f);
|
|
||||||
savelf(f, player);
|
|
||||||
saveknowledge(f);
|
|
||||||
savevars(f);
|
|
||||||
fclose(f);
|
|
||||||
}
|
}
|
||||||
|
fprintf(f, "end_maps\n");
|
||||||
|
// load world data
|
||||||
|
saveworlddata(f);
|
||||||
|
// save player + their objects
|
||||||
|
savelf(f, player);
|
||||||
|
saveknowledge(f);
|
||||||
|
savevars(f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int savemap(map_t *m) {
|
int savemap(FILE *f, map_t *m) {
|
||||||
FILE *f;
|
|
||||||
char filename[BUFLEN];
|
|
||||||
int i;
|
int i;
|
||||||
object_t *o;
|
object_t *o;
|
||||||
lifeform_t *l;
|
lifeform_t *l;
|
||||||
int x,y;
|
int x,y;
|
||||||
int obcount = 0;
|
int obcount = 0;
|
||||||
|
|
||||||
// TODO: check that map dir exists
|
|
||||||
snprintf(filename, BUFLEN, "%s/map%d.map",MAPDIR, m->id);
|
|
||||||
f = fopen(filename, "wt");
|
|
||||||
|
|
||||||
// save map info
|
// save map info
|
||||||
fprintf(f, "id:%d\n",m->id); // map id
|
fprintf(f, "id:%d\n",m->id); // map id
|
||||||
fprintf(f, "region:%d\n",m->region->id); // map region id
|
fprintf(f, "region:%d\n",m->region->id); // map region id
|
||||||
|
@ -1028,8 +984,6 @@ int savemap(map_t *m) {
|
||||||
|
|
||||||
saveflagpile(f, m->flags);
|
saveflagpile(f, m->flags);
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1061,17 +1015,13 @@ int saveob(FILE *f, object_t *o) {
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int saveregions(void) {
|
int saveregions(FILE *f) {
|
||||||
FILE *f;
|
|
||||||
char filename[BUFLEN];
|
|
||||||
int i;
|
int i;
|
||||||
regionoutline_t *ro;
|
regionoutline_t *ro;
|
||||||
region_t *r;
|
region_t *r;
|
||||||
int numoutlines = 0,numregions = 0;
|
int numoutlines = 0,numregions = 0;
|
||||||
|
|
||||||
// TODO: check that map dir exists
|
fprintf(f, "start_regions\n");
|
||||||
snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR);
|
|
||||||
f = fopen(filename, "wt");
|
|
||||||
for (ro = firstregionoutline ; ro ; ro = ro->next) {
|
for (ro = firstregionoutline ; ro ; ro = ro->next) {
|
||||||
numoutlines++;
|
numoutlines++;
|
||||||
}
|
}
|
||||||
|
@ -1105,7 +1055,6 @@ int saveregions(void) {
|
||||||
|
|
||||||
|
|
||||||
// now save out the actual region->outline mappings
|
// now save out the actual region->outline mappings
|
||||||
|
|
||||||
numregions = 0;
|
numregions = 0;
|
||||||
for (r = firstregion ; r; r = r->next) {
|
for (r = firstregion ; r; r = r->next) {
|
||||||
numregions++;
|
numregions++;
|
||||||
|
@ -1122,7 +1071,7 @@ int saveregions(void) {
|
||||||
fprintf(f, " depthmod:%d\n",r->depthmod);
|
fprintf(f, " depthmod:%d\n",r->depthmod);
|
||||||
fprintf(f, "endregion\n");
|
fprintf(f, "endregion\n");
|
||||||
}
|
}
|
||||||
fclose(f);
|
fprintf(f, "end_regions\n");
|
||||||
|
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
|
8
save.h
8
save.h
|
@ -4,18 +4,18 @@ int loadall(void);
|
||||||
int loadflagpile(FILE *f, flagpile_t *fp);
|
int loadflagpile(FILE *f, flagpile_t *fp);
|
||||||
int loadknowledge(FILE *f);
|
int loadknowledge(FILE *f);
|
||||||
lifeform_t *loadlf(FILE *f, cell_t *where);
|
lifeform_t *loadlf(FILE *f, cell_t *where);
|
||||||
map_t *loadmap(char *basefile);
|
map_t *loadmap(FILE *f);
|
||||||
int loadob(FILE *f, obpile_t *op, long *id);
|
int loadob(FILE *f, obpile_t *op, long *id);
|
||||||
int loadregions(void);
|
int loadregions(FILE *f);
|
||||||
int loadsavegame(void);
|
int loadsavegame(void);
|
||||||
int loadworlddata(FILE *f);
|
int loadworlddata(FILE *f);
|
||||||
int saveflagpile(FILE *f, flagpile_t *fp);
|
int saveflagpile(FILE *f, flagpile_t *fp);
|
||||||
int saveknowledge(FILE *f);
|
int saveknowledge(FILE *f);
|
||||||
int savelf(FILE *f, lifeform_t *l);
|
int savelf(FILE *f, lifeform_t *l);
|
||||||
int savegame(void);
|
int savegame(void);
|
||||||
int savemap(map_t *m);
|
int savemap(FILE *f, map_t *m);
|
||||||
int saveob(FILE *f, object_t *o);
|
int saveob(FILE *f, object_t *o);
|
||||||
int saveregions(void);
|
int saveregions(FILE *f);
|
||||||
int saveworlddata(FILE *f);
|
int saveworlddata(FILE *f);
|
||||||
int showhiscores(lifeform_t *lf, int min, int max);
|
int showhiscores(lifeform_t *lf, int min, int max);
|
||||||
int writehiscore(lifeform_t *lf, int *rank);
|
int writehiscore(lifeform_t *lf, int *rank);
|
||||||
|
|
Loading…
Reference in New Issue