2010-12-07 18:34:26 +11:00
|
|
|
#include <assert.h>
|
2010-12-02 12:17:54 +11:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-02-01 06:16:13 +11:00
|
|
|
#include <unistd.h>
|
2010-12-02 12:17:54 +11:00
|
|
|
#include "defs.h"
|
2011-02-01 06:16:13 +11:00
|
|
|
#include "flag.h"
|
|
|
|
#include "io.h"
|
2010-12-02 12:17:54 +11:00
|
|
|
#include "lf.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "move.h"
|
|
|
|
#include "nexus.h"
|
|
|
|
#include "objects.h"
|
|
|
|
#include "save.h"
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
extern long curtime;
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
extern lifeform_t *player;
|
|
|
|
extern map_t *firstmap;
|
2010-12-07 18:34:26 +11:00
|
|
|
extern knowledge_t *knowledge;
|
|
|
|
|
2011-03-18 12:25:18 +11:00
|
|
|
extern enum GAMEMODE gamemode;
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
int loadall(void) {
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
|
|
|
|
2011-03-18 12:25:18 +11:00
|
|
|
gamemode = GM_LOADING;
|
2010-12-07 18:34:26 +11:00
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
dir = opendir(MAPDIR);
|
|
|
|
if (!dir) {
|
|
|
|
dblog("Could not open map directory '%s'",MAPDIR);
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
loadsavegame();
|
|
|
|
|
2011-03-18 12:25:18 +11:00
|
|
|
gamemode = GM_LOADED;
|
2010-12-07 18:34:26 +11:00
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
int loadflagpile(FILE *f, flagpile_t *fp) {
|
|
|
|
flag_t tempflag;
|
|
|
|
flag_t *fl;
|
|
|
|
char buf[BUFLEN];
|
|
|
|
int rv;
|
|
|
|
int db = B_TRUE;
|
|
|
|
|
|
|
|
rv = fscanf(f, "%d,%d,%d,%d,%d,%d,%d,%ld\n",
|
|
|
|
&tempflag.id, &tempflag.nvals, &tempflag.val[0], &tempflag.val[1], &tempflag.val[2],&tempflag.lifetime, &tempflag.known,&tempflag.obfrom);
|
|
|
|
|
|
|
|
while (tempflag.id != -1) {
|
|
|
|
dblog("got flag id=%d\n",tempflag.id);
|
|
|
|
// get flag text
|
|
|
|
fgets(buf, BUFLEN, f);
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
|
|
|
|
|
|
|
fl = addflag_real(fp, tempflag.id,
|
|
|
|
tempflag.val[0],
|
|
|
|
tempflag.val[1],
|
2011-02-16 05:21:33 +11:00
|
|
|
tempflag.val[2], strcmp(buf, "^^^") ? buf : NULL, tempflag.lifetime, tempflag.known, tempflag.obfrom);
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
|
|
|
|
if (db) {
|
|
|
|
dblog("--> added flag id=%d. v0=%d, v1=%d, v2=%d, text=%s, lifetime=%d, known=%d, obfrom=%ld\n",fl->id,
|
|
|
|
fl->val[0], fl->val[1], fl->val[2], fl->text ? fl->text : "(null)", fl->lifetime, fl->known,fl->obfrom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load next one
|
|
|
|
rv = fscanf(f, "%d,%d,%d,%d,%d,%d,%d,%ld\n",
|
|
|
|
&tempflag.id, &tempflag.nvals, &tempflag.val[0], &tempflag.val[1], &tempflag.val[2],&tempflag.lifetime, &tempflag.known,&tempflag.obfrom);
|
|
|
|
//dblog("fscanf returned %d\n",rv);
|
|
|
|
}
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
int loadknowledge(FILE *f) {
|
|
|
|
int db = B_FALSE;
|
|
|
|
char buf[BUFLEN];
|
2011-04-06 17:27:55 +10:00
|
|
|
char line[BUFLEN];
|
2010-12-07 18:34:26 +11:00
|
|
|
int otid,known;
|
|
|
|
char hiddenname[BUFLEN];
|
2011-04-06 17:27:55 +10:00
|
|
|
char *p,*dummy;
|
2010-12-07 18:34:26 +11:00
|
|
|
if (db) dblog("--> Loading knowledge...\n");
|
|
|
|
fscanf(f, "startknowledge\n");
|
|
|
|
|
|
|
|
fgets(buf, BUFLEN, f);
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
while (strcmp(buf, "endknowledge")) {
|
2011-04-06 17:27:55 +10:00
|
|
|
//sscanf(buf, "%d^%s^%d",&otid, hiddenname, &known);
|
|
|
|
strcpy(line, buf);
|
|
|
|
p = strtok_r(line, "^", &dummy);
|
|
|
|
otid = atoi(p);
|
|
|
|
p = strtok_r(NULL, "^", &dummy);
|
|
|
|
strcpy(hiddenname, p);
|
|
|
|
p = strtok_r(NULL, "^", &dummy);
|
|
|
|
known = atoi(p);
|
2010-12-07 18:34:26 +11:00
|
|
|
addknowledge(otid, hiddenname, known);
|
|
|
|
// get next line
|
|
|
|
fgets(buf, BUFLEN, f);
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
int loadvars(FILE *f) {
|
|
|
|
int db = B_FALSE;
|
|
|
|
if (db) dblog("--> Loading knowledge...\n");
|
|
|
|
fscanf(f, "startvars\n");
|
|
|
|
fscanf(f, "curtime:%ld\n",&curtime);
|
|
|
|
fscanf(f, "endvars\n");
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
// load and allocate one lifeform from given file
|
|
|
|
lifeform_t *loadlf(FILE *f, cell_t *where) {
|
|
|
|
lifeform_t *l;
|
|
|
|
int lfid, lfraceid;
|
|
|
|
long obid;
|
|
|
|
int rv;
|
|
|
|
int i;
|
|
|
|
char buf[BUFLEN];
|
|
|
|
int obcount;
|
|
|
|
int mapid;
|
|
|
|
map_t *m;
|
2011-04-14 09:44:29 +10:00
|
|
|
int x,y,level,newlevel;
|
2010-12-02 12:17:54 +11:00
|
|
|
int db = B_TRUE;
|
|
|
|
|
|
|
|
if (db) dblog("--> Loading lifeform...\n");
|
|
|
|
|
|
|
|
fscanf(f, "startlf\n");
|
|
|
|
fscanf(f, "lfid: %d\n",&lfid);
|
|
|
|
fscanf(f, "race: %d\n",&lfraceid);
|
|
|
|
fscanf(f, "map: %d\n",&mapid);
|
|
|
|
fscanf(f, "pos: %d,%d\n",&x, &y);
|
2010-12-07 18:34:26 +11:00
|
|
|
fscanf(f, "level: %d\n",&level);
|
2011-04-14 09:44:29 +10:00
|
|
|
fscanf(f, "newlevel: %d\n",&newlevel);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// find the map
|
|
|
|
m = findmap(mapid);
|
|
|
|
if (!m) {
|
|
|
|
dblog("ERROR loading lf id %d: can't find map id %d\n",lfid,mapid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (where == NULL) {
|
|
|
|
where = getcellat(m, x, y);
|
|
|
|
}
|
|
|
|
if (!m) {
|
|
|
|
dblog("ERROR loading lf id %d: can't find cell at %d,%d on map id %d\n",lfid,x,y,mapid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
l = addlf(where, lfraceid,level);
|
2010-12-02 12:17:54 +11:00
|
|
|
l->id = lfid;
|
|
|
|
l->x = x;
|
|
|
|
l->y = y;
|
2011-04-14 09:44:29 +10:00
|
|
|
l->newlevel = newlevel;
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// load rest of this lf
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "str: %d/%d\n",&l->att[A_STR],&l->baseatt[A_STR]);
|
|
|
|
fscanf(f, "dex: %d/%d\n",&l->att[A_DEX],&l->baseatt[A_DEX]);
|
|
|
|
fscanf(f, "int: %d/%d\n",&l->att[A_IQ],&l->baseatt[A_IQ]);
|
|
|
|
fscanf(f, "xp: %ld\n",&l->xp);
|
2011-03-16 15:45:46 +11:00
|
|
|
fscanf(f, "skp: %d\n",&l->skillpoints);
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "contr: %d\n",&l->controller);
|
|
|
|
fscanf(f, "hp: %d/%d\n",&l->hp, &l->maxhp);
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "mp: %d/%d\n",&l->mp, &l->maxmp);
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "alive: %d\n",&l->alive);
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "lastdamtype: %d\n",(int *)&l->lastdamtype);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
fgets(buf, BUFLEN, f); // lastdam
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
|
|
|
l->lastdam = strdup(buf + 9); // after 'lastdam: '
|
|
|
|
|
|
|
|
fscanf(f, "timespent: %d\n",&l->timespent);
|
|
|
|
|
|
|
|
fscanf(f, "sorted: %d\n",&l->sorted);
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "polyrevert: %d\n",&l->polyrevert);
|
2010-12-07 18:34:26 +11:00
|
|
|
fscanf(f, "forgettimer: %f\n",&l->forgettimer);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
if (db) dblog("--> Got hp=%d/%d. timespend=%d. sorted=%d. Now loading flags.",l->hp,l->maxhp,l->timespent,l->sorted);
|
|
|
|
|
* [+] bug: secret doors revealed when we walk away from them.
- [+] make lamps last heaps longer
* [+] web spell
* [+] spider monstrer
* [+] funnelweb:
* [+] redback:
- [+] if you are wracked with pain, don't clear msg
- [+] check rarity for spiders
* [+] attack/defense mod if there is stickiness in your square
- [+] replace "sticky" with "restrictive"
* [+] make some mosnters start hidden
- [+] adjust spot checks basd on distance
- [+] ensure that attacking stops you hiding
- [+] casting spells stops you from being hidden
- [+] hidden mosnters shouldn't move unless their victim is ADJACENT.
- [+] hidden mosnters shouldn't cast spells, throw missiles, etc unless
their victim is ADJACENT.
- [-] XP CALC
- [+] funnelweb and redback are the same.
- [+] check this is right...... i want funnel web to be worse.
- [+] make hitconfer check in calcxpval take lifetime into account
- [+] ALSO assign an xp rating to each hitconferred flag.
- [+] hardcode this.
* [+] entangle spell
- [+] reveal secret doors if you see them get damaged.
* [+] make askcoords list restrivitce objects
- [+] ACTUALLY make vines not damaged by struggling
* [+] object descriptions, a/an needs to change if showing condition:
"a battered entangling vine"
- [+] wizard levelled up and was prompted for "WISH, GIFT"! shouldn't
happen!
- [+] The human diety reads a blessed scroll of create monster! -- but
nothing happens??
* [+] throw code
- [+] wizard: ask for school specialty at start, from: fire, ice, xxx
? You get this + WILD.
- [+] describe varpower spells
- [+] fix mp cost for varpower spells
- [+] we're not stopping running at staircases anymore for some reason.
- [+] CHARGE ability (like swoop but don't return to original positino)
- [+] need to honor f_canlearn when displaying new skills to learn!
- [+] ai: if we are going to player's last known loc (via targetcell),
abandon if we can SEE the player!
- [+] make shatter() into a function
- [+] oil potion makes oil puddle whan smashed
- [+] make flammable objects be able to convert to others
- [+] replace 'magic item usage' with 'channeling'
- [+] a cloud of darkness descends. this is a *cursed* wand of light.
- [+] spiders shouldn't be able to be stuck in a web!
* [+] spells should be able to have MULTIPLE schools.
- [+] don't bleed into walls
- [+] in @M, use colours to show which spells are too hard so far (ie
cost > maxmp)
* [+] in @M, use schools that you know
* [+] after loading game, barbarian is getting an extra attack?
You miss the eyebat. You punch the eyebat.
- [+] show objects on top of stairs
- [+] stuck mosnters must pass a saving throw to follow you up/down
stairs
- [+] genericise: trytomove(lf)
* [+] add more snakes
- [+] undead can't eat or drink? or MOST undead can't.
* [+] why can MONSTERS shoot webs through things? (but I can't)
- [+] barkskin - doesn't reduce max mp enough?
- [+] The skeleton touches a fuming aqua potion [tried] then recoils in
pain!
The skeleton drops a blessed fuming aqua potion [tried].
The skeleton drinks a fuming aqua potion!
- [+] why can't i use abilites anymore?
- [+] infinite loop bug due to ai only having one ignorecell.
- [+] make sleet storms rust all armour
- [+] make a kind of walkdam that hits armour
- [+] add this as well as walkdam for: acid, fire, water
- [+] Takeoff isn't prompting properly. only showing weapons!
* [+] waterproof obs (ie cloak)
* [+] walkdambp doesn't hurt body if you have a cloak
NATURE SPELLS:
- [+] mending, heals 1d6 damage
- [+] spark
- [+] purify food
- [+] sticks to snakes
- [+] calm animals (power_d4 hd)
* [+] charm animal (works on one animal up to power hit dice, temporary)
- [+] airblast
- [+] barkskin (power +2 AR, firevuln, ongoing)
- [+] soften earth (makes ground into mud)
- [+] warp wood (damages wooden objects)
- [+] repel insects
- [+] reduce poison
- [+] web
- [+] windshield
- [+] call lightning, air
- [+] resist elements, ongoing
- [+] passwall
- [+] poisonbolt
- [+] quench (puts out a fire)
- [+] sleet storm (lowers movement, vision)
- [+] healing
- [+] cure poison
* [+] calming scent
- [+] dig
- [+] entangle
- [+] levitate
- [+] flamepillar
- [+] hailstorm. like sleetstorm but hurts more. power d 6.
- [+] burning wave
- [+] gaseous form
* [+] knowledge skills:
* [+] force makespellchoicelist() to show spells in level order.
* [+] druid
- [+] check OBJECT rarity list (dumplev)
- [+] fix bug where heaps of books suddently appear from dlev 3 onwards
- [+] gain skills on level up for some jobs
- [+] f_levspellschool, v0=lev, v1 = school or ANY - select one
from that school
2011-04-23 14:27:42 +10:00
|
|
|
// clear existing flags from addlf
|
|
|
|
while (l->flags->first) {
|
|
|
|
killflag(l->flags->first);
|
|
|
|
}
|
|
|
|
// load lf flags
|
2011-02-01 06:16:13 +11:00
|
|
|
loadflagpile(f, l->flags);
|
|
|
|
|
|
|
|
if (db) dblog("--> now loading objects");
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// load object list
|
|
|
|
obcount = 0;
|
|
|
|
obid = 9999; // for testing
|
|
|
|
rv = fscanf(f, "ob:%ld\n",&obid);
|
|
|
|
while (obid != -1) {
|
|
|
|
if (db) dblog("--> Load ob id %d into list...",obid);
|
|
|
|
l->pack->oblist[obcount] = obid;
|
|
|
|
obcount++;
|
|
|
|
fscanf(f, "ob:%ld\n",&obid);
|
|
|
|
}
|
|
|
|
// terminate with -1s!
|
|
|
|
for (i = obcount ; i < MAXPILEOBS; i++) {
|
|
|
|
l->pack->oblist[i] = -1;
|
|
|
|
}
|
|
|
|
if (db) dblog("--> Finished oblist. Found %d objects.",obcount);
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
// now load load object defs for this player!
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "obdefs\n");
|
|
|
|
for (i = 0; i < obcount; i++) {
|
2010-12-07 18:34:26 +11:00
|
|
|
long thisid;
|
|
|
|
if (db) dblog("--> Creating ob #%d for lf.",i);
|
2010-12-02 12:17:54 +11:00
|
|
|
//if (db) dblog("-----> ob %d/%d...\n",i+1,obcount);
|
2010-12-07 18:34:26 +11:00
|
|
|
if (loadob(f, l->pack, &thisid)) {
|
2010-12-02 12:17:54 +11:00
|
|
|
dblog("Error - can't create object %d/%d!\n",i+1,obcount);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
if (db) dblog("----> done (id=%ld)",thisid);
|
2010-12-02 12:17:54 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// is this the player?
|
|
|
|
if (l->controller == C_PLAYER) {
|
|
|
|
player = l;
|
|
|
|
}
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
sortlf(l->cell->map, l);
|
|
|
|
return l;
|
2010-12-02 12:17:54 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map_t *loadmap(char *basefile) {
|
|
|
|
FILE *f;
|
|
|
|
char filename[BUFLEN];
|
|
|
|
char buf[BUFLEN];
|
|
|
|
int obcount;
|
|
|
|
int i;
|
|
|
|
int x,y;
|
|
|
|
int db = B_TRUE;
|
2011-06-22 16:01:48 +10:00
|
|
|
enum HABITAT habitatid;
|
2010-12-02 12:17:54 +11:00
|
|
|
lifeform_t *l;
|
2011-02-01 06:16:13 +11:00
|
|
|
object_t *o;
|
2010-12-02 12:17:54 +11:00
|
|
|
map_t *m;
|
|
|
|
cell_t *dummycell;
|
|
|
|
|
|
|
|
if (db) dblog("Loading map from %s...",basefile);
|
|
|
|
sprintf(filename, "%s/%s",MAPDIR,basefile);
|
|
|
|
f = fopen(filename, "rt");
|
|
|
|
|
|
|
|
// create map
|
|
|
|
m = addmap();
|
|
|
|
dummycell = malloc(sizeof(cell_t));
|
|
|
|
dummycell->obpile = addobpile(NULL, dummycell);
|
|
|
|
dummycell->map = m;
|
2010-12-07 18:34:26 +11:00
|
|
|
dummycell->type = (celltype_t *)DUMMYCELLTYPE; // for debugging
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
if (!m) {
|
|
|
|
dblog("Error creating map while loading file '%s'",filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// load map info
|
|
|
|
if (db) dblog("--> Loading map info...\n");
|
|
|
|
fscanf(f, "id:%d\n",&m->id); // map id
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "depth:%d\n",&m->depth); // map depth
|
2010-12-02 12:17:54 +11:00
|
|
|
fgets(buf, BUFLEN, f); // map name
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
|
|
|
m->name = strdup(buf + 5); // after 'name:'
|
2011-06-22 16:01:48 +10:00
|
|
|
fscanf(f, "habitat:%d\n",(int *)habitatid); // habitat
|
|
|
|
m->habitat = findhabitat(habitatid);
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "seed:%d\n",&m->seed); // seed
|
|
|
|
fscanf(f, "dims:%d,%d\n",&m->w, &m->h); // map dimensons
|
|
|
|
fscanf(f, "nextmaps:\n");
|
|
|
|
for (i = 0; i < MAXDIR_ORTH; i++) {
|
|
|
|
fscanf(f, "%d\n",&m->nextmap[i]); // map dimensons
|
|
|
|
}
|
|
|
|
if (db) dblog("--> Finished map info. name='%s', dims=%d x %d\n",m->name, m->w, m->h);
|
2011-03-24 16:09:31 +11:00
|
|
|
fscanf(f, "beingcreated:%d\n",&m->beingcreated);
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "id:%d\n",&m->id); // map id
|
|
|
|
|
|
|
|
// load lifeforms
|
|
|
|
if (db) dblog("--> Loading lifeforms...\n");
|
|
|
|
fscanf(f, "lifeforms:\n");
|
|
|
|
|
|
|
|
fscanf(f, "%s\n",buf);
|
|
|
|
while (!strcmp(buf ,"startlf")) {
|
|
|
|
loadlf(f, dummycell);
|
|
|
|
|
|
|
|
// check for more lifeforms...
|
|
|
|
fscanf(f, "%s\n",buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load cells
|
|
|
|
if (db) dblog("--> Loading map cells...\n");
|
|
|
|
fscanf(f, "cells:\n");
|
|
|
|
for (y = 0; y < m->h; y++) {
|
|
|
|
for (x = 0; x < m->w; x++) {
|
|
|
|
cell_t *c;
|
|
|
|
celltype_t *ct;
|
|
|
|
int celltypeid;
|
|
|
|
long obid;
|
|
|
|
|
|
|
|
//if (db) dblog("cell %d,%d...",x,y);
|
|
|
|
|
|
|
|
// allocate this cell
|
|
|
|
c = addcell(m, x, y);
|
|
|
|
/*
|
|
|
|
c = m->cell[y * m->w + x];
|
|
|
|
c->map = m;
|
|
|
|
c->obpile = addobpile(NULL, c);
|
|
|
|
c->lf = NULL;
|
|
|
|
c->x = x;
|
|
|
|
c->y = y;
|
|
|
|
c->roomid = -1;
|
|
|
|
*/
|
|
|
|
|
|
|
|
// cell info
|
2011-05-20 06:30:58 +10:00
|
|
|
fscanf(f, "%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
|
|
|
|
&c->roomid, &celltypeid, &c->known, &c->knownglyph.ch, &c->knownglyph.colour, &c->visited, &c->lit, &c->origlit, &c->littimer);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
|
|
|
|
ct = findcelltype(celltypeid);
|
|
|
|
if (ct) {
|
|
|
|
c->type = ct;
|
|
|
|
} else {
|
|
|
|
dblog("ERROR loading map cells - can't find celltype id %ld\n",celltypeid);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// cell objects
|
|
|
|
obcount = 0;
|
|
|
|
fscanf(f, "ob:%ld\n",&obid);
|
|
|
|
while (obid != -1) {
|
|
|
|
c->obpile->oblist[obcount] = obid;
|
|
|
|
obcount++;
|
|
|
|
fscanf(f, "ob:%ld\n",&obid);
|
|
|
|
}
|
|
|
|
// terminate with -1s!
|
|
|
|
for (i = obcount ; i < MAXPILEOBS; i++) {
|
|
|
|
c->obpile->oblist[i] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// load object definitions
|
|
|
|
if (db) dblog("--> Loading object definitions for map obs...\n");
|
|
|
|
fscanf(f, "MAPOBS:%d\n",&obcount); // how many obs?
|
|
|
|
|
|
|
|
// create all objects in a dummy cell
|
|
|
|
for (i = 0; i < obcount; i++) {
|
2010-12-07 18:34:26 +11:00
|
|
|
long thisid;
|
|
|
|
if (db) dblog("-----> loading into dummycell: mapob %d/%d...\n",i+1,obcount);
|
|
|
|
if (loadob(f, dummycell->obpile, &thisid)) {
|
2010-12-02 12:17:54 +11:00
|
|
|
dblog("Error - can't create object %d/%d!\n",i+1,obcount);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
if (db) dblog("----------> got obid %ld\n",thisid);
|
|
|
|
// check!
|
|
|
|
if (!hasobid(dummycell->obpile, thisid)) {
|
|
|
|
dblog("Error: after loading obid %ld, can't find it in dummycell!\n",thisid);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-02 12:17:54 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
// hand out the objects to lifeforms...
|
2010-12-07 18:34:26 +11:00
|
|
|
/*
|
2010-12-02 12:17:54 +11:00
|
|
|
for (l = m->lf ; l ; l = l->next) {
|
|
|
|
int curob = 0;
|
|
|
|
long obid;
|
|
|
|
obid = l->pack->oblist[curob];
|
|
|
|
while (obid != -1) {
|
|
|
|
int found = B_FALSE;
|
|
|
|
// find this ob id in the dummycell
|
|
|
|
for (o = dummycell->obpile->first ; o ; o = nexto) {
|
|
|
|
nexto = o->next;
|
|
|
|
if (o->id == obid) {
|
|
|
|
relinkob(o, l->pack);
|
|
|
|
found = B_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
2010-12-07 18:34:26 +11:00
|
|
|
dblog("Error loading obs - lf %d should have obid %ld but can't find it in dummycell.\n",l->id, obid);
|
2010-12-02 12:17:54 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
// next one
|
|
|
|
curob++;
|
|
|
|
obid = l->pack->oblist[curob];
|
|
|
|
|
|
|
|
}
|
|
|
|
// clear the oblist
|
|
|
|
for (i = 0; i < MAXPILEOBS; i++) {
|
|
|
|
l->pack->oblist[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
*/
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// hand out objects to cells
|
|
|
|
for (y = 0; y < m->h; y++) {
|
|
|
|
for (x = 0; x < m->w; x++) {
|
|
|
|
cell_t *c;
|
|
|
|
long obid;
|
|
|
|
int curob = 0;
|
|
|
|
c = m->cell[y * m->w + x];
|
|
|
|
|
|
|
|
obid = c->obpile->oblist[curob];
|
2010-12-07 18:34:26 +11:00
|
|
|
dblog("Handing out objects to cell %d,%d\n",x,y);
|
2010-12-02 12:17:54 +11:00
|
|
|
while (obid != -1) {
|
2010-12-07 18:34:26 +11:00
|
|
|
dblog(" Looking for obid %ld in dummycell...",obid);
|
2010-12-02 12:17:54 +11:00
|
|
|
// find this ob id in the dummycell
|
2010-12-07 18:34:26 +11:00
|
|
|
o = hasobid(dummycell->obpile, obid);
|
|
|
|
if (o) {
|
|
|
|
dblog(" Got it.");
|
|
|
|
relinkob(o, c->obpile);
|
|
|
|
} else {
|
|
|
|
dblog(" Error loading obs - cell %d,%d should have obid %ld but can't find it.\n",x,y, obid);
|
2010-12-02 12:17:54 +11:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
// next one
|
|
|
|
curob++;
|
2010-12-07 18:34:26 +11:00
|
|
|
obid = c->obpile->oblist[curob];
|
2010-12-02 12:17:54 +11:00
|
|
|
}
|
|
|
|
// clear the oblist
|
|
|
|
for (i = 0; i < MAXPILEOBS; i++) {
|
|
|
|
c->obpile->oblist[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 06:30:58 +10:00
|
|
|
|
|
|
|
// load flags
|
|
|
|
loadflagpile(f, m->flags);
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
// move lifeforms to their proper locations
|
|
|
|
for (l = m->lf ; l ; l = l->next) {
|
|
|
|
cell_t *c;
|
|
|
|
c = getcellat(m, l->x, l->y);
|
|
|
|
if (!c) {
|
|
|
|
dblog("Error loading map - Can't find cell at %d,%d to place lifeform id %d.\n",
|
|
|
|
l->x, l->y, l->id);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
movelf(l, c);
|
|
|
|
//dblog("Moving lf %d to %d,%d\n",l->id, l->x, l->y);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(dummycell);
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
// successful load - kill the map now
|
|
|
|
unlink(filename);
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
int loadob(FILE *f, obpile_t *op, long *id) {
|
2010-12-02 12:17:54 +11:00
|
|
|
objecttype_t *ot;
|
|
|
|
object_t *o;
|
|
|
|
material_t *mat;
|
|
|
|
long obid;
|
|
|
|
int otid,matid;
|
|
|
|
char buf[BUFLEN];
|
2010-12-07 18:34:26 +11:00
|
|
|
int db = B_TRUE;
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
fscanf(f, "id:%ld\n",&obid);
|
|
|
|
fscanf(f, "type:%d\n",&otid);
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
if (db) dblog("... loading object id %ld",obid);
|
|
|
|
if (id) {
|
|
|
|
*id = obid;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
ot = findot(otid);
|
|
|
|
if (!ot) {
|
2011-02-01 06:16:13 +11:00
|
|
|
dblog("ERROR loading objects - can't find obtype id %d (obj id %ld)\n",otid,obid);
|
2010-12-02 12:17:54 +11:00
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
// create the object
|
2010-12-07 18:34:26 +11:00
|
|
|
o = addobject(op, ot->name, B_NOSTACK); // no stacking!
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// overwrite ob parameters
|
|
|
|
o->id = obid;
|
|
|
|
fscanf(f, "material:%d\n",&matid);
|
|
|
|
mat = findmaterial(matid);
|
|
|
|
if (!mat) {
|
|
|
|
dblog("ERROR loading objects - can't find material %d\n",matid);
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
o->material = mat;
|
|
|
|
|
|
|
|
fscanf(f, "weight:%f\n",&o->weight);
|
|
|
|
|
|
|
|
fgets(buf, BUFLEN, f); // inscription
|
|
|
|
buf[strlen(buf)-1] = '\0'; // strip newline
|
|
|
|
o->inscription = strdup(buf + 6); // after 'inscr:'
|
|
|
|
if (!strcmp(o->inscription, "^^^")) { // ie. if equal to ^^^...
|
|
|
|
free(o->inscription);
|
|
|
|
o->inscription = NULL;
|
|
|
|
}
|
|
|
|
fscanf(f, "letter:%c\n",&o->letter);
|
|
|
|
fscanf(f, "bless:%d\n",&o->blessed);
|
|
|
|
fscanf(f, "blessknown:%d\n",&o->blessknown);
|
|
|
|
fscanf(f, "amt:%d\n",&o->amt);
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "birthtime:%ld\n",&o->birthtime);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
// now remove ALL obejct flags (which were inherited
|
|
|
|
// from the obtype during addobject() ). these will be
|
|
|
|
// loaded in instead.
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
while (o->flags->first) {
|
|
|
|
killflag(o->flags->first);
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
fscanf(f, "flags:\n");
|
2010-12-02 12:17:54 +11:00
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
dblog("About to start loading object flags...");
|
|
|
|
loadflagpile(f, o->flags);
|
2010-12-02 12:17:54 +11:00
|
|
|
fscanf(f, "endob\n");
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int loadsavegame(void) {
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
|
|
|
char filename[BUFLEN];
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
// now see if there is a savegame...
|
|
|
|
dir = opendir(SAVEDIR);
|
|
|
|
if (!dir) {
|
|
|
|
dblog("Could not open savegame directory '%s'",SAVEDIR);
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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") ) {
|
|
|
|
sprintf(filename, "%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);
|
|
|
|
}
|
|
|
|
if (!loadlf(f, NULL)) {
|
|
|
|
printf("Error loading savegame from file '%s'",ent->d_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-07 18:34:26 +11:00
|
|
|
if (loadknowledge(f)) {
|
|
|
|
printf("Error loading knowledge from file '%s'",ent->d_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-01 06:16:13 +11:00
|
|
|
if (loadvars(f)) {
|
|
|
|
printf("Error loading game variables from file '%s'",ent->d_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-12-02 12:17:54 +11:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
// successful load - kill the savegame now
|
|
|
|
unlink(filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int savevars(FILE *f) {
|
|
|
|
int db = B_FALSE;
|
|
|
|
if (db) dblog("--> Saving knowledge...\n");
|
|
|
|
fprintf(f, "startvars\n");
|
|
|
|
fprintf(f, "curtime:%ld\n",curtime);
|
|
|
|
fprintf(f, "endvars\n");
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int saveflagpile(FILE *f, flagpile_t *fp) {
|
|
|
|
flag_t *fl;
|
|
|
|
fprintf(f, "flags:\n");
|
|
|
|
for (fl = fp->first ; fl ; fl = fl->next) {
|
|
|
|
fprintf(f, "%d,%d,%d,%d,%d,%d,%d,%ld\n",
|
|
|
|
fl->id, fl->nvals, fl->val[0], fl->val[1], fl->val[2],fl->lifetime,fl->known,fl->obfrom);
|
|
|
|
if (!fl->text || !strcmp(fl->text, "")) {
|
|
|
|
fprintf(f, "%s\n","^^^");
|
|
|
|
} else {
|
|
|
|
fprintf(f, "%s\n",fl->text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f, "-1,-1,-1,-1,-1,-1,-1,-1\n");
|
2010-12-02 12:17:54 +11:00
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-07 18:34:26 +11:00
|
|
|
int saveknowledge(FILE *f) {
|
|
|
|
int db = B_FALSE;
|
|
|
|
knowledge_t *k;
|
|
|
|
if (db) dblog("--> Saving knowledge...\n");
|
|
|
|
fprintf(f, "startknowledge\n");
|
|
|
|
|
|
|
|
for (k = knowledge; k ; k = k->next) {
|
|
|
|
fprintf(f, "%d^%s^%d\n",k->id, k->hiddenname, k->known);
|
|
|
|
}
|
|
|
|
fprintf(f, "endknowledge\n");
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
int savelf(FILE *f, lifeform_t *l) {
|
|
|
|
object_t *o;
|
|
|
|
int obcount = 0;
|
|
|
|
// save this lf
|
|
|
|
fprintf(f, "startlf\n");
|
|
|
|
fprintf(f, "lfid: %d\n",l->id);
|
|
|
|
fprintf(f, "race: %d\n",l->race->id);
|
|
|
|
fprintf(f, "map: %d\n",l->cell->map->id);
|
|
|
|
fprintf(f, "pos: %d,%d\n",l->cell->x, l->cell->y);
|
2010-12-07 18:34:26 +11:00
|
|
|
fprintf(f, "level: %d\n",l->level);
|
2011-04-14 09:44:29 +10:00
|
|
|
fprintf(f, "newlevel: %d\n",l->newlevel);
|
2011-02-01 06:16:13 +11:00
|
|
|
// liefform will be created after loading the above.
|
|
|
|
fprintf(f, "str: %d/%d\n",l->att[A_STR],l->baseatt[A_STR]);
|
|
|
|
fprintf(f, "dex: %d/%d\n",l->att[A_DEX],l->baseatt[A_DEX]);
|
|
|
|
fprintf(f, "int: %d/%d\n",l->att[A_IQ],l->baseatt[A_IQ]);
|
|
|
|
fprintf(f, "xp: %ld\n",l->xp);
|
2011-03-16 15:45:46 +11:00
|
|
|
fprintf(f, "skp: %d\n",l->skillpoints);
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "contr: %d\n",l->controller);
|
|
|
|
fprintf(f, "hp: %d/%d\n",l->hp, l->maxhp);
|
2011-02-01 06:16:13 +11:00
|
|
|
fprintf(f, "mp: %d/%d\n",l->mp, l->maxmp);
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "alive: %d\n",l->alive);
|
2011-02-01 06:16:13 +11:00
|
|
|
fprintf(f, "lastdamtype: %d\n",l->lastdamtype);
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "lastdam: %s\n",l->lastdam);
|
|
|
|
fprintf(f, "timespent: %d\n",l->timespent);
|
|
|
|
fprintf(f, "sorted: %d\n",l->sorted);
|
2011-02-01 06:16:13 +11:00
|
|
|
fprintf(f, "polyrevert: %d\n",l->polyrevert);
|
2010-12-07 18:34:26 +11:00
|
|
|
fprintf(f, "forgettimer: %f\n",l->forgettimer);
|
2011-02-01 06:16:13 +11:00
|
|
|
|
|
|
|
// lf flags
|
|
|
|
saveflagpile(f, l->flags);
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
// lifeform objects
|
|
|
|
obcount = 0;
|
|
|
|
for (o = l->pack->first ; o ; o = o->next) {
|
|
|
|
fprintf(f, "ob:%ld\n",o->id);
|
|
|
|
obcount++;
|
|
|
|
}
|
|
|
|
fprintf(f, "ob:-1\n");
|
|
|
|
|
|
|
|
fprintf(f, "obdefs\n");
|
|
|
|
|
|
|
|
// now save our object definitions
|
|
|
|
for (o = l->pack->first ; o ; o = o->next) {
|
|
|
|
saveob(f, o);
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:16:13 +11:00
|
|
|
int savegame(void) {
|
|
|
|
map_t *m;
|
|
|
|
FILE *f;
|
|
|
|
char buf[BUFLEN];
|
|
|
|
int rv;
|
|
|
|
for (m = firstmap; m ; m = m->next) {
|
|
|
|
// save world
|
|
|
|
rv = savemap(m);
|
|
|
|
if (rv) {
|
|
|
|
msg("Could not save map '%s'",m->name);
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
// save player + their objects
|
|
|
|
sprintf(buf, "%s/game.sav",SAVEDIR);
|
|
|
|
f = fopen(buf, "wt");
|
|
|
|
if (!f) {
|
|
|
|
msg("Could not open save file!");
|
|
|
|
return B_TRUE;
|
|
|
|
}
|
|
|
|
savelf(f, player);
|
|
|
|
saveknowledge(f);
|
|
|
|
savevars(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
int savemap(map_t *m) {
|
|
|
|
FILE *f;
|
|
|
|
char filename[BUFLEN];
|
|
|
|
int i;
|
|
|
|
object_t *o;
|
|
|
|
lifeform_t *l;
|
|
|
|
int x,y;
|
|
|
|
int obcount = 0;
|
|
|
|
|
|
|
|
// TODO: check that map dir exists
|
|
|
|
sprintf(filename, "%s/map%d.map",MAPDIR, m->id);
|
|
|
|
f = fopen(filename, "wt");
|
|
|
|
|
|
|
|
// save map info
|
|
|
|
fprintf(f, "id:%d\n",m->id); // map id
|
2011-02-01 06:16:13 +11:00
|
|
|
fprintf(f, "depth:%d\n",m->depth); // map depth
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "name:%s\n",m->name); // map name
|
2011-06-22 16:01:48 +10:00
|
|
|
fprintf(f, "habitat:%d\n",m->habitat->id); // habitat
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "seed:%d\n",m->seed); // seed
|
|
|
|
fprintf(f, "dims:%d,%d\n",m->w, m->h); // map dimensons
|
|
|
|
fprintf(f, "nextmaps:\n");
|
|
|
|
for (i = 0; i < MAXDIR_ORTH; i++) {
|
|
|
|
fprintf(f, "%d\n",m->nextmap[i] ); // map dimensons
|
|
|
|
}
|
2011-03-24 16:09:31 +11:00
|
|
|
fprintf(f, "beingcreated:%d\n",m->beingcreated);
|
2010-12-02 12:17:54 +11:00
|
|
|
|
|
|
|
// save all non-player lifeforms (includes their objects)
|
|
|
|
fprintf(f, "lifeforms:\n");
|
|
|
|
for (l = m->lf ; l ; l = l->next) {
|
|
|
|
if (l->controller != C_PLAYER) { // don't save the player!
|
|
|
|
savelf(f, l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(f, "endlifeforms\n");
|
|
|
|
|
|
|
|
// cells
|
|
|
|
fprintf(f, "cells:\n");
|
|
|
|
for (y = 0; y < m->h; y++) {
|
|
|
|
for (x = 0; x < m->w; x++) {
|
|
|
|
cell_t *c;
|
|
|
|
c = getcellat(m, x, y);
|
|
|
|
// cell info
|
2011-05-20 06:30:58 +10:00
|
|
|
fprintf(f, "%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
|
|
|
|
c->roomid, c->type->id, c->known, c->knownglyph.ch, c->knownglyph.colour, c->visited,c->lit,c->origlit,c->littimer);
|
2010-12-02 12:17:54 +11:00
|
|
|
// cell objects
|
|
|
|
for (o = c->obpile->first ; o ; o = o->next) {
|
|
|
|
fprintf(f, "ob:%ld\n",o->id);
|
|
|
|
obcount++;
|
|
|
|
}
|
|
|
|
fprintf(f, "ob:-1\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save object definitions from map cells
|
|
|
|
fprintf(f, "MAPOBS:%d\n",obcount);
|
|
|
|
for (y = 0; y < m->h; y++) {
|
|
|
|
for (x = 0; x < m->w; x++) {
|
|
|
|
cell_t *c;
|
|
|
|
c = getcellat(m, x, y);
|
|
|
|
// cell objects
|
|
|
|
for (o = c->obpile->first ; o ; o = o->next) {
|
|
|
|
saveob(f, o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 06:30:58 +10:00
|
|
|
saveflagpile(f, m->flags);
|
|
|
|
|
2010-12-02 12:17:54 +11:00
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int saveob(FILE *f, object_t *o) {
|
|
|
|
fprintf(f, "id:%ld\n",o->id);
|
|
|
|
fprintf(f, "type:%d\n",o->type->id);
|
|
|
|
fprintf(f, "material:%d\n",o->material->id);
|
|
|
|
fprintf(f, "weight:%f\n",o->weight);
|
|
|
|
fprintf(f, "inscr:%s\n",o->inscription ? o->inscription : "^^^");
|
|
|
|
fprintf(f, "letter:%c\n",o->letter);
|
|
|
|
fprintf(f, "bless:%d\n",o->blessed);
|
|
|
|
fprintf(f, "blessknown:%d\n",o->blessknown);
|
|
|
|
fprintf(f, "amt:%d\n",o->amt);
|
2011-02-01 06:16:13 +11:00
|
|
|
fprintf(f, "birthtime:%ld\n",o->birthtime);
|
|
|
|
saveflagpile(f, o->flags);
|
2010-12-02 12:17:54 +11:00
|
|
|
fprintf(f, "endob\n");
|
|
|
|
return B_FALSE;
|
|
|
|
}
|