- [+] 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:
Rob Pearce 2012-02-01 23:02:18 +00:00
parent 584d1e8681
commit 3a671253a1
9 changed files with 142 additions and 171 deletions

2
data.c
View File

@ -7400,7 +7400,7 @@ void initrace(void) {
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);
addflag(lastrace->flags, F_PLAYABLE, B_TRUE, NA, NA, NULL);
addflag(lastrace->flags, F_STARTATT, A_STR, AT_LTAVERAGE, NA, NULL);

1
defs.h
View File

@ -304,7 +304,6 @@ enum TRADEINFOTYPE {
#define MAXPNAMELEN 12 // max player name length
// file i/o
#define DATADIR "data"
#define MAPDIR "data/maps"
#define SAVEDIR "data/save"
#define VAULTDIR "vaults"
// rank, score, name, job, killer

2
lf.c
View File

@ -11029,7 +11029,7 @@ int ishelplessvictim(lifeform_t *victim, lifeform_t *attacker, enum HELPLESSTYPE
if (isfleeing(victim)) {
if (how) *how = HL_FLEEING;
return B_TRUE;
} else if (!cansee(victim, attacker)) {
} else if (!cansee(victim, attacker) && (getraceclass(victim) != RC_PLANT)) {
if (how) *how = HL_CANTSEE;
return B_TRUE;
}

32
map.c
View File

@ -45,6 +45,7 @@ extern enum ERROR reason;
extern enum GAMEMODE gamemode;
extern int needredraw;
extern int noredraw;
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 *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
if (firstregionoutline == NULL) {
@ -719,11 +728,7 @@ regionoutline_t *addregionoutline(enum REGIONTYPE rtype) {
a->next = NULL;
// props
if (a == firstregionoutline) {
a->id = 0;
} else {
a->id = lastregionoutline->id + 1;
}
a->id = nextid;
a->rtype = findregiontype(rtype);
a->nthings = 0;
return a;
@ -1683,6 +1688,9 @@ void calclight(map_t *map) {
cell_t *c;
int i;
// disable screen redraws
noredraw = B_TRUE;
// remember lit values for cells in player's los
if (gamemode == GM_GAMESTARTED) {
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?
if (gamemode == GM_GAMESTARTED) {
int dolos = B_FALSE;
@ -1757,7 +1768,8 @@ void calclight(map_t *map) {
setlosdirty(player);
}
}
*/
}
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) {
int vx[4],vy[4],i;
// habitats
// thingchance, obchance, vaultchance, maxvisrange
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_STOMACH, "A Stomach", B_FALSE, H_STOMACH, 1, 0, D_NONE, B_FALSE, 0);
}
void initmaplayout(void) {
int vx[4],vy[4],i;
// MAPMAPMAPMAP
// region definitions (outlines)
addregionoutline(RG_WORLDMAP);

1
map.h
View File

@ -125,6 +125,7 @@ int hasknownobject(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);
void initmap(void);
void initmaplayout(void);
int isadjacent(cell_t *src, cell_t *dst);
int isdark(cell_t *c);
int isdiggable(cell_t *c);

17
nexus.c
View File

@ -120,6 +120,7 @@ int main(int argc, char **argv) {
char welcomemsg[BUFLEN];
int ch;
FILE *playerfile = NULL;
int foundsavegame = B_FALSE;
int x,y,i;
cell_t *c,*targc;
vault_t *v;
@ -151,8 +152,8 @@ int main(int argc, char **argv) {
exit(1);
}
// load whatever maps are available
loadall();
// load savegame, if available
foundsavegame = loadall();
// init graphics
initgfx();
@ -174,8 +175,8 @@ int main(int argc, char **argv) {
}
// if no player (ie. didn't load a game), add them
if (!player) {
// if we didn't load a game, add the player
if (!foundsavegame) {
char *user,pname[BUFLEN],buf[BUFLEN];
job_t *j = NULL;
race_t *startrace = NULL;
@ -187,6 +188,9 @@ int main(int argc, char **argv) {
region_t *wregion, *dregion,*hregion;
map_t *dmap,*surfmap;
// create the dungeon layout
initmaplayout();
// populate scroll, potion, etc names
genhiddennames();
@ -479,7 +483,6 @@ int main(int argc, char **argv) {
// start game - this will cause debug messages to now
// go to the log file instead of stdout.
timeleft = 0; // reset game timer
enteringmap = B_FALSE; // no time passes for lfs on a different map to the player.
@ -1147,14 +1150,12 @@ int init(void) {
initskills();
initjobs();
initrace();
initmap();
// open log file (want to do this before digging the first map)
logfile = fopen("log.txt","wt");
fprintf(logfile, "\n\n\n====== NEW LOGFILE ====\n");
// create the dungeon layout
initmap();
validatehiddennames();

View File

@ -1255,6 +1255,10 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes
god = getrandomgod();
if (god) {
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
if (o->type->obclass->id == OC_BOOK) {
if ((o->type->obclass->id == OC_BOOK) || (o->type->id == OT_MAP)) {
identify(o);
} else {
makeknown(o->type->id);
@ -10457,9 +10462,9 @@ int readsomething(lifeform_t *lf, object_t *o) {
if (ismagical(o)) {
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
// dont double up the god bonus.
// dont double up the god bonus for using magic.
}
// special scrolls

235
save.c
View File

@ -32,55 +32,24 @@ extern long curtime, gamedays, gamesecs;
extern enum GAMEMODE gamemode;
// returns TRUE if we successfully loaded a save file
int loadall(void) {
DIR *dir;
struct dirent *ent;
int db = B_FALSE;
//int db = B_FALSE;
int foundsavegame = B_FALSE;
region_t *heavenregion;
gamemode = GM_LOADING;
dir = opendir(MAPDIR);
if (!dir) {
dblog("Could not open map directory '%s'",MAPDIR);
return B_TRUE;
if (loadsavegame()) {
// update fixed region pointers
heavenregion = findregionbytype(RG_HEAVEN);
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;
return B_FALSE;
return foundsavegame;
}
int loadflagpile(FILE *f, flagpile_t *fp) {
@ -323,9 +292,7 @@ lifeform_t *loadlf(FILE *f, cell_t *where) {
map_t *loadmap(char *basefile) {
FILE *f;
char filename[BUFLEN];
map_t *loadmap(FILE *f) {
char buf[BUFLEN];
int obcount;
int i;
@ -339,10 +306,6 @@ map_t *loadmap(char *basefile) {
cell_t *dummycell;
int regionid;
if (db) dblog("Loading map from %s...",basefile);
snprintf(filename, BUFLEN, "%s/%s",MAPDIR,basefile);
f = fopen(filename, "rt");
// create map
m = addmap();
dummycell = malloc(sizeof(cell_t));
@ -351,7 +314,7 @@ map_t *loadmap(char *basefile) {
dummycell->type = (celltype_t *)DUMMYCELLTYPE; // for debugging
if (!m) {
dblog("Error creating map while loading file '%s'",filename);
printf("Error creating map while loading.");
return NULL;
}
@ -538,7 +501,7 @@ map_t *loadmap(char *basefile) {
// load flags
loadflagpile(f, m->flags);
fclose(f);
// we are now finished loading from the file.
// move lifeforms to their proper locations
for (l = m->lf ; l ; l = l->next) {
@ -555,9 +518,6 @@ map_t *loadmap(char *basefile) {
free(dummycell);
// successful load - kill the map now
unlink(filename);
return m;
}
@ -656,20 +616,13 @@ int loadob(FILE *f, obpile_t *op, long *id) {
return B_FALSE;
}
int loadregions(void) {
FILE *f;
char filename[BUFLEN];
int loadregions(FILE *f) {
int rtid,nthings,i,n;
int numoutlines,numregions;
int db = B_FALSE;
int db = B_TRUE;
int depthmod;
// TODO: check that map dir exists
snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR);
f = fopen(filename, "rt");
if (!f) {
return B_TRUE;
}
fscanf(f, "start_regions\n");
fscanf(f, "numoutlines:%d\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);
}
// now save out the actual region->outline mappings
// now load in the actual region->outline mappings
fscanf(f, "numregions:%d\n",&numregions);
if (db) dblog("Found %d regions.\n",numregions);
for (n = 0; n < numregions; n++) {
@ -712,7 +665,7 @@ int loadregions(void) {
int rid;
int outlineid,parentid,nthings;
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, " outline:%d\n",&outlineid);
fscanf(f, " parentregion:%d\n",&parentid);
@ -725,68 +678,68 @@ int loadregions(void) {
if (db) dblog("Loaded region #%d / %d",n+1, numregions);
}
fclose(f);
// successful load - kill the file now
unlink(filename);
fscanf(f, "end_regions\n");
return B_FALSE;
}
// returns TRUE if there was a savegame file.
int loadsavegame(void) {
DIR *dir;
struct dirent *ent;
char filename[BUFLEN];
FILE *f;
int mapcount,i;
// now see if there is a savegame...
dir = opendir(SAVEDIR);
if (!dir) {
dblog("Could not open savegame directory '%s'",SAVEDIR);
return B_TRUE;
// check for a save file...
snprintf(filename, BUFLEN, "%s/game.sav",SAVEDIR);
f = fopen(filename, "rt");
if (!f) {
// this isn't an error - just means no savegames
dblog("No savegame found.");
return B_FALSE;
}
ent = readdir(dir);
while ((ent = readdir(dir)) != NULL) {
char *p;
// ie. start of 4 char prefix
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);
// load region outlines
if (loadregions(f)) {
printf("No region data found in savegame file!");
exit(1);
}
// successful load - kill the savegame now
unlink(filename);
break;
// load maps
fscanf(f, "start_maps:%d\n",&mapcount);
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) {
@ -916,50 +869,53 @@ int savegame(void) {
FILE *f;
char buf[BUFLEN];
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) {
msg("Could not save region data.");
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) {
// save world
rv = savemap(m);
rv = savemap(f, m);
if (rv) {
msg("Could not save map '%s'",m->name);
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;
}
int savemap(map_t *m) {
FILE *f;
char filename[BUFLEN];
int savemap(FILE *f, map_t *m) {
int i;
object_t *o;
lifeform_t *l;
int x,y;
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
fprintf(f, "id:%d\n",m->id); // map 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);
fclose(f);
return B_FALSE;
}
@ -1061,17 +1015,13 @@ int saveob(FILE *f, object_t *o) {
return B_FALSE;
}
int saveregions(void) {
FILE *f;
char filename[BUFLEN];
int saveregions(FILE *f) {
int i;
regionoutline_t *ro;
region_t *r;
int numoutlines = 0,numregions = 0;
// TODO: check that map dir exists
snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR);
f = fopen(filename, "wt");
fprintf(f, "start_regions\n");
for (ro = firstregionoutline ; ro ; ro = ro->next) {
numoutlines++;
}
@ -1105,7 +1055,6 @@ int saveregions(void) {
// now save out the actual region->outline mappings
numregions = 0;
for (r = firstregion ; r; r = r->next) {
numregions++;
@ -1122,7 +1071,7 @@ int saveregions(void) {
fprintf(f, " depthmod:%d\n",r->depthmod);
fprintf(f, "endregion\n");
}
fclose(f);
fprintf(f, "end_regions\n");
return B_FALSE;
}

8
save.h
View File

@ -4,18 +4,18 @@ int loadall(void);
int loadflagpile(FILE *f, flagpile_t *fp);
int loadknowledge(FILE *f);
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 loadregions(void);
int loadregions(FILE *f);
int loadsavegame(void);
int loadworlddata(FILE *f);
int saveflagpile(FILE *f, flagpile_t *fp);
int saveknowledge(FILE *f);
int savelf(FILE *f, lifeform_t *l);
int savegame(void);
int savemap(map_t *m);
int savemap(FILE *f, map_t *m);
int saveob(FILE *f, object_t *o);
int saveregions(void);
int saveregions(FILE *f);
int saveworlddata(FILE *f);
int showhiscores(lifeform_t *lf, int min, int max);
int writehiscore(lifeform_t *lf, int *rank);