nexus/nexus.c

1080 lines
24 KiB
C
Raw Normal View History

2011-02-01 06:16:13 +11:00
#include <assert.h>
2010-12-02 12:17:54 +11:00
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2011-02-01 06:16:13 +11:00
#include <time.h>
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
#include <unistd.h>
2011-02-01 06:16:13 +11:00
#include "ai.h"
#include "attack.h"
2010-12-02 12:17:54 +11:00
#include "io.h"
2011-02-01 06:16:13 +11:00
#include "flag.h"
2010-12-02 12:17:54 +11:00
#include "lf.h"
#include "map.h"
2011-02-01 06:16:13 +11:00
#include "move.h"
2010-12-02 12:17:54 +11:00
#include "nexus.h"
#include "objects.h"
#include "save.h"
2011-02-01 06:16:13 +11:00
#include "text.h"
2010-12-02 12:17:54 +11:00
material_t *material = NULL,*lastmaterial = NULL;
objectclass_t *objectclass = NULL,*lastobjectclass = NULL;
objecttype_t *objecttype = NULL,*lastobjecttype = NULL;
2011-03-10 16:47:18 +11:00
brand_t *firstbrand = NULL,*lastbrand = NULL;
obmod_t *firstobmod = NULL,*lastobmod = NULL;
2010-12-02 12:17:54 +11:00
celltype_t *firstcelltype = NULL,*lastcelltype = NULL;
2011-03-04 12:22:36 +11:00
command_t *firstcommand = NULL,*lastcommand = NULL;
2010-12-02 12:17:54 +11:00
race_t *firstrace = NULL,*lastrace = NULL;
2011-02-01 06:16:13 +11:00
job_t *firstjob = NULL,*lastjob = NULL;
2011-03-10 16:47:18 +11:00
skill_t *firstskill = NULL,*lastskill = NULL;
2010-12-02 12:17:54 +11:00
map_t *firstmap = NULL,*lastmap = NULL;
2010-12-07 18:34:26 +11:00
knowledge_t *knowledge = NULL, *lastknowledge = NULL;
2011-03-10 16:47:18 +11:00
hiddenname_t *firsthiddenname = NULL, *lasthiddenname = NULL;
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// maintains unique lifeform ID numbers
long nextlfid = 0;
int SCREENW = DEF_SCREENW;
int SCREENH = DEF_SCREENH;
// object return list
object_t *retobs[MAXPILEOBS+1];
int retobscount[MAXPILEOBS+1];
int nretobs = 0;
2010-12-02 12:17:54 +11:00
FILE *logfile;
2011-02-01 06:16:13 +11:00
prompt_t prompt;
char msghist[MAXHISTORY][BUFLEN];
int nmsghist = 0;
2010-12-02 12:17:54 +11:00
enum ERROR reason; // global for returning errors
2011-02-01 06:16:13 +11:00
void *rdata; // globel for returning data
2010-12-02 12:17:54 +11:00
lifeform_t *player = NULL;
int gameover;
enum GAMEMODE gamemode = GM_FIRST;
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
long curtime = 0;
long timeleft = 0;
extern int statdirty;
int needredraw = B_TRUE;
int numdraws = 0;
int main(int argc, char **argv) {
2010-12-02 12:17:54 +11:00
int newworld = B_FALSE;
2011-02-01 06:16:13 +11:00
object_t *o;
2011-03-11 12:25:38 +11:00
char welcomemsg[BUFLEN];
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
int ch;
FILE *playerfile = NULL;
2010-12-02 12:17:54 +11:00
atexit(cleanup);
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
while ((ch = getopt(argc, argv, "f:")) != -1) {
switch (ch) {
case 'f':
playerfile = fopen(optarg, "rt");
if (!playerfile) {
fprintf(stderr, "cannot open player file: %s\n",optarg);
exit(1);
}
break;
case 'h':
case '?':
default:
usage(argv[0]);
exit(0);
}
}
2010-12-02 12:17:54 +11:00
// init params
2011-02-01 06:16:13 +11:00
if (init()) {
exit(1);
}
2010-12-02 12:17:54 +11:00
// load whatever maps are available
loadall();
// init graphics
initgfx();
// if no maps, make the initial level
if (!firstmap) {
newworld = B_TRUE;
addmap();
2011-02-01 06:16:13 +11:00
createmap(firstmap, 1, H_DUNGEON, NULL, findot(OT_STAIRSUP));
2010-12-02 12:17:54 +11:00
}
2010-12-07 18:34:26 +11:00
if (!knowledge) {
2011-02-01 06:16:13 +11:00
// populate scroll, potion, etc names
2010-12-07 18:34:26 +11:00
genhiddennames();
}
// if no player (ie. didn't load a game), add them
2010-12-02 12:17:54 +11:00
if (!player) {
2011-02-01 06:16:13 +11:00
char *user;
char pname[BUFLEN];
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
char buf[BUFLEN];
job_t *j = NULL;
2011-02-01 06:16:13 +11:00
char ch;
cell_t *where;
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
// read from input file if required
if (playerfile) {
char *p;
while (!feof(playerfile)) {
fgets(buf, BUFLEN, playerfile);
buf[strlen(buf)-1] = '\0';
if (strstr(buf, "job:") == buf) {
p = buf + strlen("job:");
j = findjobbyname(p);
if (j) break;
}
}
fseek(playerfile, 0, SEEK_SET);
2011-02-01 06:16:13 +11:00
}
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
if (!j) {
// ask for race
initprompt(&prompt, "Select your job:");
ch = 'a';
for (j = firstjob ; j ; j = j->next) {
addchoice(&prompt, ch++, j->name, NULL, j);
}
j = NULL;
while (!j) {
getchoice(&prompt);
j = prompt.result;
}
2011-02-01 06:16:13 +11:00
}
// find staircase
where = findobinmap(firstmap, OT_STAIRSUP);
assert(where);
// make sure no lifeforms are there
if (where->lf) {
killlf(where->lf);
}
2010-12-07 18:34:26 +11:00
// add player
2011-02-01 06:16:13 +11:00
real_addlf(where, R_HUMAN, 1, C_PLAYER); // this will assign 'player'
user = getenv("USER");
if (user) {
addflag(player->flags, F_NAME, NA, NA, NA, getenv("USER"));
} else {
addflag(player->flags, F_NAME, NA, NA, NA, "Anonymous");
}
givejob(player, j->id);
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
if (playerfile) {
if (parseplayerfile(playerfile, player)) {
// error!
exit(0);
}
fclose(playerfile);
}
2011-02-01 06:16:13 +11:00
// player needs hunger
addflag(player->flags, F_HUNGER, 0, NA, NA, NULL);
getplayernamefull(pname);
2011-03-11 12:25:38 +11:00
sprintf(welcomemsg, "Greetings %s, welcome to %snexus!", pname, newworld ? "the new " : "");
2010-12-07 18:34:26 +11:00
// XXX testing
//addlf(getcellindir(player->cell, D_N), R_GOBLIN, 1);
2011-02-01 06:16:13 +11:00
// 00:00 - 23:59
curtime = rnd(0,86399);
2010-12-02 12:17:54 +11:00
} else {
2011-03-11 12:25:38 +11:00
sprintf(welcomemsg, "Welcome back!");
2010-12-02 12:17:54 +11:00
}
// start game - this will cause debug messages to now
// go to the log file instead of stdout.
gamemode = GM_GAMESTARTED;
2011-02-01 06:16:13 +11:00
timeleft = 0; // reset game timer
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// calculate initial light
calclight(player->cell->map);
// pre-calc line-of-sight for player
precalclos(player);
2010-12-02 12:17:54 +11:00
// show level
drawscreen();
2011-03-11 12:25:38 +11:00
msg("%s",welcomemsg);
more();
2010-12-02 12:17:54 +11:00
// MAIN LOOP
2011-02-01 06:16:13 +11:00
// basic flow is:
//
// donextturn() - process a turn for a lifeform
// turneffectslf() Rest effects, Damage from floor objects, etc
// lifeform takes action
// checkdeath() - check for object/player death. remove dead things.
// timeeffectsworld() Fires burn out, ice melts, etc
// Also keeps lf->timespent values under control.
//
//
// redraw screen
//
// checkendgame() - has the game ended yet?
2010-12-02 12:17:54 +11:00
gameover = B_FALSE;
while (!gameover) {
2011-02-01 06:16:13 +11:00
map_t *curmap;
curmap = player->cell->map;
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// default to no redraw - donextturn() will change this if needed.
needredraw = B_FALSE;
numdraws = 0;
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// someone has a turn - this will then call taketime -> timehappens();
donextturn(curmap);
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// update lifeform structue to figure out who goes next
//timehappens(curmap);
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// show level (if required)
//if (haslos(player, curmap->lf->cell)) {
2010-12-02 12:17:54 +11:00
drawscreen();
2011-02-01 06:16:13 +11:00
//dblog("**** END of turn, numdraws = %d", numdraws);
2010-12-02 12:17:54 +11:00
// check end of game
checkendgame();
}
2011-02-01 06:16:13 +11:00
// identify all objects
for (o = player->pack->first ; o ; o = o->next) {
identify(o);
}
// show possessions
dofinaloblist(player->pack);
2010-12-02 12:17:54 +11:00
// print tombstone
tombstone(player);
2011-02-01 06:16:13 +11:00
return B_FALSE;
2010-12-02 12:17:54 +11:00
}
2011-02-01 06:16:13 +11:00
celltype_t *addcelltype(int id, char *name, char glyph, int solid, int transparent, enum MATERIAL mat) {
2010-12-02 12:17:54 +11:00
celltype_t *a;
// add to the end of the list
if (firstcelltype == NULL) {
firstcelltype = malloc(sizeof(celltype_t));
a = firstcelltype;
a->prev = NULL;
} else {
// go to end of list
a = lastcelltype;
a->next = malloc(sizeof(celltype_t));
a->next->prev = a;
a = a->next;
}
lastcelltype = a;
a->next = NULL;
// set props
a->id = id;
2011-02-01 06:16:13 +11:00
a->name = strdup(name);
2010-12-02 12:17:54 +11:00
a->glyph = glyph;
a->solid = solid;
a->transparent = transparent;
2011-02-01 06:16:13 +11:00
a->material = findmaterial(mat);
a->flags = addflagpile(NULL, NULL);
return a;
}
2011-03-04 12:22:36 +11:00
command_t *addcommand(enum COMMAND id, char ch, char *desc) {
command_t *a;
// add to the end of the list
if (firstcommand == NULL) {
firstcommand = malloc(sizeof(command_t));
a = firstcommand;
a->prev = NULL;
} else {
// go to end of list
a = lastcommand;
a->next = malloc(sizeof(command_t));
a->next->prev = a;
a = a->next;
}
lastcommand = a;
a->next = NULL;
// set props
a->id = id;
a->ch = ch;
a->desc = strdup(desc);
return a;
}
2011-02-01 06:16:13 +11:00
void checkdeath(void) {
lifeform_t *lf, *nextlf;
int x,y;
for (lf = player->cell->map->lf; lf ; lf = nextlf) {
nextlf = lf->next;
// check for death
if (lf->hp <= 0) {
// die!
die(lf);
continue;
}
// check for object death
removedeadobs(lf->pack);
}
// check for object death on map
for (y = 0; y < player->cell->map->h; y++) {
for (x = 0; x < player->cell->map->w; x++) {
cell_t *c;
c = getcellat(player->cell->map, x, y);
if (c) {
removedeadobs(c->obpile);
}
}
}
2010-12-02 12:17:54 +11:00
}
2011-02-01 06:16:13 +11:00
2010-12-02 12:17:54 +11:00
void checkendgame(void) {
if (!player->alive) {
gameover = B_TRUE;
}
}
void cleanup(void) {
fclose(logfile);
cleanupgfx();
// free maps
// free knowledge
2011-03-10 16:47:18 +11:00
// free brands
// free obtypes
// free objects
// free materials
// free races
2010-12-02 12:17:54 +11:00
}
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
void dobresnham(int d, int xinc1, int yinc1, int dinc1, int xinc2, int yinc2, int dinc2, int *xinc, int *yinc, int *dinc) {
if (d < 0) {
*xinc = xinc1;
*yinc = yinc1;
*dinc = dinc1;
} else {
*xinc = xinc2;
*yinc = yinc2;
*dinc = dinc2;
}
}
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
void donextturn(map_t *map) {
lifeform_t *who;
int db = B_FALSE;
2011-02-01 06:16:13 +11:00
who = map->lf;
if (db) dblog("**** donextturn for: id %d %s", who->id, who->race->name);
2011-02-01 06:16:13 +11:00
turneffectslf(who);
// calculate light
calclight(map);
// pre-calculate line of sight for this lifeform
precalclos(who);
2011-03-16 15:45:46 +11:00
if (isplayer(who) || cansee(player, who)) {
2011-02-01 06:16:13 +11:00
needredraw = B_TRUE;
drawscreen();
2010-12-02 12:17:54 +11:00
}
2011-02-01 06:16:13 +11:00
// update gun targets
autotarget(who);
assert(who->timespent == 0);
// keep looping until they actually do something or are dead!
while (who->timespent == 0) {
if (isdead(who)) {
// skip turn
taketime(who, SPEED_DEAD);
} else {
// do we need to run away from something?
if (!flee(who)) {
int donormalmove = B_TRUE;
flag_t *f;
if (donormalmove) {
// paralyzed etc?
2011-03-04 12:22:36 +11:00
if (isimmobile(who)) {
2011-02-01 06:16:13 +11:00
rest(who, B_FALSE);
donormalmove = B_FALSE;
}
}
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
// resting?
if (donormalmove) {
f = hasflag(who->flags, F_RESTING);
if (f) {
rest(who, B_TRUE);
donormalmove = B_FALSE;
2011-02-01 06:16:13 +11:00
}
}
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
if (donormalmove) {
if (isplayer(who)) {
drawcursor();
// find out what player wants to do
handleinput();
} else {
// do ai move
aimove(who);
}
}
}
}
}
2010-12-02 12:17:54 +11:00
2011-03-04 12:22:36 +11:00
if (hasflag(player->flags, F_RESTING)) {
// ooo is this right ?
needredraw = B_FALSE;
2011-03-16 15:45:46 +11:00
} else if (isdead(who) || cansee(player, who)) {
2011-02-01 06:16:13 +11:00
needredraw = B_TRUE;
2010-12-02 12:17:54 +11:00
}
2011-02-01 06:16:13 +11:00
// check for death etc
checkdeath();
//////////////////////////////////
// effects which happen every GAME TICK
// ie. object hp drain etc
//////////////////////////////////
// note: can't use 'who->' below since 'who' might have died
// and been de-alloced during checkdeath() above.
timeeffectsworld(player->cell->map); // in case the player changed levels!
2010-12-02 12:17:54 +11:00
}
celltype_t *findcelltype(int id) {
celltype_t *ct;
for (ct = firstcelltype; ct ; ct = ct->next) {
if (ct->id == id) {
return ct;
}
}
return NULL;
}
char *getdirname(int dir) {
switch (dir) {
case D_N:
return "North";
case D_E:
return "East";
case D_S:
return "South";
case D_W:
return "West";
2011-02-01 06:16:13 +11:00
case D_UP:
return "up";
case D_DOWN:
return "down";
2010-12-02 12:17:54 +11:00
case D_UNKNOWN:
return "D_UNKNOWN";
case D_NONE:
return "D_NONE";
case DC_N:
return "North";
case DC_NE:
return "Northeast";
case DC_E:
return "East";
case DC_SE:
return "Southeast";
case DC_S:
return "South";
case DC_SW:
return "Southwest";
case DC_W:
return "West";
case DC_NW:
return "Northwest";
2010-12-02 12:17:54 +11:00
}
return "?errordir?";
}
2011-02-01 06:16:13 +11:00
void getrarity(int depth, int *min, int *max, int range) {
int mid;
mid = 100 - (depth * 3);
*min = mid - range; if (*min < 0) *min = 0;
2011-03-04 12:22:36 +11:00
//*max = mid + range; if (*max > 100) *max = 100;
*max = 100;
2011-02-01 06:16:13 +11:00
2011-03-10 16:47:18 +11:00
if (*min > 85) *min = 85;
2011-02-01 06:16:13 +11:00
if (*max < 25) *max = 25;
}
2010-12-02 12:17:54 +11:00
int init(void) {
// random numbers
srand(time(NULL));
gamemode = GM_INIT;
2011-03-04 12:22:36 +11:00
initcommands();
2010-12-02 12:17:54 +11:00
initobjects();
2011-03-10 16:47:18 +11:00
initskills();
2011-02-01 06:16:13 +11:00
initjobs();
2010-12-02 12:17:54 +11:00
initrace();
2011-02-01 06:16:13 +11:00
// cell types
addcelltype(CT_WALL, "rock wall", '#', B_SOLID, B_OPAQUE, MT_STONE);
addcelltype(CT_ROOMWALL, "rock wall", '#', B_SOLID, B_OPAQUE, MT_STONE);
addcelltype(CT_CORRIDOR, "rock floor", '.', B_EMPTY, B_TRANS, MT_STONE);
addcelltype(CT_LOOPCORRIDOR, "rock floor", 'L', B_EMPTY, B_TRANS, MT_STONE);
addcelltype(CT_ROOM, "rock floor", '.', B_EMPTY, B_TRANS, MT_STONE);
//addcelltype(CT_DOOROPEN, "wooden door", '-', B_EMPTY, B_TRANS, MT_WOOD);
//addcelltype(CT_DOORCLOSED, "wooden door", '+', B_SOLID, B_OPAQUE, MT_WOOD);
gamemode = GM_VALIDATION;
2011-02-01 06:16:13 +11:00
if (validateobs()) {
return B_TRUE;
}
if (validateraces()) {
return B_TRUE;
}
// open log file
logfile = fopen("log.txt","wt");
fprintf(logfile, "\n\n\n====== NEW LOGFILE ====\n");
2010-12-02 12:17:54 +11:00
return B_FALSE;
}
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
void calcbresnham(map_t *m, int x1, int y1, int x2, int y2, cell_t **retcell, int *numpixels) {
int xinc1,xinc2,yinc1,yinc2,dinc1,dinc2,d;
int xinc,yinc,dinc;
int i;
int x,y;
initbresnham( x1, y1, x2, y2, &xinc1, &yinc1, &dinc1, &xinc2, &yinc2, &dinc2, numpixels, &d);
x = x1;
y = y1;
for (i = 0; i < *numpixels; i++) {
retcell[i] = getcellat(m, x, y);
dobresnham(d, xinc1, yinc1, dinc1, xinc2, yinc2, dinc2, &xinc, &yinc, &dinc);
// move to next cell
d += dinc;
x += xinc;
y += yinc;
}
}
void initbresnham(int x1, int y1, int x2, int y2, int *xinc1, int *yinc1, int *dinc1, int *xinc2, int *yinc2, int *dinc2, int *numpixels, int *d) {
int deltax,deltay;
deltax = (x2 - x1);
if (deltax < 0) deltax = -deltax;
deltay = (y2 - y1);
if (deltay < 0) deltay = -deltay;
if (deltax >= deltay) {
*numpixels = deltax + 1;
*d = (deltay*2) - deltax;
*dinc1 = deltay << 1;
*dinc2 = (deltay-deltax) << 1;
*xinc1 = 1;
*xinc2 = 1;
*yinc1 = 0;
*yinc2 = 1;
} else {
*numpixels = deltay + 1;
*d = (deltax*2) - deltay;
*dinc1 = deltax << 1;
*dinc2 = (deltax - deltay) << 1;
*xinc1 = 0;
*xinc2 = 1;
*yinc1 = 1;
*yinc2 = 1;
}
if (x1 > x2) {
*xinc1 = - *xinc1;
*xinc2 = - *xinc2;
}
if (y1 > y2) {
*yinc1 = - *yinc1;
*yinc2 = - *yinc2;
}
}
2011-03-04 12:22:36 +11:00
void initcommands(void) {
// Actions
addcommand(CMD_UP, '<', "Go up stairs.");
addcommand(CMD_DOWN, '>', "Go down stairs, enter a shop/portal.");
addcommand(CMD_REST, '.', "Rest once.");
addcommand(CMD_PICKUP, ',', "Pick up something from the ground.");
addcommand(CMD_CLOSE, 'c', "Close a door.");
addcommand(CMD_DROP, 'd', "Drop an item.");
addcommand(CMD_DROPMULTI, 'D', "Drop multiple items.");
addcommand(CMD_EAT, 'e', "Eat something.");
2011-03-16 15:45:46 +11:00
addcommand(CMD_EAT, 'E', "Enhance your skills.");
2011-03-04 12:22:36 +11:00
addcommand(CMD_MAGIC, 'm', "Use magic or abilities.");
2011-03-16 15:45:46 +11:00
addcommand(CMD_MEMMAGIC, 'M', "Memorise a magic shortcut");
2011-03-04 12:22:36 +11:00
addcommand(CMD_OPERATE, 'o', "Operate a tool/wand/device.");
addcommand(CMD_PICKLOCK, 'p', "Pick a lock.");
addcommand(CMD_POUR, 'P', "Pour a potion onto something.");
addcommand(CMD_QUAFF, 'q', "Quaff (drink) a potion.");
addcommand(CMD_READ, 'r', "Read a scroll/book.");
2011-03-16 15:45:46 +11:00
addcommand(CMD_RESTFULL, 'R', "Rest until healed, or train your skills.");
2011-03-04 12:22:36 +11:00
addcommand(CMD_TAKEOFF, 'T', "Take off an item of clothing/jewelery.");
addcommand(CMD_WEILD, 'w', "Weild a weapon.");
addcommand(CMD_WEAR, 'W', "Wear an item of clothing/jewelery.");
// Firearms
addcommand(CMD_FIRE, 'f', "Fire your firearm/bow at your current target.");
addcommand(CMD_FIRENEW, 'F', "Fire your firearm/bow at a new target.");
addcommand(CMD_AIM, 'a', "Aim your current firearm/bow at a new target.");
// Information
addcommand(CMD_HELP, '?', "Display this text.");
addcommand(CMD_INFOPLAYER, '@', "Display player stats.");
addcommand(CMD_INFOARMOUR, ']', "Display player armour.");
addcommand(CMD_FORCEATTACK, 'A', "Force an attack in a given direction.");
addcommand(CMD_LOOKHERE, ':', "Look at current cell.");
addcommand(CMD_LOOKAROUND, '/', "Look at a remote cell.");
addcommand(CMD_INFOKNOWLEDGE, '\\', "Display known items.");
addcommand(CMD_MSGHIST, '|', "Display message history.");
addcommand(CMD_INV, 'i', "Display your inventory.");
// GAME FUNCTIONS
addcommand(CMD_QUIT, 'Q', "Quit the game.");
addcommand(CMD_SAVEQUIT, 'S', "Save and quit the game.");
sortcommands();
}
2010-12-02 12:17:54 +11:00
int isplayerturn(void) {
2010-12-07 18:34:26 +11:00
if (!player) return B_FALSE;
2010-12-02 12:17:54 +11:00
if (player->cell->map->lf->controller == C_PLAYER) {
return B_TRUE;
}
return B_FALSE;
}
2011-03-04 12:22:36 +11:00
int limit(int *what, int min, int max) {
int limited = B_FALSE;
if (*what < min) {
*what = min;
limited = B_TRUE;
}
if (*what > max) {
*what = max;
limited = B_TRUE;
}
return limited;
}
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
int parseplayerfile(FILE *f, lifeform_t *lf) {
// add extra obs etc from f
char *pp;
char localbuf[BUFLEN];
char buf[BUFLEN];
int goterror = B_FALSE;
fgets(buf, BUFLEN, f);
while (!feof(f)) {
if (buf[strlen(buf)-1] == '\n') {
buf[strlen(buf)-1] = '\0';
}
//dblog("got line: [%s]",buf);
if (strstr(buf, "skill:") == buf) {
skill_t *sk;
enum SKILLLEVEL slev;
strcpy(localbuf, buf + strlen("skill:"));
pp = strtok(localbuf, " ");
if (!pp) {
dblog("ERROR in playerfile. unknown skill level in this line:\n%s\n",buf);
goterror = B_TRUE;
}
slev = findskilllevbyname(pp);
pp += (strlen(pp) + 1);
if (!pp) {
dblog("ERROR in playerfile. missing skill name in this line:\n%s\n",buf);
goterror = B_TRUE;
}
sk = findskillbyname(pp);
if (sk) {
giveskilllev(lf, sk->id, slev);
} else {
dblog("ERROR in playerfile. unknown skill (%s) in this line:\n%s\n",pp, buf);
goterror = B_TRUE;
}
} else if (strstr(buf, "ob:") == buf) {
object_t *o;
strcpy(localbuf, buf + strlen("ob:"));
o = addob(lf->pack, localbuf);
if (o) {
identify(o);
} else {
dblog("ERROR in playerfile. unknown object in this line:\n%s\n",buf);
goterror = B_TRUE;
}
}
fgets(buf, BUFLEN, f);
}
return goterror;
}
2011-02-01 06:16:13 +11:00
float pctof(float pct, float num) {
return ((pct / 100.0) * num);
}
2010-12-07 18:34:26 +11:00
// get a random number between min and max
2010-12-02 12:17:54 +11:00
int rnd(int min, int max) {
int res;
res = (rand() % (max - min + 1)) + min;
return res;
}
int roll(char *string) {
int ndice,nsides,bonus;
int roll;
texttodice(string, &ndice,&nsides,&bonus);
roll = rolldie(ndice, nsides) + bonus;
return roll;
}
2010-12-07 18:34:26 +11:00
// get a random number
int rolldie(int ndice, int sides) {
int i;
int res = 0;
for (i = 0; i < ndice; i++) {
res += rnd(1,sides);
}
return res;
}
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
int rollhitdice(lifeform_t *lf) {
flag_t *f;
int ndice, plus;
2011-03-10 16:47:18 +11:00
int roll = 0;
int i;
float mod;
int db = B_TRUE;
2011-02-01 06:16:13 +11:00
f = hasflag(lf->flags, F_HITDICE);
if (f) {
ndice = f->val[0];
if (f->val[1] == NA) plus = 0;
else plus = f->val[1];
} else {
ndice = 1;
plus = 0;
}
2011-03-10 16:47:18 +11:00
if (db && isplayer(lf)) dblog("rollhitdice() - rolling %dd4 + %d",ndice,plus);
mod = getstatmod(lf, A_CON);
if (mod > 0) mod *= 2;
if (db && isplayer(lf)) dblog("rollhitdice() - mod is +%0.0f%%",mod);
if (ndice == 0) {
int thisroll;
// just the bonus
thisroll = plus;
thisroll = thisroll + (int)((float)thisroll * (mod/100));
if (thisroll < 1) thisroll = 1;
roll += thisroll;
} else {
for (i = 0; i < ndice; i++) {
int thisroll;
thisroll = rolldie(1, 4) + plus;
if (thisroll < 1) thisroll = 1;
if (db && isplayer(lf)) dblog("rollhitdice() ---- die %d/%d == %d",i+1,ndice,thisroll);
roll += thisroll;
}
}
if (db && isplayer(lf)) dblog("TOTAL: %d",roll);
roll = roll + (int)((float)roll * (mod/100));
if (db && isplayer(lf)) dblog(" -> modified to: %d",roll);
2011-02-01 06:16:13 +11:00
return roll;
}
int rollmpdice(lifeform_t *lf) {
flag_t *f;
int ndice, plus;
int roll;
2011-03-16 15:45:46 +11:00
float mod;
2011-02-01 06:16:13 +11:00
f = hasflag(lf->flags, F_MPDICE);
if (f) {
ndice = f->val[0];
if (f->val[1] == NA) plus = 0;
else plus = f->val[1];
} else {
return 0;
}
2011-03-16 15:45:46 +11:00
mod = getstatmod(lf, A_IQ);
if (mod > 0) mod *= 2;
2011-02-01 06:16:13 +11:00
roll = rolldie(ndice, 4) + plus;
2011-03-16 15:45:46 +11:00
roll = roll + (int)((float)roll * (mod/100));
2011-02-01 06:16:13 +11:00
return roll;
}
/*
2010-12-02 12:17:54 +11:00
void sortlf(map_t *map) {
int donesomething;
2011-02-01 06:16:13 +11:00
int db = B_FALSE;
lifeform_t *l,*nextl;
int iter = 0;
2010-12-02 12:17:54 +11:00
// bubblesort
donesomething = B_TRUE;
2011-02-01 06:16:13 +11:00
dblog("doing sort...");
2010-12-02 12:17:54 +11:00
while (donesomething) {
donesomething = B_FALSE;
2011-02-01 06:16:13 +11:00
//dblog("ITER %d",iter++);
if (db) {
dblog("ITER %d",iter++);
for (l = map->lf ; l ; l = l->next) {
dblog("- %s (timespent= %d) (sorted=%d)", (l == player) ? "player" : l->race->name, l->timespent,l->sorted);
}
}
for (l = map->lf ; l->next ; l = nextl) {
nextl = l->next;
//if (!l->sorted && (l->timespent >= l->next->timespent) ) {
if (l->sorted) {
//dblog("skipping id %d %s, already sorted ",l->id, l->race->name);
continue;
}
if (l->timespent >= l->next->timespent) {
2010-12-02 12:17:54 +11:00
lifeform_t *temp;
2011-02-01 06:16:13 +11:00
//dblog("moving id %d %s upwards",l->id, l->race->name);
2010-12-02 12:17:54 +11:00
// remember next element
temp = l->next;
// remove this element from list
2011-02-01 06:16:13 +11:00
// don't bother checking if (l->next == NULL) as we know
// this won't be true due to the for loop condition
2010-12-02 12:17:54 +11:00
if (l->prev == NULL) {
// first
map->lf = l->next;
2011-02-01 06:16:13 +11:00
l->next->prev = NULL;
2010-12-02 12:17:54 +11:00
} else {
// not first
l->prev->next = l->next;
2011-02-01 06:16:13 +11:00
l->next->prev = l->prev;
}
// TESTING: re-add at correct position.
while (temp->next && (temp->next->timespent <= l->timespent)) {
//dblog("moving past %d %s (timespend=%d)...",temp->next->id, temp->next->race->name, temp->next->timespent);
temp = temp->next;
2010-12-02 12:17:54 +11:00
}
// re-add element afterwards
l->next = temp->next;
l->prev = temp;
temp->next = l;
2011-02-01 06:16:13 +11:00
if (l->next == NULL) {
map->lastlf = l;
} else {
l->next->prev = l;
}
l->sorted = B_TRUE;
2010-12-02 12:17:54 +11:00
donesomething = B_TRUE;
2011-02-01 06:16:13 +11:00
break;
2010-12-02 12:17:54 +11:00
} else {
l->sorted = B_TRUE;
}
}
}
2011-02-01 06:16:13 +11:00
//dblog("finished sort.");
// reset sorted var for next time
for (l = map->lf ; l->next ; l = l->next) {
l->sorted = B_FALSE;
}
// sanity check
if (player->next) {
assert(player->next->prev == player);
}
if (player->prev) {
assert(player->prev->next == player);
}
2010-12-02 12:17:54 +11:00
if (db) {
dblog("AFTER SORT:");
for (l = map->lf ; l ; l = l->next) {
2011-02-01 06:16:13 +11:00
// if (haslos(player, l->cell)) {
2010-12-07 18:34:26 +11:00
dblog("- %s (timespent= %d) (sorted=%d)", (l == player) ? "player" : l->race->name, l->timespent,l->sorted);
2011-02-01 06:16:13 +11:00
// }
2010-12-02 12:17:54 +11:00
}
}
2011-02-01 06:16:13 +11:00
}
*/
2011-03-04 12:22:36 +11:00
void sortcommands(void) {
command_t *c;
int donesomething = B_TRUE;
while (donesomething) {
donesomething = B_FALSE;
for (c = firstcommand ; c->next ; c = c->next) {
// move up one position if required.
if (c->ch > c->next->ch) {
command_t *temp;
// remember next element
temp = c->next;
// remove this element from list
if (c->prev == NULL) {
// first
firstcommand = c->next;
c->next->prev = NULL;
} else {
// not first
c->prev->next = c->next;
c->next->prev = c->prev;
}
// re-add element afterwards
c->next = temp->next;
c->prev = temp;
temp->next = c;
if (c->next == NULL) {
lastcommand = c;
} else {
c->next->prev = c;
}
// mark as done.
donesomething = B_TRUE;
break;
}
}
}
}
2011-02-01 06:16:13 +11:00
void timeeffectsworld(map_t *map) {
lifeform_t *l;
int db = B_FALSE;
2011-02-01 06:16:13 +11:00
object_t *o,*nexto;
int x,y;
long firstlftime;
2010-12-02 12:17:54 +11:00
// now go through the list and make the first element be 0
2011-02-01 06:16:13 +11:00
l = map->lf;
if (l) {
// if (db) dblog("first lf is: %s (id %ld)\n",l->race->name, l->id);
firstlftime = l->timespent;
assert(firstlftime >= 0);
} else {
dblog("no lifeforms on map!\n");
// no first lf!
firstlftime = 0;
2010-12-02 12:17:54 +11:00
}
2011-02-01 06:16:13 +11:00
//if (db) dblog("timespent = %d\n", timespent);
if (db) dblog("firstlftime = %d\n", firstlftime);
2011-02-01 06:16:13 +11:00
if (firstlftime > 0) {
if (db) dblog("making firstlf timespent = 0 (currently %d):", firstlftime);
2011-02-01 06:16:13 +11:00
//dumplf();
for (l = map->lf ; l ; l = l->next) {
//dblog("shuffling id %d %s timespent=%d -> %d",l->id,l->race->name, l->timespent, l->timespent - firstlftime);
l->timespent -= firstlftime;
assert(l->timespent >= 0);
if (isplayer(l)) {
statdirty = B_TRUE;
}
}
//dblog("after shuffle:");
//dumplf();
} else {
if (db) dblog("firstlf timespent is not greater than 0. no shuffle.");
2011-02-01 06:16:13 +11:00
}
timeleft += firstlftime;
// now do effects based on time...
while (timeleft >= TICK_INTERVAL) {
timeleft -= TICK_INTERVAL;
// global time-based effects on map or map objects
for (y = 0; y < map->h; y++) {
for (x = 0; x < map->w; x++) {
cell_t *c;
c = getcellat(map, x, y);
if (c) {
// go through each object in the cell...
for (o = c->obpile->first ; o ; o = nexto) {
nexto = o->next;
timeeffectsob(o);
} // end foreach object here
2011-03-10 16:47:18 +11:00
// expire light effects
if (c->littimer > 0) {
c->littimer--;
if (c->littimer == 0) {
c->lit = c->origlit;
}
}
2011-02-01 06:16:13 +11:00
}
}
} // end for (y...
// now handle effects on lifeforms and/or their objects
for (l = map->lf ; l ; l = l->next) {
timeeffectslf(l);
}
//dblog("AFTER SORT AND ADJUST.....");
//dumplf();
} // end if timespent
// inc game time
curtime += firstlftime;
2010-12-02 12:17:54 +11:00
2011-02-01 06:16:13 +11:00
if (db) dblog("cur time is %ld\n",curtime);
2010-12-02 12:17:54 +11:00
}
* [+] backstab - [+] monsters start asleep and make spot checks ? - [+] make them start asleep - [+] then make this random - [+] sound will wake them (ie. "makenoise") - [+] when you move, make SC_STEALTH check. if you fail, you make noise! - [+] must pass LISTEN check OR have los to hear something. - [+] "the blowfly falls asleep" "the blowfly appears" when summoned. - [+] don't show 'falls asleep' while being created! * [+] don't start summoned mosnters asleep! * [+] clean up bresnham functions - [+] hearing - instead of just using distance, use distance modiied by # of walls! - [+] getcelldistsound() - each wall counts as an extra cell! - [+] add WALK/FLY noises to all monsters! - [+] don't show 'you hear xxx' when resting. - [+] extra damage for weapon skill (up to 50% extra) - [+] make broken glass crushable - [+] only interrupt rest for non-peaceful, non-friendly monsters - [+] save to fight off poison * [+] beholder is never using its BITE attack * [+] need a price for manuals!! * [+] change"dobresnham" to populate an array of cells - [+] make ai cast animate metal (if they ahve a second weapon) - [+] implement getallegiance() to clean up isfriendly / ispeaceful etc - [+] bug - f_else f_ifpct etc not working in startobs * [+] OT_S_CHARM - [+] update askcoords to show "weilding x AND Y" - [+] stop enemies from throwing firearm ammo somehow * [+] implement - [+] pacify spell - [+] make spellbooks less common - [+] detectmetal not wokring. fixed. - [+] detectobjects spell - [+] cleanup using flagcausesredraw() - [+] increase odds of weapons in rooms, and max ob count in rooms
2011-03-24 16:09:31 +11:00
void usage(char *progname) {
printf("usage: %s [ -f playerfile ]\n",progname);
printf("\t-f xx\tReads player details from file xx.\n");
}