From c181893ae43c4125727bb41a776430945f98eed3 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Wed, 31 Aug 2011 17:33:35 +0000 Subject: [PATCH] - [+] sleeping mosnters aren't waking up soon enough!!! make difficulty of listen check easier. - [+] they tend to only wake when i'm 1 sq away - [+] get rid of sprintf - [+] replace all with snprintf via macro - [+] then search for HUGEBUFLEN etc and fix up - [+] compile with -O2, fix up warnings. - [+] gaze attacks (ie eyebat, beholder) now need 2way los, and glasses will protect you - [+] use "wrapprint" to show physical props in @@ - [+] glowbugs should flash upon death - [+] should stop gaze attacks (like eyebat) - [+] golden cobra - acidspit at eyes - [+] bright flash (glowbug, and make some of them hostile) - [+] flashbangs (make them more common) - [+] combine tracking with searching and call it "Perception" - [+] replace all occurences of SK_xxx - [+] replace skillcheck (or make it use different skill) --- Makefile | 3 + ai.c | 71 +++++-- attack.c | 65 +++--- defs.h | 37 +++- flag.c | 9 +- flag.h | 19 +- god.c | 36 ++-- io.c | 614 ++++++++++++++++++++++++++---------------------------- io.h | 1 + lf.c | 523 ++++++++++++++++++++++++++++++---------------- lf.h | 6 +- map.c | 54 ++--- move.c | 30 +-- nexus.c | 47 ++--- objects.c | 280 ++++++++++++++----------- objects.h | 3 +- save.c | 38 ++-- spell.c | 260 +++++++++++++---------- spell.h | 2 +- text.c | 58 +++--- 20 files changed, 1224 insertions(+), 932 deletions(-) diff --git a/Makefile b/Makefile index cac5531..9faea26 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ nexus: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h gcc -Wall -g -pg -o nexus nexus.c ai.c attack.c flag.c god.c io.c lf.c map.c move.c objects.c text.c save.c spell.c vault.c vault.h -lncurses -lsqlite3 + +check: Makefile defs.h nexus.c nexus.h ai.c ai.h attack.c attack.h flag.c flag.h god.c god.h io.c io.h lf.c lf.h map.c map.h move.c move.h objects.c objects.h text.c text.h save.c save.h spell.c spell.h vault.c vault.h + splint -onlytrans -nullret -nullstate -branchstate -usedef -type -retvalint -retvalother +posixlib -unrecog -boolops -mustfreefresh -predboolint -unqualifiedtrans -compdef *.c diff --git a/ai.c b/ai.c index 9391ab6..3f668ad 100644 --- a/ai.c +++ b/ai.c @@ -110,12 +110,11 @@ int aiattack(lifeform_t *lf, lifeform_t *victim, int timelimit) { enum OBTYPE aigetattackspell(lifeform_t *lf, lifeform_t *victim) { flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; flag_t *f; enum OBTYPE poss[MAXPILEOBS]; - int nposs = 0; + int nposs = 0,i; int db = B_FALSE; - int castok = B_TRUE; if (lfhasflag(lf, F_DEBUG)) { db = B_TRUE; @@ -123,19 +122,33 @@ enum OBTYPE aigetattackspell(lifeform_t *lf, lifeform_t *victim) { f = lfhasflag(lf, F_NEEDOBFORSPELLS); if (f && !hasob(lf->pack, f->val[0])) { - castok = B_FALSE; + if (db) dblog(".oO { Cannot cast spell, I don't have my spellcast object }"); + return OT_NONE; + } + f = lfhasflag(lf, F_CASTTYPE); + if (f) { + switch (f->val[0]) { + case CT_GAZE: // gaze into victim's eyes: they must be able to see you and vice versa + if (!cansee(victim, lf) || !cansee(lf, victim)) { + if (db) dblog(".oO { Cannot cast spell, no 2way los for gaze attack or victims eyes covered }"); + return OT_NONE; + } + break; + case CT_EYESPIT: // spit into the victim's eyes. lof is checked in aispellok + if (!cansee(victim, lf) ) { + if (db) dblog(".oO { Cannot cast spell, no 2way los for gaze attack or victims eyes covered }"); + return OT_NONE; + } + break; + } } - if (castok) { - int i; - - getflags(lf->flags, retflag, &nretflags, F_CANCAST, F_CANWILL, F_NONE); - for (i = 0; i < nretflags; i++) { - f = retflag[i]; - if (aispellok(lf, f->val[0], victim, F_AICASTTOATTACK)) { - poss[nposs] = f->val[0]; - nposs++; - } + getflags(lf->flags, retflag, &nretflags, F_CANCAST, F_CANWILL, F_NONE); + for (i = 0; i < nretflags; i++) { + f = retflag[i]; + if (aispellok(lf, f->val[0], victim, F_AICASTTOATTACK)) { + poss[nposs] = f->val[0]; + nposs++; } } @@ -159,9 +172,9 @@ enum OBTYPE aigetfleespell(lifeform_t *lf) { enum OBTYPE poss[MAXPILEOBS]; int nposs = 0,i; int db = B_FALSE; - lifeform_t *fleefrom; + lifeform_t *fleefrom = NULL; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (lfhasflag(lf, F_DEBUG)) { db = B_TRUE; @@ -193,7 +206,7 @@ enum OBTYPE aigetfleespell(lifeform_t *lf) { // this function assumes that you can't just SEE the target! cell_t *aigetlastknownpos(lifeform_t *lf, lifeform_t *target, int *lastx, int *lasty, int *lastdir) { - flag_t *f, *tflag, *bestflag; + flag_t *f, *tflag, *bestflag = NULL; cell_t *c = NULL; int besttime = -1; int i; @@ -208,7 +221,7 @@ cell_t *aigetlastknownpos(lifeform_t *lf, lifeform_t *target, int *lastx, int *l } } } - if (c) { + if (bestflag && c) { if (lastx) *lastx = c->x; if (lasty) *lasty = c->y; if (lastdir) { @@ -456,9 +469,9 @@ flag_t *aigoto(lifeform_t *lf, cell_t *c, enum MOVEREASON why, void *data, int t killflagsofid(lf->flags, F_TARGETCELL); if (why == MR_LF) { - sprintf(whybuf, "%d", ((lifeform_t *)data)->id); + snprintf(whybuf, BUFLEN, "%d", ((lifeform_t *)data)->id); } else if (why == MR_OB) { - sprintf(whybuf, "%ld", ((object_t *)data)->id); + snprintf(whybuf, BUFLEN, "%ld", ((object_t *)data)->id); } else { strcpy(whybuf, ""); } @@ -923,7 +936,7 @@ void aiturn(lifeform_t *lf) { enum ATTRBRACKET iqb; int n,i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; /* @@ -1490,6 +1503,18 @@ int aispellok(lifeform_t *lf, enum OBTYPE spellid, lifeform_t *victim, enum FLAG needlof = f->val[1]; } } + // override needlos/lof based on cast type + f = lfhasflag(lf, F_CASTTYPE); + if (f) { + switch (f->val[0]) { + case CT_GAZE: + needlos = B_TRUE; + break; + case CT_EYESPIT: + needlof = LOF_NEED; + break; + } + } // enough mp etc? if (!cancast(lf, spellid, NULL)) { @@ -1535,7 +1560,7 @@ int aispellok(lifeform_t *lf, enum OBTYPE spellid, lifeform_t *victim, enum FLAG int range; switch (f->val[0]) { case ST_VICTIM: - range = getspellrange(spellid, getspellpower(lf, spellid)); + range = getspellrange(lf, spellid, getspellpower(lf, spellid)); if ((range == UNLIMITED) || (getcelldist(lf->cell, victim->cell) <= range)) { if (db) { dblog(".oO { spell possibility: %s }", ot ? ot->name : "?unkownspell?"); @@ -2045,7 +2070,7 @@ void makewantedoblist(lifeform_t *lf, int *noids, enum OBTYPE *oid, int *oidcove int i; flag_t *f; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; // construct a list of objects which we want *noids = 0; diff --git a/attack.c b/attack.c index 06668ff..bbb43c9 100644 --- a/attack.c +++ b/attack.c @@ -166,7 +166,7 @@ int attackcell(lifeform_t *lf, cell_t *c, int force) { flag_t *sf; int saysorry = B_FALSE; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; // anyone there? if so just attack. if (c->lf) { @@ -177,13 +177,13 @@ int attackcell(lifeform_t *lf, cell_t *c, int force) { getlfname(c->lf, victimname); switch (getallegiance(c->lf)) { case AL_PEACEFUL: - sprintf(buf, "Really attack the peaceful %s?",noprefix(victimname)); + snprintf(buf, BUFLEN, "Really attack the peaceful %s?",noprefix(victimname)); break; case AL_FRIENDLY: - sprintf(buf, "Really attack the allied %s?",noprefix(victimname)); + snprintf(buf, BUFLEN, "Really attack the allied %s?",noprefix(victimname)); break; default: - sprintf(buf, "Really attack the allied %s?",noprefix(victimname)); + snprintf(buf, BUFLEN, "Really attack the allied %s?",noprefix(victimname)); break; } ch = askchar(buf, "yn","n", B_TRUE); @@ -212,7 +212,7 @@ int attackcell(lifeform_t *lf, cell_t *c, int force) { char ch; real_getobname(o, obname, o->amt, B_FALSE, B_FALSE, B_TRUE, B_FALSE, B_FALSE); getobname(priwep, wepname, priwep->amt); - sprintf(buf, "Attacking %s might damage your %s. Proceed?", obname, noprefix(wepname)); + snprintf(buf, BUFLEN, "Attacking %s might damage your %s. Proceed?", obname, noprefix(wepname)); ch = askchar(buf, "yn","n", B_TRUE); if (ch == 'n') { // cancel. @@ -424,7 +424,7 @@ int attackcell(lifeform_t *lf, cell_t *c, int force) { sayphrase(lf, SP_SORRY, -1, NA, NULL); } - if (lfhasflagval(lf, F_INJURY, BP_HANDS, DT_SLASH, NA, NULL)) { + if (lfhasflagval(lf, F_INJURY, NA, BP_HANDS, DT_SLASH, NULL)) { bleed(lf); losehp(lf, 1, DT_DIRECT, NULL, "blood loss"); } @@ -456,7 +456,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) int isunarmed = B_FALSE; skill_t *wepsk = NULL; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; int aidb = B_FALSE; flag_t *f; enum BODYPART critpos = BP_NONE; @@ -537,10 +537,10 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) critpos = getrandomcorebp(victim); // replace victicname to include body part if ((lf == victim) && !isplayer(lf)) { - sprintf(victimbpname, "its %s", getbodypartname(critpos)); + snprintf(victimbpname, BUFLEN, "its %s", getbodypartname(critpos)); } else { getlfname(victim, buf); - sprintf(victimbpname, "%s%s %s", buf, getpossessive(buf), getbodypartname(critpos)); + snprintf(victimbpname, BUFLEN, "%s%s %s", buf, getpossessive(buf), getbodypartname(critpos)); } } else { strcpy(victimbpname, ""); @@ -801,7 +801,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) strcpy(extradambuf, ""); if (wep && !ismeleeweapon(wep)) { - sprintf(withwep, " with %s", wepname); + snprintf(withwep, BUFLEN, " with %s", wepname); } else { strcpy(withwep, ""); } @@ -813,7 +813,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) strcpy(extradambuf, " ineffectually"); } } else if (lfhasflag(player, F_EXTRAINFO) || lfhasflag(player, F_OMNIPOTENT) ) { - sprintf(extradambuf, " [%d dmg]",dam[i]); + snprintf(extradambuf, BUFLEN, " [%d dmg]",dam[i]); } if (backstab && (i == 0)) { @@ -846,7 +846,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) if (needfree) { free(verb); } - } else { + } else { // ie. the attacker is a monster if (cansee(player, lf) || isplayer(victim)) { char withwep[BUFLEN]; char attackverb[BUFLEN]; @@ -858,7 +858,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) capitalise(buf); if (wep && !isunarmed && (lf->race->id != R_DANCINGWEAPON) && cansee(player, lf)) { - sprintf(withwep, " with %s", wepname); + snprintf(withwep, BUFLEN, " with %s", wepname); } else { strcpy(withwep, ""); } @@ -875,7 +875,9 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) needses(attackverb) ? "es" : "s", usecrittext ? victimbpname : victimname,withwep, nodamstr); } - noise(lf->cell, lf, NC_OTHER, 3, "sounds of fighting.", NULL); + if (!isplayer(victim)) { + noise(lf->cell, lf, NC_OTHER, 3, "sounds of fighting.", NULL); + } } } @@ -915,7 +917,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) if (wep && !isunarmed) { char wepname[BUFLEN]; getobname(wep, wepname, 1); - sprintf(buf, "%s^%s %s",attackername2, + snprintf(buf, BUFLEN, "%s^%s %s",attackername2, (lf == victim) ? "using" : "weilding", wepname); } else { @@ -991,7 +993,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) } if (nmatched >= f->val[2]) { char damstring[BUFLEN]; - sprintf(damstring, "%s pack", lfname); + snprintf(damstring, BUFLEN, "%s pack", lfname); losehp(victim, f->val[0], f->val[1], lf, damstring); if (isplayer(victim) || cansee(player, victim)) { msg("%c%s pack attacks %s!", isplayer(victim) ? 'b' : 'c', lfname, victimname); @@ -1050,7 +1052,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) getattackverb(victim, NULL, f->val[2], rdam, lf->maxhp), attackername); } - sprintf(damstring, "%s%s %s", victimname, getpossessive(victimname), noprefix(f->text)); + snprintf(damstring, BUFLEN, "%s%s %s", victimname, getpossessive(victimname), noprefix(f->text)); losehp(lf, rdam, f->val[2], victim, damstring); } } @@ -1068,7 +1070,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) } } else if (lfhasflag(victim, F_MAGSHIELD) && ismetal(wep->material->id)) { if (isplayer(lf) || cansee(player, lf)) { - sprintf(buf, "%s",attackername); + snprintf(buf, BUFLEN, "%s",attackername); msg("^w%s%s magnetic shield repels %s%s attack.", victimname, getpossessive(victimname), buf, getpossessive(buf)); @@ -1079,7 +1081,7 @@ int attacklf(lifeform_t *lf, lifeform_t *victim, object_t *wep, flag_t *damflag) } else { if (cansee(player, lf)) { // capitalise first letter - sprintf(buf, "%s",attackername); + snprintf(buf, BUFLEN, "%s",attackername); msg("%s misses %s.", buf, victimname); } @@ -1247,7 +1249,7 @@ int attackob(lifeform_t *lf, object_t *o, object_t *wep, flag_t *damflag) { if (isplayer(lf)) { char extradambuf[BUFLEN]; if (lfhasflag(player, F_EXTRAINFO) || lfhasflag(player, F_OMNIPOTENT) ) { - sprintf(extradambuf, " [%d dmg]",dam[i]); + snprintf(extradambuf, BUFLEN, " [%d dmg]",dam[i]); } else { strcpy(extradambuf, ""); } @@ -1257,7 +1259,7 @@ int attackob(lifeform_t *lf, object_t *o, object_t *wep, flag_t *damflag) { char withwep[BUFLEN]; if (wep && !isunarmed && !isblind(player)) { // announce weapon used - sprintf(withwep, " with %s", wepname); + snprintf(withwep, BUFLEN, " with %s", wepname); } else { strcpy(withwep, ""); } @@ -1276,7 +1278,7 @@ int attackob(lifeform_t *lf, object_t *o, object_t *wep, flag_t *damflag) { // ok } else { char buf[BUFLEN]; - sprintf(buf, "punching %s", obname); + snprintf(buf, BUFLEN, "punching %s", obname); if ( losehp(lf, 1, DT_BASH, lf, buf)) { if (isplayer(lf)) { msg("^bOw!"); @@ -1326,7 +1328,6 @@ void criticalhit(lifeform_t *lf, lifeform_t *victim, enum BODYPART hitpos, enum object_t *o; // replace some dam types if (damtype == DT_UNARMED) damtype = DT_BASH; - if (damtype == DT_BITE) damtype = DT_SLASH; if (damtype == DT_PIERCE) damtype = DT_SLASH; if (damtype == DT_CHOP) damtype = DT_SLASH; @@ -1459,7 +1460,7 @@ char *getattackverb(lifeform_t *lf, object_t *wep, enum DAMTYPE damtype, int dam float pct; enum LFSIZE ownersize = SZ_HUMAN; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (lf) { ownersize = getlfsize(lf); @@ -1649,7 +1650,7 @@ int getextradamlf(lifeform_t *lf, int *dam, enum DAMTYPE *damtype, int *ndam) { flag_t *f; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; // special case - EXTRADAM goes onto INITIAL dam[] if the same type, rather than // adding a new one. getflags(lf->flags, retflag, &nretflags, F_EXTRADAM, F_NONE); @@ -1697,7 +1698,7 @@ int getextradamwep(object_t *wep, int *dam, enum DAMTYPE *damtype, int *ndam) { flag_t *f; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; getflags(wep->flags, retflag, &nretflags, F_FROZEN, F_ONFIRE, F_NONE); for (i = 0; i < nretflags; i++) { f = retflag[i]; @@ -1734,7 +1735,7 @@ char *getkillverb(lifeform_t *victim, object_t *wep, enum DAMTYPE damtype, int d flag_t *f; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; getflags(wep->flags, retflag, &nretflags, F_KILLVERB, F_NONE); for (i = 0; i < nretflags; i++) { f = retflag[i]; @@ -1863,7 +1864,7 @@ int getdamroll(object_t *o, lifeform_t *victim, flag_t *damflag) { } if (victim) { - if (lfhasflagval(victim, F_INJURY, BP_BODY, DT_SLASH, NA, NULL)) { + if (lfhasflagval(victim, F_INJURY, NA, BP_BODY, DT_SLASH, NULL)) { // extra damage dam += rnd(1,2); } @@ -2130,7 +2131,7 @@ void wepeffects(flagpile_t *fp, cell_t *where, flag_t *damflag, int dam) { object_t *wep; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (!where) return; @@ -2195,7 +2196,7 @@ void wepeffects(flagpile_t *fp, cell_t *where, flag_t *damflag, int dam) { f->known = B_TRUE; } - sprintf(damstring, "%s%s blast of revenge",buf2, getpossessive(buf2)); + snprintf(damstring, BUFLEN, "%s%s blast of revenge",buf2, getpossessive(buf2)); losehp(victim, extradam, DT_DIRECT, owner, damstring); } } // end if dampct > 50 @@ -2297,12 +2298,12 @@ void wepeffects(flagpile_t *fp, cell_t *where, flag_t *damflag, int dam) { getlfnamea(owner, lfname); getobname(wep, wepname, 1); // ie. "a goblin's poisoned short sword" - sprintf(frombuf, "%s%s %s",lfname,getpossessive(lfname), wepname); + snprintf(frombuf, BUFLEN, "%s%s %s",lfname,getpossessive(lfname), wepname); } else { char wepname[BUFLEN]; getobname(wep, wepname, 1); // ie "a poisoned short sword" - sprintf(frombuf, "%s", wepname); + snprintf(frombuf, BUFLEN, "%s", wepname); } } else { strcpy(frombuf, "something unknown"); diff --git a/defs.h b/defs.h index 644b5d4..60ee75f 100644 --- a/defs.h +++ b/defs.h @@ -48,6 +48,7 @@ #define B_MAYCHASE (-1) #define B_NODOORS (0) #define B_DONTKILL (-1) +#define B_APPENDYOU (-1) //#define B_TEMP (-1) //#define B_PERM (-2) @@ -253,6 +254,7 @@ #define PCT (65432) // must be POSITIVE #define RANDOM (-2610) #define AUTO (-7654) +#define HEAVYWEPKG (5) // Time periods #define TM_DRUNKTIME (10) // how long it takes for alcohol to wear off @@ -320,6 +322,11 @@ enum COLOUR { }; #define BLUEBG 50 +enum CASTTYPE { + CT_NORMAL = 0, + CT_GAZE, + CT_EYESPIT +}; enum NOISECLASS { NC_NONE = 0, @@ -793,7 +800,8 @@ enum RACE { R_RAT, R_SNAKE, R_SNAKECARPET, - R_SNAKECOBRA, + R_SNAKECOBRABLACK, + R_SNAKECOBRAGOLDEN, R_SNAKECONSTRICTOR, R_SNAKETREE, R_SNAKEWATER, @@ -1595,6 +1603,7 @@ enum FLAG { F_NEWWATERDEPTH, // temp flag for the spread of f_deepwater obs. // v0+1 are x/y, v2 is new depth. // object flags + F_BEINGUSED, // this object is currently being used F_DEAD, // object will be removed F_ONEPERCELL, // only one of these objects can exist per cell F_CREATEDBY, // object was made by lf id v0, text=real lfname @@ -2096,6 +2105,8 @@ enum FLAG { F_SPELLCASTTEXT, // text is announcement for spellcast // if text is empty, then don't announce // this lf's spell casting at all. + // if v2 is 'appendyou' " at xxx" will + // be appended. F_NODEATHANNOUNCE, // don't say 'the xx dies' if this lf dies F_BEHEADED, // use special corpse drop code F_MOVESPEED, // override default move speed @@ -2168,6 +2179,9 @@ enum FLAG { F_BLIND, // cannot see anything F_DEAF, // cannot hear F_NEEDOBFORSPELLS, // lf can only cast spells if it has object v0 + F_CASTTYPE, // lf uses enum CASTTYPE v0 for spells + // optional v1 is colour for casttype-based animations + // (ie. spit spells) F_CAFFEINATED, // can't sleep. F_CANCAST, // can cast the spell val0 (need MP) F_CANHEARLF, // you can hear lifeform id v0 (show their glyph) @@ -2184,6 +2198,7 @@ enum FLAG { // dam:xdy+b; damage // needgrab:xx; do you need to grab first? // range:xx; + // gaze (this is a gaze spell) F_CHARMEDBY,// you've been charmed by lf id v0 F_CONTROL,// you control polymorphs, teleports and createmonsters F_DETECTAURAS, // autodetect bless/curse @@ -2222,7 +2237,8 @@ enum FLAG { F_HIDING, // lifeform is hiding. v0 is modifier to stealth checks. F_ICESLIDE, // lf has "slide" spell active. // v0 = timeleft (since 'lifetime' is used for FROMSPELL) - F_INJURY, // v0 = where, v1 = damtype + F_INJURY, // v0 = enum injury, v1 = where (enum bp), v2 = damtype + // text is desc, ie "rib is cracked" F_INVISIBLE, // lifeform is invisible F_INVULNERABLE,// immune to most damage // this can apply to objects too! @@ -2384,6 +2400,22 @@ enum HUNGER { H_STARVED = 5 }; +// injuries +enum INJURY { + IJ_NONE, + IJ_BLACKEYE, + IJ_CHESTBLEED, + IJ_FINGERBROKEN, + IJ_HANDBLEED, + IJ_LEGBLEED, + IJ_LEGBROKEN, + IJ_LEGBRUISE, + IJ_RIBCRACKED, + IJ_SHOULDERDISLOCATED, + IJ_TENDONCUT, +}; + + #define PIETYPRAYLOSS 75 #define PIETY_MIN -200 @@ -2483,6 +2515,7 @@ enum ERROR { E_PENTAGRAM, E_SWIMMING, E_DANGEROUS, + E_INJURED, }; diff --git a/flag.c b/flag.c index 6cf08f9..0098882 100644 --- a/flag.c +++ b/flag.c @@ -216,7 +216,7 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, ob = findobbyid(f->pile->owner->pack, f->obfrom); if (ob) { - flag_t *f2; + flag_t *f2 = NULL; switch (f->lifetime) { case FROMOBEQUIP: f2 = hasflagval(ob->flags, F_EQUIPCONFER, f->id, NA, NA, NULL); @@ -352,6 +352,8 @@ int countflags(flagpile_t *fp) { int flagcausesloscalc(enum FLAG fid) { switch (fid) { + case F_ASLEEP: + case F_BLIND: case F_BLOCKSVIEW: case F_PRONE: return B_TRUE; @@ -444,12 +446,13 @@ flag_t *hasflagknown(flagpile_t *fp, int id) { flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception) { flag_t *f,*foundflag = NULL, *searchfrom = NULL; lifeform_t *owner; - owner = fp->owner; int pos; int l,r; int iter = 0,subiter = 0; int db = B_FALSE; + owner = fp->owner; + if (flagdb) db = B_TRUE; if (db) dblog("hasflag %d in flagpile with %d entries", id, fp->nitems); @@ -558,11 +561,11 @@ int getcounter(flagpile_t *fp) { flag_t *hasflagval_real(flagpile_t *fp, int id, int val1, int val2, int val3, char *text, int wantknown) { flag_t *f,*foundflag = NULL, *searchfrom = NULL; lifeform_t *owner; - owner = fp->owner; int pos; int l,r; int iter = 0; int db = B_FALSE; + owner = fp->owner; if (flagdb) db = B_TRUE; diff --git a/flag.h b/flag.h index 0735413..68bbdc0 100644 --- a/flag.h +++ b/flag.h @@ -2,11 +2,11 @@ // functions -altflagval_t *addaltval(flag_t *f, enum FLAG id, int val1, int val2, int val3, char *text); +altflagval_t *addaltval(flag_t *f, enum FLAG id, int val1, int val2, int val3, /*@null@*/ char *text); void addcondition(flag_t *f, enum FLAGCONDITION fc, int chance); -flag_t *addflag(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, char *text); -flag_t *addtempflag(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, char *text, int timeleft); -flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, char *text, int lifetime, int known, long obfromid); +flag_t *addflag(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, /*@null@*/ char *text); +flag_t *addtempflag(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, /*@null@*/ char *text, int timeleft); +flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, /*@null@*/ char *text, int lifetime, int known, long obfromid); flagpile_t *addflagpile(lifeform_t *owner, object_t *o); void changeflagtext(flag_t *f, char *newtext); void copyflag(flagpile_t *dst, flagpile_t *src, enum FLAG id); @@ -18,22 +18,21 @@ int flagcausesstatredraw(lifeform_t *lf, enum FLAG fid); int flagstacks(enum FLAG fid); cell_t *getflagpilelocation(flagpile_t *fp); int getflags(flagpile_t *fp, flag_t **retflag, int *nretflags, ... ); -int modcounter(flagpile_t *fp, int amt); flag_t *hasflag(flagpile_t *fp, int id); flag_t *hasflagknown(flagpile_t *fp, int id); flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception); -flag_t *hasflagval(flagpile_t *fp, int id, int val1, int val2, int val3, char *text); -flag_t *hasflagvalknown(flagpile_t *fp, int id, int val1, int val2, int val3, char *text); -flag_t *hasflagval_real(flagpile_t *fp, int id, int val1, int val2, int val3, char *text, int wantknown); +flag_t *hasflagval(flagpile_t *fp, int id, int val1, int val2, int val3, /*@null@*/ char *text); +flag_t *hasflagvalknown(flagpile_t *fp, int id, int val1, int val2, int val3, /*@null@*/ char *text); +flag_t *hasflagval_real(flagpile_t *fp, int id, int val1, int val2, int val3, /*@null@*/ char *text, int wantknown); int istransitoryflag(flag_t *f); int killflagsofid(flagpile_t *fp, enum FLAG fid); void killflag(flag_t *f); void killflagpile(flagpile_t *fp); int killtransitoryflags(flagpile_t *fp, enum FLAG fid); -int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, char *text); +int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, /*@null@*/ char *text); void makeflagknown(flagpile_t *fp); int modcounter(flagpile_t *fp, int amt); -flag_t *modflag(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, char *text); +flag_t *modflag(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, /*@null@*/ char *text); void sumflags(flagpile_t *fp, int id, int *val0, int *val1, int *val2); void timeeffectsflag(flag_t *f, int howlong); void timeeffectsflags(flagpile_t *fp); diff --git a/god.c b/god.c index 1b63807..d3d9a64 100644 --- a/god.c +++ b/god.c @@ -382,13 +382,13 @@ int godgiftmaybe(enum RACE rid) { rollagain = B_FALSE; switch (rnd(1,6)) { case 1: - sprintf(obtogive, "2-4 blessed potions of water"); + snprintf(obtogive, BUFLEN, "2-4 blessed potions of water"); break; case 2: - sprintf(obtogive, "blessed great weapon"); + snprintf(obtogive, BUFLEN, "blessed great weapon"); break; case 3: - sprintf(obtogive, "wand of turn undead"); + snprintf(obtogive, BUFLEN, "wand of turn undead"); break; case 4: // bless your weapon wep = getweapon(player); @@ -435,10 +435,10 @@ int godgiftmaybe(enum RACE rid) { rollagain = B_FALSE; switch (rnd(1,5)) { case 1: - sprintf(obtogive, "3-5 cursed potions of water"); + snprintf(obtogive, BUFLEN, "3-5 cursed potions of water"); break; case 2: - sprintf(obtogive, "cursed branded weapon"); + snprintf(obtogive, BUFLEN, "cursed branded weapon"); break; case 3: // poison your weapon wep = getweapon(player); @@ -475,32 +475,32 @@ int godgiftmaybe(enum RACE rid) { switch (rnd(1,7)) { case 1: if (getskill(player, SK_TECHUSAGE) >= gettechlevel(OT_LOCKHACKER)) { - sprintf(obtogive, "lock hacker"); + snprintf(obtogive, BUFLEN, "lock hacker"); } else { - sprintf(obtogive, "3-6 blessed lockpicks"); + snprintf(obtogive, BUFLEN, "3-6 blessed lockpicks"); } break; case 2: if (onein(6)) { - sprintf(obtogive, "large bag of holding"); + snprintf(obtogive, BUFLEN, "large bag of holding"); } else { - sprintf(obtogive, "bag of holding"); + snprintf(obtogive, BUFLEN, "bag of holding"); } break; case 3: - sprintf(obtogive, "safebox"); + snprintf(obtogive, BUFLEN, "safebox"); break; case 4: - sprintf(obtogive, "wand of opening"); + snprintf(obtogive, BUFLEN, "wand of opening"); break; case 5: - sprintf(obtogive, "wand of invisibility"); + snprintf(obtogive, BUFLEN, "wand of invisibility"); break; case 6: - sprintf(obtogive, "3-6 potions of invisibility"); + snprintf(obtogive, BUFLEN, "3-6 potions of invisibility"); break; case 7: - sprintf(obtogive, "leather boots of stealth"); + snprintf(obtogive, BUFLEN, "leather boots of stealth"); break; } } @@ -511,13 +511,13 @@ int godgiftmaybe(enum RACE rid) { rollagain = B_FALSE; switch (rnd(1,4)) { case 1: - sprintf(obtogive, "3 vials of ambrosia"); + snprintf(obtogive, BUFLEN, "3 vials of ambrosia"); break; case 2: - sprintf(obtogive, "ring of regeneration"); + snprintf(obtogive, BUFLEN, "ring of regeneration"); break; case 3: - sprintf(obtogive, "ring of miracles"); + snprintf(obtogive, BUFLEN, "ring of miracles"); break; case 4: // immune to disease / poison if (lfhasflag(player, F_DISEASEIMMUNE)) { @@ -575,7 +575,7 @@ void godsay(enum RACE rid, char *format, ...) { va_list args; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); god = findgod(rid); diff --git a/io.c b/io.c index 8228101..56702a8 100644 --- a/io.c +++ b/io.c @@ -471,7 +471,7 @@ char askchar(char *prompt, char *validchars, char *def, int showchars) { more(); wclear(msgwin); if (showchars) { - sprintf(buf, "%s (",prompt); + snprintf(buf, BUFLEN, "%s (",prompt); for (p = validchars ; *p ; ) { temp[0] = *p; temp[1] = '\0'; @@ -483,7 +483,7 @@ char askchar(char *prompt, char *validchars, char *def, int showchars) { } strcat(buf, ")"); } else { - sprintf(buf, "%s",prompt); + snprintf(buf, BUFLEN, "%s",prompt); } if (def) { strcat(buf, " ["); @@ -525,9 +525,10 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src int ntargets = 0,curtarget = -1; int x,y; enum ATTRBRACKET iqb; - iqb = getattrbracket(getattr(player, A_IQ), A_IQ, NULL); - flag_t *retflag[MAXCANDIDATES]; int nretflags; + flag_t *retflag[MAXCANDIDATES]; + + iqb = getattrbracket(getattr(player, A_IQ), A_IQ, NULL); // remember previously targetted lifeforms if (startlf > 0) { @@ -647,7 +648,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src // level /* if (lfhasflag(player, F_EXTRAINFO) || lfhasflag(player, F_OMNIPOTENT)) { - sprintf(extrainfo, "level %d, ",c->lf->level); + snprintf(extrainfo, BUFLEN, "level %d, ",c->lf->level); } */ switch (getallegiance(c->lf)) { @@ -721,7 +722,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src char buf2[BUFLEN]; getlfname(alf, alfname); if (strlen(extrainfo)) strcat(extrainfo, ", "); - sprintf(buf2, "attached to %s",alfname); + snprintf(buf2, BUFLEN, "attached to %s",alfname); strcat(extrainfo, buf2); } } @@ -732,21 +733,21 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src float rating; rating = comparelfs(player, c->lf); if (rating >= 4) { - sprintf(dangerbuf, "trivial"); + snprintf(dangerbuf, BUFLEN, "trivial"); } else if (rating >= 3) { - sprintf(dangerbuf, "very easy"); + snprintf(dangerbuf, BUFLEN, "very easy"); } else if (rating >= 2) { - sprintf(dangerbuf, "easy"); + snprintf(dangerbuf, BUFLEN, "easy"); } else if (rating >= 1) { - sprintf(dangerbuf, "average"); + snprintf(dangerbuf, BUFLEN, "average"); } else if (rating >= 0.5) { - sprintf(dangerbuf, "challenging"); + snprintf(dangerbuf, BUFLEN, "challenging"); } else if (rating >= 0.25) { - sprintf(dangerbuf, "formidable"); + snprintf(dangerbuf, BUFLEN, "formidable"); } else if (rating >= 0.125) { - sprintf(dangerbuf, "dangerous"); + snprintf(dangerbuf, BUFLEN, "dangerous"); } else { - sprintf(dangerbuf, "very dangerous"); + snprintf(dangerbuf, BUFLEN, "very dangerous"); } if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, dangerbuf); @@ -759,7 +760,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src if (strlen(extrainfo)) strcat(extrainfo, ", "); getobname(o, obname, o->amt); - sprintf(buf2, "stuck in %s", obname); + snprintf(buf2, BUFLEN, "stuck in %s", obname); strcat(extrainfo, buf2); } // hp @@ -768,13 +769,13 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src ) { char buf2[BUFLEN]; // show actual hp - sprintf(buf2, "hp %d/%d",c->lf->hp, c->lf->maxhp); + snprintf(buf2, BUFLEN, "hp %d/%d",c->lf->hp, c->lf->maxhp); if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, buf2); } else { char buf2[BUFLEN]; // show condition name - sprintf(buf2, "%s",getseenlfconditionname(c->lf, player)); + snprintf(buf2, BUFLEN, "%s",getseenlfconditionname(c->lf, player)); if (strlen(buf2)) { if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, buf2); @@ -804,7 +805,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src char obname[BUFLEN]; char buf2[BUFLEN]; getobname(wep, obname, wep->amt); - sprintf(buf2, "weilding %s",obname); + snprintf(buf2, BUFLEN, "weilding %s",obname); if (strlen(extrainfo)) strcat(extrainfo, ", "); secwep = getequippedob(c->lf->pack, BP_SECWEAPON); @@ -820,7 +821,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src char obname[BUFLEN]; char buf2[BUFLEN]; getobname(wep, obname, wep->amt); - sprintf(buf2, "weilding %s",obname); + snprintf(buf2, BUFLEN, "weilding %s",obname); if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, buf2); } @@ -834,7 +835,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src char lfname2[BUFLEN]; char buf2[BUFLEN]; getlfname(lf2, lfname2); - sprintf(buf2, "holding %s",lfname2); + snprintf(buf2, BUFLEN, "holding %s",lfname2); if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, buf2); } @@ -848,7 +849,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src char lfname2[BUFLEN]; char buf2[BUFLEN]; getlfname(lf2, lfname2); - sprintf(buf2, "held by %s",lfname2); + snprintf(buf2, BUFLEN, "held by %s",lfname2); if (strlen(extrainfo)) strcat(extrainfo, ", "); strcat(extrainfo, buf2); } @@ -857,7 +858,7 @@ cell_t *askcoords(char *prompt, char *subprompt, int targettype, lifeform_t *src // show iextra info if lf isn't feigning death if (strlen(extrainfo) && !lfhasflag(c->lf, F_FEIGNINGDEATH)) { char buf2[BUFLEN]; - sprintf(buf2, " [%s]",extrainfo); + snprintf(buf2, BUFLEN, " [%s]",extrainfo); strcat(buf, buf2); } } else { @@ -1006,7 +1007,7 @@ char *askstring(char *prompt, char punc, char *retbuf, int retbuflen, char *def) more(); wclear(msgwin); - sprintf(buf, "%s",prompt); + snprintf(buf, BUFLEN, "%s",prompt); if (def) { strcat(buf, " ["); strcat(buf, def); @@ -1062,8 +1063,8 @@ int announceflaggain(lifeform_t *lf, flag_t *f) { lifeform_t *lf2; char lfname[BUFLEN]; char buf[BUFLEN]; - char buf3[BUFLEN]; char *buf2; + char *p; if (isdead(player)) { return B_FALSE; @@ -1211,11 +1212,11 @@ int announceflaggain(lifeform_t *lf, flag_t *f) { ot = findot(f->val[0]); if (ot && (!hasflag(ot->flags, F_NOANNOUNCE))) { char buf[BUFLEN]; - sprintf(buf, "^gYou have learned the ability '%s'.", ot->name); + snprintf(buf, BUFLEN, "^gYou have learned the ability '%s'.", ot->name); /* if (f->val[2] != NA) { char turnbuf[BUFLEN]; - sprintf(turnbuf, " (every %d turn%s)",f->val[2], (f->val[2] == 1) ? "" : "s"); + snprintf(turnbuf, BUFLEN, " (every %d turn%s)",f->val[2], (f->val[2] == 1) ? "" : "s"); strcat(buf, turnbuf); } strcat(buf, "."); @@ -1308,17 +1309,9 @@ int announceflaggain(lifeform_t *lf, flag_t *f) { donesomething = B_TRUE; break; case F_INJURY: - strcpy(buf, getinjuredbpname(f->val[0])); - strcpy(buf3, getinjuryname(f->val[1])); - if (isplayer(lf)) { - msg("^%cYour %s %s %s!", getlfcol(lf, CC_VBAD), buf, - (f->val[1] == DT_SLASH) ? "starts" : "is", buf3); - } else { - msg("^%c%s%s %s %s %s!", getlfcol(lf, CC_VBAD), - lfname, getpossessive(lfname), buf, - (f->val[1] == DT_SLASH) ? "starts" : "is", - buf3); - } + p = readuntil(buf, f->text, '^'); + msg("^%c%s%s %s!", getlfcol(lf, CC_VBAD), lfname, getpossessive(lfname), buf); + donesomething = B_TRUE; break; case F_INVISIBLE: if (isplayer(lf)) { @@ -1645,7 +1638,7 @@ int announceflaggain(lifeform_t *lf, flag_t *f) { int announceflagloss(lifeform_t *lf, flag_t *f) { char lfname[BUFLEN]; - char buf[BUFLEN], buf3[BUFLEN]; + char buf[BUFLEN]; lifeform_t *lf2; int donesomething = B_FALSE; @@ -1892,14 +1885,8 @@ int announceflagloss(lifeform_t *lf, flag_t *f) { donesomething = B_TRUE; break; case F_INJURY: - strcpy(buf, getinjuredbpname(f->val[0])); - strcpy(buf3, getinjuryname(f->val[1])); - if (isplayer(lf)) { - msg("^%cYour %s %s has healed.", getlfcol(lf, CC_VGOOD), buf3, buf); - } else { - msg("^%c%s%s %s %s has healed.", getlfcol(lf, CC_VGOOD), - lfname, getpossessive(lfname), buf3, buf); - } + strcpy(buf, getinjuredbpname(f->val[1])); + msg("^%c%s%s injured %s has healed.", getlfcol(lf, CC_VGOOD), lfname, getpossessive(lfname), buf); break; case F_INVISIBLE: if (isplayer(lf)) { @@ -2202,14 +2189,14 @@ int announceobflaggain(object_t *o, flag_t *f) { if (o->pile->owner) { if (isplayer(o->pile->owner)) { - sprintf(prefix, "Your %s",noprefix(obname)); + snprintf(prefix, BUFLEN, "Your %s",noprefix(obname)); } else { char lfname[BUFLEN]; getlfname(o->pile->owner, lfname); - sprintf(prefix, "%s%s %s",lfname, getpossessive(lfname), noprefix(obname)); + snprintf(prefix, BUFLEN, "%s%s %s",lfname, getpossessive(lfname), noprefix(obname)); } } else { - sprintf(prefix, "%s",obname); + snprintf(prefix, BUFLEN, "%s",obname); } @@ -2246,14 +2233,14 @@ void announceobflagloss(object_t *o, flag_t *f) { if (o->pile->owner) { if (isplayer(o->pile->owner)) { - sprintf(prefix, "Your %s",noprefix(obname)); + snprintf(prefix, BUFLEN, "Your %s",noprefix(obname)); } else { char lfname[BUFLEN]; getlfname(o->pile->owner, lfname); - sprintf(prefix, "%s%s %s",lfname, getpossessive(lfname), noprefix(obname)); + snprintf(prefix, BUFLEN, "%s%s %s",lfname, getpossessive(lfname), noprefix(obname)); } } else { - sprintf(prefix, "%s",obname); + snprintf(prefix, BUFLEN, "%s",obname); } if (o->amt == 1) { @@ -2346,16 +2333,16 @@ void listobs(WINDOW *win, object_t **mylist, int *sellist, int *selcount, int fi } if (forpickup && hasflag(mylist[i]->flags, F_NOPICKUP)) { - sprintf(buf, "%c %s", selchar, obname); + snprintf(buf, BUFLEN, "%c %s", selchar, obname); } else { - sprintf(buf, "%c %c - %s", selchar, useobletters ? mylist[i]->letter : myletters[i], + snprintf(buf, BUFLEN, "%c %c - %s", selchar, useobletters ? mylist[i]->letter : myletters[i], obname); } if (showpoints && (mylist[i]->type->id != OT_GOLD)) { long points; points = getobpoints(mylist[i]); - sprintf(pointsbuf, " [%ld points]", points); + snprintf(pointsbuf, BUFLEN, " [%ld points]", points); } else { strcpy(pointsbuf, ""); } @@ -2840,7 +2827,7 @@ void centre(WINDOW *win, enum COLOUR col, int y, char *format, ... ) { int colcount = 0; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); for (p = buf ; *p ; p++) { @@ -3009,10 +2996,10 @@ void describegod(lifeform_t *god) { f = hasflag(god->flags, F_GODOF); real_getlfname(god, godname, B_FALSE); - sprintf(goddesc, "(%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); + snprintf(goddesc, BUFLEN, "(%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); // title - sprintf(buf, "God::%s %s",godname, goddesc); + snprintf(buf, BUFLEN, "God::%s %s",godname, goddesc); wattron(mainwin, A_BOLD); mvwprintw(mainwin, 0, 0, buf); wattroff(mainwin, A_BOLD); @@ -3092,11 +3079,11 @@ void describeob(object_t *o) { y = 4; if (o->material->id != MT_NOTHING) { if (o->material->id == MT_FOOD) { - sprintf(buf, "%s %s food product%s, ",(o->amt == 1) ? "It is a" : "They are", + snprintf(buf, BUFLEN, "%s %s food product%s, ",(o->amt == 1) ? "It is a" : "They are", getsizetext(getobsize(o)), (o->amt == 1) ? "" : "s"); } else { - sprintf(buf, "%s %s sized, made from %s, ",(o->amt == 1) ? "It is" : "They are", + snprintf(buf, BUFLEN, "%s %s sized, made from %s, ",(o->amt == 1) ? "It is" : "They are", getsizetext(getobsize(o)), o->material->name); } @@ -3104,14 +3091,14 @@ void describeob(object_t *o) { if (o->amt == 1) { char wbuf[BUFLEN]; getweighttext(getobweight(o), wbuf); - sprintf(buf2, "and weighs %s.",wbuf); + snprintf(buf2, BUFLEN, "and weighs %s.",wbuf); strcat(buf, buf2); } else { char wbuf[BUFLEN]; char wbuf2[BUFLEN]; getweighttext(getobweight(o), wbuf); getweighttext(getobunitweight(o), wbuf2); - sprintf(buf2, "and weigh %s (%s each).",wbuf, wbuf2); + snprintf(buf2, BUFLEN, "and weigh %s (%s each).",wbuf, wbuf2); strcat(buf, buf2); } mvwprintw(mainwin, y, 0, "%s",buf); @@ -3187,11 +3174,11 @@ void describeob(object_t *o) { ot = findot(ff->val[0]); if (ot) { if (streq(buf, "")) { - sprintf(buf, " %s",ot->name); + snprintf(buf, BUFLEN, " %s",ot->name); } else { if (strlen(buf) >= 60) { mvwprintw(mainwin, y, 0, "%s",buf); y++; - sprintf(buf, " %s",ot->name); + snprintf(buf, BUFLEN, " %s",ot->name); } else { strcat(buf, ", "); strcat(buf, ot->name); @@ -3218,7 +3205,7 @@ void describeob(object_t *o) { flag_t *damflag; int delay; int critchance; - sprintf(buf, "It is a %s weapon", hasflag(o->flags, F_TWOHANDED) ? "two-handed" : "single handed"); + snprintf(buf, BUFLEN, "It is a %s weapon", hasflag(o->flags, F_TWOHANDED) ? "two-handed" : "single handed"); damflag = hasflag(o->flags, F_DAM); if (damflag) { int bonus = 0; @@ -3240,9 +3227,9 @@ void describeob(object_t *o) { if (maxdam < 0) maxdam = 0; if (mindam == maxdam) { - sprintf(buf2, " which inflicts %d %s damage",maxdam, getdamname(damtype)); + snprintf(buf2, BUFLEN, " which inflicts %d %s damage",maxdam, getdamname(damtype)); } else { - sprintf(buf2, " which inflicts %d-%d %s damage",mindam,maxdam, getdamname(damtype)); + snprintf(buf2, BUFLEN, " which inflicts %d-%d %s damage",mindam,maxdam, getdamname(damtype)); } strcat(buf, buf2); @@ -3313,21 +3300,21 @@ void describeob(object_t *o) { if (isarmour(o)) { f = hasflag(o->flags, F_GOESON); if (f) { - sprintf(buf, "It is worn %s your %s, ",getbodypartequipname(f->val[0]), getbodypartname(f->val[0])); + snprintf(buf, BUFLEN, "It is worn %s your %s, ",getbodypartequipname(f->val[0]), getbodypartname(f->val[0])); } else { strcpy(buf, ""); } f = hasflag(o->flags, F_ARMOURRATING); if (f) { if (strlen(buf)) { - sprintf(buf2, "and has an Armour Rating of %d.",f->val[0] + getobbonus(o)); + snprintf(buf2, BUFLEN, "and has an Armour Rating of %d.",f->val[0] + getobbonus(o)); strcat(buf, buf2); } else { - sprintf(buf, "It has an Armour Rating of %d.",f->val[0] + getobbonus(o)); + snprintf(buf, BUFLEN, "It has an Armour Rating of %d.",f->val[0] + getobbonus(o)); } } else { if (strlen(buf)) { - sprintf(buf2, "and provides no protection."); + snprintf(buf2, BUFLEN, "and provides no protection."); strcat(buf, buf2); } } @@ -3339,7 +3326,7 @@ void describeob(object_t *o) { int evmod; evmod = adjustarmourpenalty(player, f->val[0]); if (evmod != 0) { - sprintf(buf, " When worn, it %s your evasion chance by %d%%.", (evmod < 0) ? "reduces" : "increases", abs(evmod)); + snprintf(buf, BUFLEN, " When worn, it %s your evasion chance by %d%%.", (evmod < 0) ? "reduces" : "increases", abs(evmod)); mvwprintw(mainwin, y, 0, "%s",buf); y++; } @@ -3361,7 +3348,7 @@ void describeob(object_t *o) { // non armour, but still wearable. f = hasflag(o->flags, F_GOESON); if (f) { - sprintf(buf, "It is worn %s your %s. ",getbodypartequipname(f->val[0]), getbodypartname(f->val[0])); + snprintf(buf, BUFLEN, "It is worn %s your %s. ",getbodypartequipname(f->val[0]), getbodypartname(f->val[0])); mvwprintw(mainwin, y, 0, "%s",buf); y++; } @@ -3381,18 +3368,18 @@ void describeob(object_t *o) { } if (isdamaged(o)) { - sprintf(buf, "It has been damaged."); + snprintf(buf, BUFLEN, "It has been damaged."); } else { - sprintf(buf, "It is in perfect condition."); + snprintf(buf, BUFLEN, "It is in perfect condition."); } if (showfullhp) { int pct; pct = (int)(((float)f->val[0] / (float)f->val[1]) * 100.0); - sprintf(hpbuf, " [%d%%, %d/%d hp]", pct, f->val[0], f->val[1]); + snprintf(hpbuf, BUFLEN, " [%d%%, %d/%d hp]", pct, f->val[0], f->val[1]); } else if (isdamaged(o)) { int pct; pct = (int)(((float)f->val[0] / (float)f->val[1]) * 100.0); - sprintf(hpbuf, " [%d%% hp]", pct); + snprintf(hpbuf, BUFLEN, " [%d%% hp]", pct); } else { strcpy(hpbuf, ""); } @@ -3452,7 +3439,7 @@ void describeob(object_t *o) { strcpy(buf, ""); f = hasflagval(o->flags, F_DTIMMUNE, DT_ALL, NA, NA, NULL); if (f) { - sprintf(buf, "It is immune to %s", getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "It is immune to %s", getdamname(DT_ALL)); } else { int first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { @@ -3460,10 +3447,10 @@ void describeob(object_t *o) { if (f) { char buf2[BUFLEN]; if (first) { - sprintf(buf2, "It is immune to: %s", getdamname(i)); + snprintf(buf2, BUFLEN, "It is immune to: %s", getdamname(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamname(i)); + snprintf(buf2, BUFLEN, ", %s", getdamname(i)); } strcat(buf, buf2); } @@ -3479,7 +3466,7 @@ void describeob(object_t *o) { strcpy(buf, ""); f = hasflagval(o->flags, F_DTRESIST, DT_ALL, NA, NA, NULL); if (f) { - sprintf(buf, "It is resistant to %s", getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "It is resistant to %s", getdamname(DT_ALL)); } else { int first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { @@ -3487,10 +3474,10 @@ void describeob(object_t *o) { if (f) { char buf2[BUFLEN]; if (first) { - sprintf(buf2, "It is resistant to: %s", getdamname(i)); + snprintf(buf2, BUFLEN, "It is resistant to: %s", getdamname(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamname(i)); + snprintf(buf2, BUFLEN, ", %s", getdamname(i)); } strcat(buf, buf2); } @@ -3506,7 +3493,7 @@ void describeob(object_t *o) { strcpy(buf, ""); f = hasflagval(o->flags, F_DTVULN, DT_ALL, NA, NA, NULL); if (f) { - sprintf(buf, "It is vulnerable to %s", getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "It is vulnerable to %s", getdamname(DT_ALL)); } else { int first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { @@ -3514,10 +3501,10 @@ void describeob(object_t *o) { if (f) { char buf2[BUFLEN]; if (first) { - sprintf(buf2, "It is vulnerable to: %s", getdamname(i)); + snprintf(buf2, BUFLEN, "It is vulnerable to: %s", getdamname(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamname(i)); + snprintf(buf2, BUFLEN, ", %s", getdamname(i)); } strcat(buf, buf2); } @@ -3936,7 +3923,7 @@ void describeskill(enum SKILL skid) { if (!sk) return; // title - sprintf(buf, "Skill::%s",sk->name); + snprintf(buf, BUFLEN, "Skill::%s",sk->name); wattron(mainwin, A_BOLD); mvwprintw(mainwin, 0, 0, buf); wattroff(mainwin, A_BOLD); @@ -3949,9 +3936,9 @@ void describeskill(enum SKILL skid) { for (i = 0; i < sk->nskilldesc; i++) { if (sk->skilldesclev[i] == slev) { if (slev == PR_INEPT) { - sprintf(buf, "%s\n",sk->skilldesctext[i]); + snprintf(buf, BUFLEN, "%s\n",sk->skilldesctext[i]); } else { - sprintf(buf, "At %s level: %s\n",getskilllevelname(sk->skilldesclev[i]), sk->skilldesctext[i]); + snprintf(buf, BUFLEN, "At %s level: %s\n",getskilllevelname(sk->skilldesclev[i]), sk->skilldesctext[i]); } textwithcol(mainwin, buf); } @@ -3979,20 +3966,20 @@ void describespell(objecttype_t *ot) { power = -1; } - range = getspellrange(ot->id, power); + range = getspellrange(player, ot->id, power); // title - sprintf(buf, "%s",ot->name); + snprintf(buf, BUFLEN, "%s",ot->name); capitalise(buf); mvwprintw(mainwin, 0, 0, buf); wmove(mainwin, 2, 0); - sprintf(buf, "%s\n", ot->desc); + snprintf(buf, BUFLEN, "%s\n", ot->desc); textwithcol(mainwin, buf); getflags(ot->flags, retflag, &nretflags, F_EXTRADESC, F_NONE); for (i = 0; i < nretflags; i++) { f = retflag[i]; - sprintf(buf, "%s\n", f->text); + snprintf(buf, BUFLEN, "%s\n", f->text); textwithcol(mainwin, buf); } @@ -4084,7 +4071,7 @@ void doclose(void) { int failed = B_TRUE; // default is to fail int dir; int adjdoors; - int forcedir; + int forcedir = D_NONE; // how many doors are nearby? @@ -4129,7 +4116,7 @@ void doclose(void) { } void docomms(lifeform_t *lf) { - cell_t *where; + cell_t *where = NULL; int i; char buf[BUFLEN]; char lfname[BUFLEN]; @@ -4137,6 +4124,12 @@ void docomms(lifeform_t *lf) { int moneyowing = 0; enum ATTRBRACKET iqb; flag_t *f; + cell_t *c; + lifeform_t *lf2 = NULL; + char lfname2[BUFLEN]; + char buf2[BUFLEN]; + int count; + object_t *o, *givenob = NULL; if (!lf) { where = askcoords("Talk to who?", "Talk->", TT_MONSTER, player, UNLIMITED, LOF_DONTNEED, B_FALSE); @@ -4150,7 +4143,7 @@ void docomms(lifeform_t *lf) { } getlfname(lf, lfname); - sprintf(buf, "What will you say to %s?",lfname); + snprintf(buf, BUFLEN, "What will you say to %s?",lfname); initprompt(&prompt, buf); prompt.maycancel = B_TRUE; @@ -4200,7 +4193,7 @@ void docomms(lifeform_t *lf) { shopid = f->val[0]; moneyowing = getowing(player, shopid, NULL); if (moneyowing > 0) { - sprintf(buf, "(pay $%d to the shopkeeper)",moneyowing); + snprintf(buf, BUFLEN, "(pay $%d to the shopkeeper)",moneyowing); addchoice(&prompt, 'p', buf, NULL, NULL); } } @@ -4209,15 +4202,9 @@ void docomms(lifeform_t *lf) { ch = getchoice(&prompt); switch (ch) { - cell_t *c; - lifeform_t *lf2 = NULL; - char lfname2[BUFLEN]; - char buf2[BUFLEN]; - int count; - object_t *o, *givenob = NULL; case 'a': - sprintf(buf, "Tell %s to attack who?",lfname); - sprintf(buf2, "%s->Attack->",lfname); + snprintf(buf, BUFLEN, "Tell %s to attack who?",lfname); + snprintf(buf2, BUFLEN, "%s->Attack->",lfname); c = askcoords(buf, buf2, TT_MONSTER, lf, UNLIMITED, LOF_DONTNEED, B_FALSE); if (c && c->lf && cansee(lf, c->lf)) { lf2 = c->lf; @@ -4246,9 +4233,8 @@ void docomms(lifeform_t *lf) { } break; case 'd': // donate - // ask what to give - sprintf(buf, "What will you give to %s?",lfname); + snprintf(buf, BUFLEN, "What will you give to %s?",lfname); o = askobject(player->pack, buf, &count, AO_NONE); if (o) { if (o->type->id == OT_GOLD) { @@ -4356,8 +4342,8 @@ void docomms(lifeform_t *lf) { break; case 'g': - sprintf(buf, "Tell %s to go where?",lfname); - sprintf(buf2, "%s->Goto->",lfname); + snprintf(buf, BUFLEN, "Tell %s to go where?",lfname); + snprintf(buf2, BUFLEN, "%s->Goto->",lfname); c = askcoords(buf, buf2, TT_NONE, lf, UNLIMITED, LOF_DONTNEED, B_FALSE); if (c && cellwalkable(lf, c, NULL) ) { } else { @@ -4397,7 +4383,7 @@ void docomms(lifeform_t *lf) { if (!isknown(o) && (countmoney(player) >= DEF_SHOPIDENTPRICE)) { char buf2[BUFLEN]; char ch2; - sprintf(buf2, "Pay $%d to identify %s?",(int)DEF_SHOPIDENTPRICE, buf); + snprintf(buf2, BUFLEN, "Pay $%d to identify %s?",(int)DEF_SHOPIDENTPRICE, buf); ch2 = askchar(buf2, "yn","n", B_TRUE); if (ch2 == 'y') { if (givemoney(player, lf, DEF_SHOPIDENTPRICE)) { @@ -4435,13 +4421,13 @@ void docomms(lifeform_t *lf) { case 't': // ask whtehr to give/take initprompt(&prompt, "How will you trade?"); - sprintf(buf, "Give items to %s",lfname); + snprintf(buf, BUFLEN, "Give items to %s",lfname); addchoice(&prompt, 'i', buf, NULL, NULL); - sprintf(buf, "Take items from %s",lfname); + snprintf(buf, BUFLEN, "Take items from %s",lfname); addchoice(&prompt, 'o', buf, NULL, NULL); - sprintf(buf, "Both"); + snprintf(buf, BUFLEN, "Both"); addchoice(&prompt, 'b', buf, NULL, NULL); - sprintf(buf, "Neither"); + snprintf(buf, BUFLEN, "Neither"); addchoice(&prompt, 'n', buf, NULL, NULL); ch = getchoice(&prompt); switch (ch) { @@ -4498,9 +4484,9 @@ void dodrop(obpile_t *op, int wantmulti, obpile_t *dst) { } if (tolf) { - sprintf(buf, "Give what to %s",toname); + snprintf(buf, BUFLEN, "Give what to %s",toname); } else if (toob) { - sprintf(buf, "Put what in %s",toname); + snprintf(buf, BUFLEN, "Put what in %s",toname); } else { strcpy(buf, "Drop what"); } @@ -4551,7 +4537,7 @@ void dodrop(obpile_t *op, int wantmulti, obpile_t *dst) { int ch; char buf2[BUFLEN]; // take it off first - this takes time. - sprintf(buf2, "Remove %s",buf); + snprintf(buf2, BUFLEN, "Remove %s",buf); ch = askchar(buf2, "yn","y", B_TRUE); if (ch == 'y') { if (takeoff(player, o)) { @@ -4627,7 +4613,7 @@ void doeat(obpile_t *op) { for (o = player->cell->obpile->first; o ; o = o->next) { if (caneat(player, o)) { getobname(o, obname, o->amt); - sprintf(buf, "There %s %s here. Eat %s", + snprintf(buf, BUFLEN, "There %s %s here. Eat %s", (o->amt == 1) ? "is" : "are", obname, (o->amt == 1) ? "it" : "one"); @@ -4685,8 +4671,8 @@ void dovendingmachine(lifeform_t *lf, object_t *vm) { char obname[BUFLEN]; // get the name of the object getobname(o, obname, o->amt); - sprintf(buf, "%c - %s", o->letter, obname); - sprintf(buf2, "%-60s$%d",buf,getobvalue(o)); + snprintf(buf, BUFLEN, "%c - %s", o->letter, obname); + snprintf(buf2, BUFLEN, "%-60s$%d",buf,getobvalue(o)); mvwprintw(mainwin, y, 0, "%s", buf2); y++; } @@ -4721,7 +4707,7 @@ void dovendingmachine(lifeform_t *lf, object_t *vm) { char answer; // confirm getobname(o, obname, o->amt); - sprintf(buf, "Buy %s for $%d?",obname, getobvalue(o)); + snprintf(buf, BUFLEN, "Buy %s for $%d?",obname, getobvalue(o)); answer = askchar(buf, "yn","n", B_TRUE); if (answer == 'y') { int shopamt; @@ -4732,20 +4718,20 @@ void dovendingmachine(lifeform_t *lf, object_t *vm) { shopamt = o->amt; // avoid "purchased: 2 apples" when you only bought 1 but were holding 1 o = moveob(o, player->pack, ALL); getobname(o, obname, shopamt); - sprintf(toptext, "Purchased: %c - %s", o->letter, obname); + snprintf(toptext, BUFLEN, "Purchased: %c - %s", o->letter, obname); } else { // cancelled strcpy(toptext, ""); } } else { // error - sprintf(toptext,"You don't seem to have any gold..."); + snprintf(toptext, BUFLEN,"You don't seem to have any gold..."); } } else { - sprintf(toptext, "You cannot afford that!"); + snprintf(toptext, BUFLEN, "You cannot afford that!"); } } else { - sprintf(toptext, "No such item."); + snprintf(toptext, BUFLEN, "No such item."); } // end if o } // end if ch } // end while not done @@ -4977,14 +4963,14 @@ void makespellchoicelist(prompt_t *pr, lifeform_t *lf, char *ques, char *ques2, deactspell[nposs] = B_FALSE; // default mpcost[nposs] = -1; if (f->val[2] == NA) { - sprintf(mpdesc[nposs], "(ready)"); + snprintf(mpdesc[nposs], BUFLEN, "(ready)"); validspell[nposs] = B_TRUE; } else { if (f->val[1] == f->val[2]) { - sprintf(mpdesc[nposs], "(ready)"); + snprintf(mpdesc[nposs], BUFLEN, "(ready)"); validspell[nposs] = B_TRUE; } else { - sprintf(mpdesc[nposs], "(%d/%d)",f->val[1],f->val[2]); + snprintf(mpdesc[nposs], BUFLEN, "(%d/%d)",f->val[1],f->val[2]); validspell[nposs] = B_FALSE; } } @@ -5043,7 +5029,7 @@ void makespellchoicelist(prompt_t *pr, lifeform_t *lf, char *ques, char *ques2, validspell[nposs] = B_FALSE; } } else { - sprintf(mpdesc[nposs], "(too hard)"); + snprintf(mpdesc[nposs], BUFLEN, "(too hard)"); validspell[nposs] = B_FALSE; } nposs++; @@ -5097,7 +5083,7 @@ void makespellchoicelist(prompt_t *pr, lifeform_t *lf, char *ques, char *ques2, } strcat(costbuf, mpdesc[i]); - sprintf(buf, "%-30s%s", buf2, costbuf); + snprintf(buf, BUFLEN, "%-30s%s", buf2, costbuf); if (wantinvalid || validspell[i]) { // letter doesn't matter @@ -5108,7 +5094,7 @@ void makespellchoicelist(prompt_t *pr, lifeform_t *lf, char *ques, char *ques2, void domagic(enum OBTYPE spellid, int cellx, int celly) { flag_t *f; - objecttype_t *ot; + objecttype_t *ot = NULL; int finished; // init the prompt if required. @@ -5232,7 +5218,7 @@ void dooperate(obpile_t *op) { getobname(o, obname, o->amt); strcpy(verb, getoperateverb(o)); capitalise(verb); - sprintf(buf, "There %s %s here. %s %s", + snprintf(buf, BUFLEN, "There %s %s here. %s %s", (o->amt == 1) ? "is" : "are", obname, verb, (o->amt == 1) ? "it" : "one"); @@ -5309,9 +5295,9 @@ int dopickup(obpile_t *op, int forceask) { if (needtoask) { if (fromlf) { - sprintf(buf, "Take what from %s",lfname); + snprintf(buf, BUFLEN, "Take what from %s",lfname); } else if (fromob) { - sprintf(buf, "Take what out of %s",fromobname); + snprintf(buf, BUFLEN, "Take what out of %s",fromobname); } else { strcpy(buf, "Pick up what"); } @@ -5472,7 +5458,7 @@ void dohelp(char helpmode) { lf = godlf[i]; real_getlfname(lf, buf, B_FALSE); f = hasflag(lf->flags, F_GODOF); - sprintf(godof, " (%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); + snprintf(godof, BUFLEN, " (%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); strcat(buf, godof); addchoice(&prompt, 'a', buf, NULL, lf); } @@ -5500,7 +5486,7 @@ void doinventory(obpile_t *op) { packweight = getobpileweight(player->pack); maxweight = getmaxcarryweight(player); pct = (packweight / maxweight) * 100; - sprintf(buf, "Inventory (%0.0f/%0.0f kg, %0.0f%%)", packweight, maxweight, pct); + snprintf(buf, BUFLEN, "Inventory (%0.0f/%0.0f kg, %0.0f%%)", packweight, maxweight, pct); o = askobject(op, buf, NULL, AO_NONE); while (o) { // describe it @@ -5528,7 +5514,7 @@ void doquaff(obpile_t *op) { } else { strcpy(drink, "Drink from"); } - sprintf(buf, "There %s %s here. %s %s", + snprintf(buf, BUFLEN, "There %s %s here. %s %s", (o->amt == 1) ? "is" : "are", obname, drink, (o->amt == 1) ? "it" : "one"); @@ -5694,6 +5680,7 @@ void doread(obpile_t *op) { } // ask which object to read + o = askobject(op, "Read what", NULL, AO_READABLE); if (o) { if (isreadable(o)) { @@ -5775,8 +5762,8 @@ int doselguntarget(void) { } getobname(gun, gunname, 1); - sprintf(buf, "Aim %s where?",gunname); - sprintf(buf2, "%s->Target->",gunname); + snprintf(buf, BUFLEN, "Aim %s where?",gunname); + snprintf(buf2, BUFLEN, "%s->Target->",gunname); where = askcoords(buf, buf2, TT_MONSTER, player, UNLIMITED, LOF_NEED, B_TRUE); if (where) { if (where->lf && haslof(player->cell, where, LOF_NEED, NULL)) { @@ -5851,8 +5838,8 @@ void dothrow(obpile_t *op) { maxdist = getmaxthrowrange(player, o); // ask where to throw it - sprintf(buf2, "Throw %s where?",buf); - sprintf(subprompt, "%s->Throw->",buf); + snprintf(buf2, BUFLEN, "Throw %s where?",buf); + snprintf(subprompt, BUFLEN, "%s->Throw->",buf); where = askcoords(buf2, subprompt, TT_MONSTER, player, maxdist, LOF_NEED, B_TRUE); if (where) { @@ -6071,7 +6058,7 @@ void drawlevelfor(lifeform_t *lf) { } if (db) dblog("ending DRAWLEVEL"); - sprintf(buf, "end. ndrawn was %d",ndrawn); + snprintf(buf, BUFLEN, "end. ndrawn was %d",ndrawn); if (db) dblog("%s",buf); //dbtimeend(buf); // move cursor to the player's position and blit @@ -6193,7 +6180,7 @@ void initgfx(void) { // init message buffer strcpy(msgbuf, ""); strcpy(lastmsgbuf, "xxx"); - sprintf(prevmsg, "!nolastmessage!"); + snprintf(prevmsg, BUFLEN, "!nolastmessage!"); msgmulti = 1; } @@ -6527,7 +6514,7 @@ char getchoicestr(prompt_t *prompt, int useshortcuts, int showallatstart) { // display prompt question - sprintf(promptstr, "%s [%s%s] %s", + snprintf(promptstr, BUFLEN, "%s [%s%s] %s", prompt->q[prompt->whichq], prompt->maycancel ? "ESC," : "", showall ? "'=next page,?=toggle" : "?=list", @@ -6552,11 +6539,11 @@ char getchoicestr(prompt_t *prompt, int useshortcuts, int showallatstart) { // fill in the name of the completed choice /* - sprintf(promptstr, "%s %s %s", + snprintf(promptstr, BUFLEN, "%s %s %s", prompt->q[prompt->whichq], prompt->maycancel ? "[ESC=cancel, '=next page] " : "", prompt->choice[validone].text); */ - sprintf(promptstr, "%s [%s%s] %s", + snprintf(promptstr, BUFLEN, "%s [%s%s] %s", prompt->q[prompt->whichq], prompt->maycancel ? "ESC," : "", showall ? "'=next page,?=toggle" : "?=list", @@ -6719,9 +6706,9 @@ void handleinput(void) { int lastdir; int ihaveturned; int stopnow = B_FALSE; + object_t *o; lastdir = f->val[0]; ihaveturned = f->val[1]; - object_t *o; // certain objects will stop us from running. for (o = player->cell->obpile->first ; o ; o = o->next) { @@ -6801,8 +6788,8 @@ void handleinput(void) { flag_t repeatflag; int wantrepeat = B_FALSE; + repeatflag.val[0] = NA; repeatflag.val[1] = NA; repeatflag.val[2] = NA; repeatflag.text = NULL; - drawcursor(); // repeated commands? @@ -7150,7 +7137,7 @@ void dblog(char *format, ... ) { va_list args; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, HUGEBUFLEN, format, args ); va_end(args); if (logfile) { @@ -7167,7 +7154,7 @@ void dblog_nocr(char *format, ... ) { va_list args; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, HUGEBUFLEN, format, args ); va_end(args); if (logfile) { @@ -7204,7 +7191,7 @@ void warn(char *format, ... ) { interrupt(player); va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); msg_real("%s", buf); } @@ -7214,7 +7201,7 @@ void msgnocap(char *format, ... ) { va_list args; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); // like msg, but don't capitalise msg_real("%s", buf); @@ -7225,7 +7212,7 @@ void msg(char *format, ... ) { va_list args; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); capitalise(buf); @@ -7244,7 +7231,7 @@ void msg_real(char *format, ... ) { //msgmod = B_TRUE; va_start(args, format); - vsprintf( buf, format, args ); + vsnprintf( buf, BUFLEN, format, args ); va_end(args); assert(buf[0] != '\0'); @@ -7252,7 +7239,7 @@ void msg_real(char *format, ... ) { // ie repeat of previous message, doesn't have colours, prev msg still on screen if (streq(buf, prevmsg) && !strchr(buf, '^') && strstr(msgbuf, prevmsg)) { msgmulti++; - sprintf(buf, "x%d",msgmulti); + snprintf(buf, BUFLEN, "x%d",msgmulti); } else { strcpy(prevmsg, buf); msgmulti = 1; @@ -7342,7 +7329,7 @@ void drawstatus(void) { if (getmaxmp(player) == player->maxmp) { strcpy(maxmpstr, ""); } else { - sprintf(maxmpstr, "(%d)",player->maxmp); + snprintf(maxmpstr, BUFLEN, "(%d)",player->maxmp); } if (getmaxmp(player) > 0) { @@ -7358,7 +7345,7 @@ void drawstatus(void) { wattron(statwin, A_BOLD); wprintw(statwin, "Xp:"); wattroff(statwin, A_BOLD); - sprintf(buf, "%d", player->level); + snprintf(buf, BUFLEN, "%d", player->level); wprintw(statwin, buf); if (lfhasflag(player, F_HASNEWLEVEL)) { @@ -7378,6 +7365,17 @@ void drawstatus(void) { unsetcol(statwin, C_RED); } + if (lfhasflag(player, F_GRAVBOOSTED)) { + setcol(statwin, C_RED); + wprintw(statwin, " HiGrv"); + unsetcol(statwin, C_RED); + } + if (lfhasflag(player, F_GRAVLESSENED)) { + setcol(statwin, C_BOLDBLUE); + wprintw(statwin, " LoGrv"); + unsetcol(statwin, C_BOLDBLUE); + } + if (lfhasflag(player, F_RAGE)) { setcol(statwin, C_RED); wprintw(statwin, " Rage"); @@ -7573,7 +7571,7 @@ void drawstatus(void) { /* // timespent > 0? if (player->timespent) { - sprintf(buf, "busy: %d", player->timespent); + snprintf(buf, BUFLEN, "busy: %d", player->timespent); strcat(waitbuf, buf); } */ @@ -7582,7 +7580,7 @@ void drawstatus(void) { f = hasflag(player->flags, F_AUTOCMD); if (f) { if (strlen(waitbuf)) strcat(waitbuf, ", "); - sprintf(buf, "'%c' x %d", f->text[0], f->val[0]); + snprintf(buf, BUFLEN, "'%c' x %d", f->text[0], f->val[0]); strcat(waitbuf, buf); } @@ -7600,14 +7598,14 @@ void drawstatus(void) { wmove(statwin, 1, 0); wattron(statwin, A_BOLD); wprintw(statwin, "AR:"); wattroff(statwin, A_BOLD); - sprintf(buf, "%d ", getarmourrating(player, NULL, NULL, NULL)); + snprintf(buf, BUFLEN, "%d ", getarmourrating(player, NULL, NULL, NULL)); wprintw(statwin, buf); wattron(statwin, A_BOLD); wprintw(statwin, "EV:"); wattroff(statwin, A_BOLD); wprintw(statwin, "%d ", getevasion(player)); wattron(statwin, A_BOLD); wprintw(statwin, "$:"); wattroff(statwin, A_BOLD); - sprintf(buf, "%d ", countmoney(player)); + snprintf(buf, BUFLEN, "%d ", countmoney(player)); wprintw(statwin, buf); for (a = 0; a < MAXATTS; a++) { @@ -7766,7 +7764,7 @@ void setobcolour(WINDOW *win, object_t *o, int set) { // dump out a single hiscore line int showhiscoreline(void *hilitescore, int ncols, char **argv, char **colname) { int i; - char *rank, *score, *name, *job, *killer; + char *rank = NULL, *score = NULL, *name = NULL, *job = NULL, *killer = NULL; for (i = 0; i < ncols; i++) { if (streq(colname[i], "rank")) rank = strdup(argv[i]); else if (streq(colname[i], "score")) score = strdup(argv[i]); @@ -7808,7 +7806,7 @@ void showlfarmour(lifeform_t *lf) { if (!lfhasflagval(lf, F_NOBODYPART, bp, NA, NA, NULL)) { object_t *outerob; - sprintf(buf, "%15s:%3s",getbodypartname(bp), " "); + snprintf(buf, BUFLEN, "%15s:%3s",getbodypartname(bp), " "); o = getequippedob(lf->pack, bp); outerob = getouterequippedob(lf, bp); if (o) { @@ -7826,7 +7824,7 @@ void showlfarmour(lifeform_t *lf) { f = hasflag(o->flags, F_ARMOURRATING); if (f && (f->val[0])) { char numbuf[BUFLENSMALL]; - sprintf(numbuf, " ^g[AR:%d]^n",f->val[0]); + snprintf(numbuf, BUFLENSMALL, " ^g[AR:%d]^n",f->val[0]); strcat(rhs, numbuf); } f = hasflag(o->flags, F_OBHP); @@ -7834,7 +7832,7 @@ void showlfarmour(lifeform_t *lf) { char numbuf[BUFLENSMALL]; int pct; pct = (int)(((float)f->val[0] / (float)f->val[1]) * 100.0); - sprintf(numbuf, " ^w[%d%%]^n",pct); + snprintf(numbuf, BUFLENSMALL, " ^w[%d%%]^n",pct); strcat(rhs, numbuf); } } else { @@ -7914,12 +7912,12 @@ void showlfstats(lifeform_t *lf, int showall) { } if (showall) { - sprintf(prompt, "^h[^W@^n=stats ^WS^nkills ^WA^nbils ^WM^nagic ^WE^nffects ^WG^nods %s^W?^n=help ^WESC^n=quit^h]", + snprintf(prompt, BUFLEN, "^h[^W@^n=stats ^WS^nkills ^WA^nbils ^WM^nagic ^WE^nffects ^WG^nods %s^W?^n=help ^WESC^n=quit^h]", isplayer(lf) ? "" : "^WI^ntems " ); - sprintf(cmdchars, "@asmeg%s",isplayer(lf) ? "" : "i"); + snprintf(cmdchars, BUFLEN, "@asmeg%s",isplayer(lf) ? "" : "i"); } else { - sprintf(prompt, "%s", "[ESC=quit]"); - sprintf(cmdchars, "%s", "@"); + snprintf(prompt, BUFLEN, "%s", "[ESC=quit]"); + snprintf(cmdchars, BUFLEN, "%s", "@"); } while (!done) { @@ -7958,9 +7956,9 @@ void showlfstats(lifeform_t *lf, int showall) { if (j) { doheadingsmall(mainwin, y, 0, ftext, "Job"); if (showall) { - sprintf(buf, "Level %d %s", lf->level, j->name); + snprintf(buf, BUFLEN, "Level %d %s", lf->level, j->name); } else { - sprintf(buf, "%s", j->name); + snprintf(buf, BUFLEN, "%s", j->name); } wprintw(mainwin, "%-20s", buf); y++; } @@ -7990,7 +7988,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (lorelev >= PR_ADEPT) unsetcol(mainwin, lorecol); } else { char hpinfo[BUFLEN]; - sprintf(hpinfo, "%s",getseenlfconditionname(lf, player)); + snprintf(hpinfo, BUFLEN, "%s",getseenlfconditionname(lf, player)); if (strlen(hpinfo) > 0) { doheadingsmall(mainwin, y, 0, ftext, "Hit Points"); wprintw(mainwin, "%s", hpinfo); y++; @@ -8002,7 +8000,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (getmaxmp(lf) == lf->maxmp) { strcpy(maxmpstr, ""); } else { - sprintf(maxmpstr, "(%d)",lf->maxmp); + snprintf(maxmpstr, BUFLEN, "(%d)",lf->maxmp); } doheadingsmall(mainwin, y, 0, ftext, "Mana"); @@ -8051,16 +8049,16 @@ void showlfstats(lifeform_t *lf, int showall) { brack = getattrbracket(val, i, bracketname); strcpy(attrname, getattrname(i)); capitalise(attrname); - sprintf(buf, "%d (%s",val, bracketname); + snprintf(buf, BUFLEN, "%d (%s",val, bracketname); if (showall) { char buf2[BUFLEN]; switch (i) { case A_STR: if (dammod > 1) { - sprintf(buf2, ", +%d%% dmg", (int)((dammod * 100) - 100) ); + snprintf(buf2, BUFLEN, ", +%d%% dmg", (int)((dammod * 100) - 100) ); strcat(buf, buf2); } else if (dammod < 1) { - sprintf(buf2, ", -%d%% dmg", (int)(100 - (dammod * 100)) ); + snprintf(buf2, BUFLEN, ", -%d%% dmg", (int)(100 - (dammod * 100)) ); strcat(buf, buf2); } break; @@ -8068,16 +8066,16 @@ void showlfstats(lifeform_t *lf, int showall) { mod = getstatmod(lf, A_CON); if (mod > 0) { mod *= 2; // note: same code as in rollhitdice - sprintf(buf2, ", +%d%% hp",mod ); + snprintf(buf2, BUFLEN, ", +%d%% hp",mod ); strcat(buf, buf2); } break; case A_DEX: if (accmod > 0) { - sprintf(buf2, ", +%d%% acc",accmod ); + snprintf(buf2, BUFLEN, ", +%d%% acc",accmod ); strcat(buf, buf2); } else if (accmod < 0) { - sprintf(buf2, ", %d%% acc",accmod ); + snprintf(buf2, BUFLEN, ", %d%% acc",accmod ); strcat(buf, buf2); } break; @@ -8181,7 +8179,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (maxdam < 0) maxdam = 0; - sprintf(buf, "%s (%d-%d dmg)", w[i]->type->name,(int)mindam,(int)maxdam); + snprintf(buf, BUFLEN, "%s (%d-%d dmg)", w[i]->type->name,(int)mindam,(int)maxdam); doheadingsmall(mainwin, y2, x2, ftext, "Weapon"); wprintw(mainwin, "%-20s", buf); y2++; @@ -8190,19 +8188,19 @@ void showlfstats(lifeform_t *lf, int showall) { speed = getattackspeed(lf); getspeedname(speed, buf2); capitalise(buf2); - sprintf(buf, "%s, %d%%",buf2,acc); + snprintf(buf, BUFLEN, "%s, %d%%",buf2,acc); mvwprintw(mainwin, y2, x2, "%14s", " "); wprintw(mainwin, "%-20s", buf); y2++; } else { // just show weapon name - sprintf(buf, "%s", w[i]->type->name); + snprintf(buf, BUFLEN, "%s", w[i]->type->name); doheadingsmall(mainwin, y2, x2, ftext, "Weapon"); wprintw(mainwin, "%-20s", buf); y2++; } } else { // no weapon - sprintf(buf, "N/A"); + snprintf(buf, BUFLEN, "N/A"); doheadingsmall(mainwin, y2, x2, ftext, "Current Weapon"); wprintw(mainwin, "%-20s", buf); y2++; } @@ -8230,7 +8228,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (o) { char dambuf[BUFLEN]; strcpy(dambuf, ""); - sprintf(buf, "%s", o->type->name); + snprintf(buf, BUFLEN, "%s", o->type->name); // damage if (showall || (lorelev >= PR_BEGINNER)) { int mindam,maxdam; @@ -8245,7 +8243,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (mindam < 0) mindam = 0; if (maxdam < 0) maxdam = 0; - sprintf(dambuf, " (%d-%d dmg)",(int)mindam,(int)maxdam); + snprintf(dambuf, BUFLEN, " (%d-%d dmg)",(int)mindam,(int)maxdam); } doheadingsmall(mainwin, y2, x2, ftext, "Innate Attack"); @@ -8264,7 +8262,7 @@ void showlfstats(lifeform_t *lf, int showall) { // no attacks at all? if ((nweps == 0) && !op->first) { - sprintf(buf, "N/A"); + snprintf(buf, BUFLEN, "N/A"); doheadingsmall(mainwin, y2, x2, ftext, "Attack"); wprintw(mainwin, "%-20s", buf); y2++; } @@ -8313,10 +8311,10 @@ void showlfstats(lifeform_t *lf, int showall) { getspeednameshort(getactspeed(lf), actbuf); getspeednameshort(getmovespeed(lf), movebuf); if (streq(actbuf, movebuf)) { - sprintf(buf, "%s", actbuf); + snprintf(buf, BUFLEN, "%s", actbuf); capitalise(buf); } else { - sprintf(buf, "Mv:%s Act:%s", movebuf,actbuf); + snprintf(buf, BUFLEN, "Mv:%s Act:%s", movebuf,actbuf); } doheadingsmall(mainwin, y2, x2, ftext, "Speed"); @@ -8347,8 +8345,6 @@ void showlfstats(lifeform_t *lf, int showall) { // now show bottom information. if (y2 > y) { y = y2 + 1; - } else { - y++; } // knowledge? @@ -8381,7 +8377,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (strlen(knowstring)) { char dambonusstr[BUFLEN]; // append dam bonus - sprintf(dambonusstr, " (+%d%% acc/dmg)",(lorelev*10)); + snprintf(dambonusstr, BUFLEN, " (+%d%% acc/dmg)",(lorelev*10)); strcat(knowstring, dambonusstr); // print it setcol(mainwin, lorecol); @@ -8397,21 +8393,21 @@ void showlfstats(lifeform_t *lf, int showall) { rating = comparelfs(player, lf); setcol(mainwin, lorecol); if (rating >= 4) { - sprintf(buf, "It is not a threat."); + snprintf(buf, BUFLEN, "It is not a threat."); } else if (rating >= 3) { - sprintf(buf, "You could defeat it very easily."); + snprintf(buf, BUFLEN, "You could defeat it very easily."); } else if (rating >= 2) { - sprintf(buf, "You could defeat it quite easily."); + snprintf(buf, BUFLEN, "You could defeat it quite easily."); } else if (rating >= 1) { - sprintf(buf, "It would present an average challenge."); + snprintf(buf, BUFLEN, "It would present an average challenge."); } else if (rating >= 0.5) { - sprintf(buf, "It would be challenging to defeat."); + snprintf(buf, BUFLEN, "It would be challenging to defeat."); } else if (rating >= 0.25) { - sprintf(buf, "It would present a formidable opponent."); + snprintf(buf, BUFLEN, "It would present a formidable opponent."); } else if (rating >= 0.125) { - sprintf(buf, "It is very dangerous to you."); + snprintf(buf, BUFLEN, "It is very dangerous to you."); } else { - sprintf(buf, "It is EXTREMELY dangerous to you."); + snprintf(buf, BUFLEN, "It is EXTREMELY dangerous to you."); } //mvwprintw(mainwin, y, 0, "Threat rating: %0.1f",comparelfs(player, lf)); mvwprintw(mainwin, y, 0, "%s", buf); @@ -8422,10 +8418,10 @@ void showlfstats(lifeform_t *lf, int showall) { } // obvious physical effects here. + // try to use the whole horizontal space here. f = lfhasknownflag(lf, F_ASLEEP); if (f) { - mvwprintw(mainwin, y, 0, "%s %s sleeping.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s sleeping.", you(lf), is(lf)); } f = lfhasknownflag(lf, F_ATTACHEDTO); if (f && (f->known)) { @@ -8437,35 +8433,29 @@ void showlfstats(lifeform_t *lf, int showall) { } else { strcpy(grabeename, "something"); } - sprintf(buf,"%s %s attached to %s.",you(lf), is(lf), grabeename); - mvwprintw(mainwin, y, 0, buf); - y++; + snprintf(buf, BUFLEN,"%s %s attached to %s.",you(lf), is(lf), grabeename); + wrapprint(mainwin, &y, &x, buf); } f = lfhasknownflag(lf, F_FASTMETAB); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s metabolic rate has been increased.", your(lf), getpossessive(you(lf))); - y++; + wrapprint(mainwin, &y, &x, "%s metabolic rate has been increased.", your(lf), getpossessive(you(lf))); } f = lfhasknownflag(lf, F_FEIGNINGDEATH); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s pretending to be dead.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s pretending to be dead.", you(lf), is(lf)); } f = lfhasknownflag(lf, F_FLYING); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s flying.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s flying.", you(lf), is(lf)); } f = lfhasknownflag(lf, F_PRONE); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s lying on the ground.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s lying on the ground.", you(lf), is(lf)); } f = lfhasflag(lf, F_FROZEN); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s been turned to ice, and %s slowly melting.", you(lf), isplayer(lf) ? "have" : "has", + wrapprint(mainwin, &y, &x, "%s %s been turned to ice, and %s slowly melting.", you(lf), isplayer(lf) ? "have" : "has", is(lf)); - y++; } f = lfhasknownflag(lf, F_GRABBEDBY); if (f && (f->known)) { @@ -8477,9 +8467,8 @@ void showlfstats(lifeform_t *lf, int showall) { } else { strcpy(grabbername, "something"); } - sprintf(buf,"%s %s being held by %s.",you(lf), is(lf), grabbername); - mvwprintw(mainwin, y, 0, buf); - y++; + snprintf(buf, BUFLEN,"%s %s being held by %s.",you(lf), is(lf), grabbername); + wrapprint(mainwin, &y, &x, buf); } f = lfhasknownflag(lf, F_GRABBING); if (f && (f->known)) { @@ -8491,93 +8480,70 @@ void showlfstats(lifeform_t *lf, int showall) { } else { strcpy(grabeename, "something"); } - sprintf(buf,"%s %s holding on to %s.",you(lf), is(lf), grabeename); - mvwprintw(mainwin, y, 0, buf); - y++; + snprintf(buf, BUFLEN,"%s %s holding on to %s.",you(lf), is(lf), grabeename); + wrapprint(mainwin, &y, &x, buf); } f = lfhasknownflag(lf, F_HIDING); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s hiding.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s hiding.", you(lf), is(lf)); } getflags(lf->flags, retflag, &nretflags, F_INJURY, F_NONE); for (i = 0; i < nretflags; i++) { - char buf[BUFLEN], buf2[BUFLEN],buf3[BUFLEN]; + char *p; + char injname[BUFLEN],injdesc[BUFLEN]; f = retflag[i]; - strcpy(buf, getinjuredbpname(f->val[0])); - strcpy(buf2, getinjuryname(f->val[1])); - strcpy(buf3, getinjurydesc(f->val[0], f->val[1])); - if (isplayer(lf)) { - mvwprintw(mainwin, y, 0, "^%cYour %s is %s%s.", getlfcol(lf, CC_VBAD), buf, buf2, buf3); - y++; - } else { - char lfname[BUFLEN]; - getlfname(lf, lfname); - mvwprintw(mainwin, y, 0, "^%c%s%s %s is %s%s.", getlfcol(lf, CC_VBAD), - lfname, getpossessive(lfname), buf, buf2, buf3); - y++; - } + p = readuntil(injname, f->text, '^'); + readuntil(injdesc, p, '^'); + wrapprint(mainwin, &y, &x, "^%c%s %s (%s).", getlfcol(lf, CC_VBAD), your(lf), injname, injdesc); } f = lfhasknownflag(lf, F_INVISIBLE); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s invisible.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s invisible.", you(lf), is(lf)); } f = lfhasknownflag(lf, F_LEVITATING); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s levitating.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s levitating.", you(lf), is(lf)); } f = lfhasflag(lf, F_NONCORPOREAL); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s %s noncorporeal and can walk through walls.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s noncorporeal and can walk through walls.", you(lf), is(lf)); } f = lfhasflag(lf, F_PRODUCESLIGHT); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s produce%s light.", you(lf), isplayer(lf) ? "" : "s"); - y++; + wrapprint(mainwin, &y, &x, "%s produce%s light.", you(lf), isplayer(lf) ? "" : "s"); } f = lfhasknownflag(lf, F_SLOWMETAB); if (f && (f->known)) { - mvwprintw(mainwin, y, 0, "%s metabolic rate has been decreased.", your(lf), getpossessive(you(lf))); - y++; + wrapprint(mainwin, &y, &x, "%s metabolic rate has been decreased.", your(lf), getpossessive(you(lf))); } f = lfhasknownflag(lf, F_SPRINTING); if (f) { if (f->val[0]) { - mvwprintw(mainwin, y, 0, "%s %s sprinting.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s sprinting.", you(lf), is(lf)); } else { - mvwprintw(mainwin, y, 0, "%s %s exhausted.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s exhausted.", you(lf), is(lf)); } } - - f = lfhasknownflag(lf, F_UNDEAD); if (f) { - mvwprintw(mainwin, y, 0, "%s %s undead.", you(lf), is(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s %s undead.", you(lf), is(lf)); } // non-intrinsic effecst like polymorph, eye shading f = lfhasknownflag(lf, F_POLYMORPHED); if (f && (f->known)) { - sprintf(buf, "%s have been polymorphed into a %s.",you(lf), lf->race->name); + snprintf(buf, BUFLEN, "%s have been polymorphed into a %s.",you(lf), lf->race->name); //if (lfhasflag(lf, F_OMNIPOTENT) || lfhasflag(lf, F_EXTRAINFO)) { - sprintf(buf2, " [%d left]", f->lifetime); + snprintf(buf2, BUFLEN, " [%d left]", f->lifetime); strcat(buf, buf2); // } - mvwprintw(mainwin, y, 0, "%s", buf); - y++; + wrapprint(mainwin, &y, &x, "%s", buf); } // missing body parts? if (lfhasflagval(lf, F_NOBODYPART, BP_WEAPON, NA, NA, NULL)) { - mvwprintw(mainwin, y, 0, "%s cannot use weapons.", you(lf)); - y++; + wrapprint(mainwin, &y, &x, "%s cannot use weapons.", you(lf)); } nmissingbp = 0; @@ -8608,7 +8574,7 @@ void showlfstats(lifeform_t *lf, int showall) { } if (nmissingbp) { - sprintf(buf, "%s %s no %s",you(lf), isplayer(lf) ? "have" : "has", getbodypartname(missingbp[0])); + snprintf(buf, BUFLEN, "%s %s no %s",you(lf), isplayer(lf) ? "have" : "has", getbodypartname(missingbp[0])); if (nmissingbp > 1) { // construct list of missing body parts for (i = 1; i < nmissingbp ; i++) { @@ -8622,19 +8588,17 @@ void showlfstats(lifeform_t *lf, int showall) { } } strcat(buf, "."); - mvwprintw(mainwin, y, 0, "%s", buf); - y++; + wrapprint(mainwin, &y, &x, "%s", buf); } f = lfhasflag(lf, F_RETALIATE); if (f && (f->known)) { if (showall || (lorelev >= PR_BEGINNER)) { - mvwprintw(mainwin, y, 0, "%s %s covered by %s (%dd%d %s dmg to attackers).", you(lf), is(lf), f->text, + wrapprint(mainwin, &y, &x, "%s %s covered by %s (%dd%d %s dmg to attackers).", you(lf), is(lf), f->text, f->val[0], f->val[1], getdamname(f->val[2])); } else { - mvwprintw(mainwin, y, 0, "%s %s covered by %s", you(lf), is(lf), f->text); + wrapprint(mainwin, &y, &x, "%s %s covered by %s", you(lf), is(lf), f->text); } - y++; } // fleeing? @@ -8645,9 +8609,7 @@ void showlfstats(lifeform_t *lf, int showall) { lf2 = findlf(NULL, f->val[0]); if (lf2) { getlfname(lf2, buf); - mvwprintw(mainwin, y, 0, "%s %s fleeing from %s.", - you(lf), is(lf), buf); - y++; + wrapprint(mainwin, &y, &x, "%s %s fleeing from %s.", you(lf), is(lf), buf); } } } @@ -8657,8 +8619,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (getlfmaterial(lf) != MT_FLESH) { material_t *mt; mt = findmaterial(getlfmaterial(lf)); - mvwprintw(mainwin, y, 0, "%s %s made out of %s.",you(lf), is(lf), mt->name); - y++; + wrapprint(mainwin, &y, &x, "%s %s made out of %s.",you(lf), is(lf), mt->name); } if (showall) { @@ -8666,24 +8627,24 @@ void showlfstats(lifeform_t *lf, int showall) { strcpy(buf, ""); f = lfhasflagval(lf, F_DTRESIST, DT_ALL, NA, NA, NULL); if (f && (showall || f->known)) { - sprintf(buf, "%s %s resistant to %s", you(lf), is(lf), getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "%s %s resistant to %s", you(lf), is(lf), getdamname(DT_ALL)); } else { first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { f = isresistantto(lf->flags, i); if (f && (showall || f->known)) { if (first) { - sprintf(buf2, "%s %s resistant to: %s", you(lf), is(lf),getdamnamenoun(i)); + snprintf(buf2, BUFLEN, "%s %s resistant to: %s", you(lf), is(lf),getdamnamenoun(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamnamenoun(i)); + snprintf(buf2, BUFLEN, ", %s", getdamnamenoun(i)); } if (lfhasknownflag(lf, F_EXTRAINFO) || lfhasflag(lf, F_OMNIPOTENT)) { if (f->lifetime != PERMENANT) { char buf3[BUFLEN]; - sprintf(buf3, "[%dt]",f->lifetime); + snprintf(buf3, BUFLEN, "[%dt]",f->lifetime); strcat(buf2, buf3); } } @@ -8693,25 +8654,24 @@ void showlfstats(lifeform_t *lf, int showall) { } if (strlen(buf) > 0) { strcat(buf, "."); - mvwprintw(mainwin, y, 0, buf); - y++; + wrapprint(mainwin, &y, &x, buf); } // immunities strcpy(buf, ""); f = lfhasflagval(lf, F_DTIMMUNE, DT_ALL, NA, NA, NULL); if (f && (showall || f->known)) { - sprintf(buf, "%s %s immune to %s", you(lf), is(lf), getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "%s %s immune to %s", you(lf), is(lf), getdamname(DT_ALL)); } else { first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { f = isimmuneto(lf->flags, i); if (f && (showall || f->known)) { if (first) { - sprintf(buf2, "%s %s immune to: %s", you(lf), is(lf), getdamname(i)); + snprintf(buf2, BUFLEN, "%s %s immune to: %s", you(lf), is(lf), getdamname(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamname(i)); + snprintf(buf2, BUFLEN, ", %s", getdamname(i)); } strcat(buf, buf2); } @@ -8720,32 +8680,31 @@ void showlfstats(lifeform_t *lf, int showall) { if (strlen(buf) > 0) { strcat(buf, "."); - mvwprintw(mainwin, y, 0, buf); - y++; + wrapprint(mainwin, &y, &x, buf); } // vulnerabilities strcpy(buf, ""); f = lfhasflagval(lf, F_DTVULN, DT_ALL, NA, NA, NULL); if (f && (showall || f->known)) { - sprintf(buf, "%s %s vulnerable to %s", you(lf), is(lf), getdamname(DT_ALL)); + snprintf(buf, BUFLEN, "%s %s vulnerable to %s", you(lf), is(lf), getdamname(DT_ALL)); } else { first = B_TRUE; for (i = 0; i < MAXDAMTYPE; i++) { f = isvulnto(lf->flags, i); if (f && (showall || f->known)) { if (first) { - sprintf(buf2, "%s %s vulnerable to: %s", you(lf), is(lf), getdamnamenoun(i)); + snprintf(buf2, BUFLEN, "%s %s vulnerable to: %s", you(lf), is(lf), getdamnamenoun(i)); first = B_FALSE; } else { - sprintf(buf2, ", %s", getdamnamenoun(i)); + snprintf(buf2, BUFLEN, ", %s", getdamnamenoun(i)); } if (lfhasknownflag(lf, F_EXTRAINFO) || lfhasflag(lf, F_OMNIPOTENT)) { if (f->lifetime != PERMENANT) { char buf3[BUFLEN]; - sprintf(buf3, "[%dt]",f->lifetime); + snprintf(buf3, BUFLEN, "[%dt]",f->lifetime); strcat(buf2, buf3); } } @@ -8755,8 +8714,7 @@ void showlfstats(lifeform_t *lf, int showall) { } if (strlen(buf) > 0) { strcat(buf, "."); - mvwprintw(mainwin, y, 0, buf); - y++; + wrapprint(mainwin, &y, &x, buf); } } @@ -8774,9 +8732,9 @@ void showlfstats(lifeform_t *lf, int showall) { int range; if (f->val[2] == NA) { - sprintf(expirebuf, "at will"); + snprintf(expirebuf, BUFLEN, "at will"); } else { - sprintf(expirebuf, "every %d turn%s",f->val[2], + snprintf(expirebuf, BUFLEN, "every %d turn%s",f->val[2], (f->val[2] == 1) ? "" : "s"); } @@ -8787,21 +8745,21 @@ void showlfstats(lifeform_t *lf, int showall) { } if (range) { char rbuf[BUFLEN]; - sprintf(rbuf, ",range:%d",range); + snprintf(rbuf, BUFLEN, ",range:%d",range); strcat(expirebuf, rbuf); } if (strlen(expirebuf)) { - sprintf(eb2,"(%s)",expirebuf); + snprintf(eb2, BUFLEN,"(%s)",expirebuf); } else { strcpy(eb2, ""); } setcol(mainwin, C_GREEN); - sprintf(buf, "%-12s", ot->name); + snprintf(buf, BUFLEN, "%-12s", ot->name); mvwprintw(mainwin, y, 0, buf); unsetcol(mainwin, C_GREEN); - sprintf(buf, "%s%s", ot->desc, eb2); + snprintf(buf, BUFLEN, "%s%s", ot->desc, eb2); wprintw(mainwin, buf); if (downline(&y, h, "ABILITIES", NULL, prompt, cmdchars, &ch)) { @@ -8840,7 +8798,7 @@ void showlfstats(lifeform_t *lf, int showall) { //centre(mainwin, y, "SKILLS"); y ++; - sprintf(skilltitle, "%-40s%-40s","AVAILABLE SKILLS", "KNOWN SKILLS (*=maxed)"); + snprintf(skilltitle, BUFLEN, "%-40s%-40s","AVAILABLE SKILLS", "KNOWN SKILLS (*=maxed)"); doheading(mainwin, &y, 0, skilltitle); for (n = 0; n < MAXOF(numknown,numavailable); n++) { if (n < numavailable) { @@ -8869,7 +8827,7 @@ void showlfstats(lifeform_t *lf, int showall) { int anyfound; int exitnow = B_FALSE; - sprintf(subheading, " %-4s%-26s%-15s%-13s%s","Lv","Spell", "School", "Power", "Cost"); + snprintf(subheading, BUFLEN, " %-4s%-26s%-15s%-13s%s","Lv","Spell", "School", "Power", "Cost"); centre(mainwin, C_WHITE, y, "MAGIC"); y += 2; doheading(mainwin, &y, 0, subheading); @@ -8896,7 +8854,7 @@ void showlfstats(lifeform_t *lf, int showall) { // power power = getspellpower(lf, ot->id); - sprintf(powerbuf, "["); + snprintf(powerbuf, BUFLEN, "["); for (i = 0; i < power; i++) { strcat(powerbuf, "#"); } @@ -8911,9 +8869,9 @@ void showlfstats(lifeform_t *lf, int showall) { mpcost = 0; if (f->val[2] == NA) { - sprintf(mpbuf, "At will"); + snprintf(mpbuf, BUFLEN, "At will"); } else { - sprintf(mpbuf, "At will, every %d turn%s",f->val[2], + snprintf(mpbuf, BUFLEN, "At will, every %d turn%s",f->val[2], (f->val[2] == 1) ? "" : "s"); } atwill = B_TRUE; @@ -8922,7 +8880,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (mpcost) { getspellcosttext(lf, ot->id, power, mpbuf); } else { - sprintf(mpbuf, "At will"); + snprintf(mpbuf, BUFLEN, "At will"); } } @@ -8935,7 +8893,7 @@ void showlfstats(lifeform_t *lf, int showall) { getspellname(ot->id, lf, spellname); if (castable) setcol(mainwin, C_GREEN); else setcol(mainwin, C_RED); - sprintf(buf, " %-4d%-26s%-15s%-13s%s",thislev, spellname, getschoolnameshort(getspellschoolknown(lf, ot->id)), powerbuf, mpbuf); + snprintf(buf, BUFLEN, " %-4d%-26s%-15s%-13s%s",thislev, spellname, getschoolnameshort(getspellschoolknown(lf, ot->id)), powerbuf, mpbuf); mvwprintw(mainwin, y, 0, "%s\n", buf); if (castable) unsetcol(mainwin, C_GREEN); else unsetcol(mainwin, C_RED); @@ -9081,7 +9039,7 @@ void showlfstats(lifeform_t *lf, int showall) { } else { strcpy(charmername, "something"); } - sprintf(buf,"%s %s been charmed by %s.",you(lf), isplayer(lf) ? "have" : "has", charmername); + snprintf(buf, BUFLEN,"%s %s been charmed by %s.",you(lf), isplayer(lf) ? "have" : "has", charmername); mvwprintw(mainwin, y, 0, buf); y++; } @@ -9184,7 +9142,7 @@ void showlfstats(lifeform_t *lf, int showall) { if (f->val[0] == NA) { strcpy(damtypebuf, "damage"); } else { - sprintf(damtypebuf, "%s damage", getdamname(f->val[0])); + snprintf(damtypebuf, BUFLEN, "%s damage", getdamname(f->val[0])); } dicetotext(ndice, nsides, bonus, &min, &max, dicebuf, mmbuf); @@ -9225,13 +9183,13 @@ void showlfstats(lifeform_t *lf, int showall) { } } - sprintf(buf, "%s %s sick with %s%s.", you(lf), is(lf), + snprintf(buf, BUFLEN, "%s %s sick with %s%s.", you(lf), is(lf), getpoisonname(f->val[0]), knownfatal ? ", potentially fatally" : ""); if (lfhasflag(lf, F_EXTRAINFO) || lfhasflag(lf, F_OMNIPOTENT) || (getskill(player, SK_FIRSTAID) >= PR_ADEPT) ) { char buf2[BUFLEN]; - sprintf(buf2, " [max %d turns left]", f->lifetime); + snprintf(buf2, BUFLEN, " [max %d turns left]", f->lifetime); strcat(buf, buf2); } mvwprintw(mainwin, y, 0, buf); @@ -9246,20 +9204,20 @@ void showlfstats(lifeform_t *lf, int showall) { } f = lfhasknownflag(lf, F_PACKATTACK); if (f && (f->known)) { - sprintf(buf,"%s deal%s extra damage when in a pack.", you(lf), isplayer(lf) ? "" : "s"); + snprintf(buf, BUFLEN,"%s deal%s extra damage when in a pack.", you(lf), isplayer(lf) ? "" : "s"); mvwprintw(mainwin, y, 0, buf); y++; } f = lfhasknownflag(lf, F_PHALANX); if (f && (f->known)) { - sprintf(buf,"%s gain%s %d extra armour rating when in a %s pack.", you(lf), isplayer(lf) ? "" : "s", + snprintf(buf, BUFLEN,"%s gain%s %d extra armour rating when in a %s pack.", you(lf), isplayer(lf) ? "" : "s", f->val[0], f->text); mvwprintw(mainwin, y, 0, buf); y++; } f = lfhasknownflag(lf, F_HEAVYBLOW); if (f) { - sprintf(buf,"%s%s attacks knock enemies back.", you(lf), getpossessive(you(lf))); + snprintf(buf, BUFLEN,"%s%s attacks knock enemies back.", you(lf), getpossessive(you(lf))); mvwprintw(mainwin, y, 0, buf); y++; } @@ -9275,7 +9233,7 @@ void showlfstats(lifeform_t *lf, int showall) { f = lfhasknownflag(lf, F_QUICKBITE); if (f && (f->known)) { - sprintf(buf,"%s can bite wounded enemies for extra damage.", you(lf)); + snprintf(buf, BUFLEN,"%s can bite wounded enemies for extra damage.", you(lf)); mvwprintw(mainwin, y, 0, buf); y++; } @@ -9284,7 +9242,7 @@ void showlfstats(lifeform_t *lf, int showall) { strcpy(buf,"The next object you touch will turn to solid ice."); if (lfhasflag(lf, F_OMNIPOTENT)) { char buf2[BUFLEN]; - sprintf(buf2, " [%d uses left]", f->val[0]); + snprintf(buf2, BUFLEN, " [%d uses left]", f->val[0]); strcat(buf, buf2); } mvwprintw(mainwin, y, 0, buf); @@ -9462,7 +9420,7 @@ void showlfstats(lifeform_t *lf, int showall) { packweight = getobpileweight(lf->pack); maxweight = getmaxcarryweight(lf); pct = (packweight / maxweight) * 100; - sprintf(invtitle, "It is carrying: (%0.0f/%0.0f kg, %0.0f%%)", packweight, maxweight, pct); + snprintf(invtitle, BUFLEN, "It is carrying: (%0.0f/%0.0f kg, %0.0f%%)", packweight, maxweight, pct); mvwprintw(mainwin, y, 0, "%s", invtitle); y += 2; for (o = lf->pack->first ; o ; o = o->next) { @@ -9485,7 +9443,7 @@ void showlfstats(lifeform_t *lf, int showall) { centre(mainwin, C_WHITE, 0, "GODS"); y = 2; - sprintf(line, "%-26s Prayed? %-22s %s","God","Piety", "Happiness"); + snprintf(line, BUFLEN, "%-26s Prayed? %-22s %s","God","Piety", "Happiness"); doheading(mainwin, &y, 0, line); @@ -9521,7 +9479,7 @@ void showlfstats(lifeform_t *lf, int showall) { // TODO: construct piety buf [---+--|--------------------] - sprintf(pietybuf, "^n["); + snprintf(pietybuf, BUFLEN, "^n["); switch (col) { case C_ORANGE: strcpy(colbuf, "^T"); break; case C_RED: strcpy(colbuf, "^B"); break; @@ -9543,7 +9501,7 @@ void showlfstats(lifeform_t *lf, int showall) { } } strcat(pietybuf, "^n]"); - sprintf(line, "%s%-26s%-9s%s %s%s", + snprintf(line, BUFLEN, "%s%-26s%-9s%s %s%s", prayedto ? "^g" : "^n", godname, prayedto ? " Yes " : " No ", @@ -9724,5 +9682,31 @@ void tombstone(lifeform_t *lf) { // close down curses curs_set(1); endwin(); - } + +void wrapprint(WINDOW *win, int *y, int *x, char *format, ... ) { + char buf[BUFLEN]; + va_list args; + int w; + + va_start(args, format); + vsnprintf( buf, BUFLEN, format, args ); + va_end(args); + + strncat(buf, " ", BUFLEN); + + w = getmaxx(win); + if (*x != 0) { + if (*x + strlen(buf) >= w) { + (*y)++; + *x = 0; + } + } + wmove(win, *y, *x); + textwithcol(win, buf); + (*x) += strlen(buf); +} + + + + diff --git a/io.h b/io.h index 731578b..db32fba 100644 --- a/io.h +++ b/io.h @@ -117,3 +117,4 @@ void textwithcol(WINDOW *win, char *buf); void tombstone(lifeform_t *lf); void updatestatus(void); int updateviewfor(cell_t *cell); +void wrapprint(WINDOW *win, int *y, int *x, char *format, ... ); diff --git a/lf.c b/lf.c index 4d3fcd3..9a2950b 100644 --- a/lf.c +++ b/lf.c @@ -117,7 +117,7 @@ void autoweild(lifeform_t *lf) { ot = getrandomammofor(firearm); if (ot) { char buf[BUFLEN]; - sprintf(buf, "1-5 %s",ot->name); + snprintf(buf, BUFLEN, "1-5 %s",ot->name); o = addob(lf->pack, buf); loadfirearm(NULL, firearm, o); } @@ -1060,6 +1060,21 @@ int canweild(lifeform_t *lf, object_t *o) { return B_FALSE; } + // too heavy? + if (o && lfhasflagval(lf, F_INJURY, IJ_SHOULDERDISLOCATED, NA, NA, NULL)) { + if (isheavyweapon(o)) { + reason = E_INJURED; + return B_FALSE; + } + } + + if (o && lfhasflagval(lf, F_INJURY, IJ_TENDONCUT, NA, NA, NULL)) { + if ((weildloc == BP_WEAPON) || (otherloc == BP_WEAPON)) { + reason = E_INJURED; + return B_FALSE; + } + } + // special case... if (lf->race->id == R_DANCINGWEAPON) { return B_TRUE; @@ -1200,10 +1215,10 @@ int castspell(lifeform_t *lf, enum OBTYPE sid, lifeform_t *targlf, object_t *tar char ch; // ask what power max = power; - sprintf(buf, "Cast %s at what power level?", sp->name); + snprintf(buf, BUFLEN, "Cast %s at what power level?", sp->name); initprompt(&prompt, buf); for (i = 1; i <= max; i++) { - sprintf(buf, "Power %s (%d MP)", roman(i), getmpcost(lf, sid) * i); + snprintf(buf, BUFLEN, "Power %s (%d MP)", roman(i), getmpcost(lf, sid) * i); getvarpowerspelldesc(sp->id, i, desc); if (strlen(desc)) { strcat(buf, "\t"); @@ -1240,12 +1255,26 @@ int castspell(lifeform_t *lf, enum OBTYPE sid, lifeform_t *targlf, object_t *tar // announce if (!isplayer(lf) && cansee(player, lf)) { char lfname[BUFLEN]; + char whattosay[BUFLEN]; getlfname(lf, lfname); + // special case f = lfhasflag(lf,F_SPELLCASTTEXT); if (f) { if (strlen(f->text)) { - msg("%s %s.", lfname, f->text); + snprintf(whattosay, BUFLEN, "%s %s", lfname, f->text); + if (targlf && (f->val[2] == B_APPENDYOU)) { + char targname[BUFLEN]; + if (targlf == lf) { + strcpy(targname, "itself"); + } else { + getlfname(targlf, targname); + } + strcat(whattosay, " at "); + strcat(whattosay, targname); + } + strcat(whattosay, "."); + msg("%s", whattosay); } } else { if (hasflag(sp->flags, F_CASTINGTIME)) { @@ -1286,21 +1315,21 @@ int castspell(lifeform_t *lf, enum OBTYPE sid, lifeform_t *targlf, object_t *tar strcpy(castingbuf, ""); if (targlf) { - sprintf(tempbuf, "%d;",targlf->id); + snprintf(tempbuf, BUFLEN, "%d;",targlf->id); } else { strcpy(tempbuf, "-1;"); } strcat(castingbuf, tempbuf); if (targob) { - sprintf(tempbuf, "%ld;",targob->id); + snprintf(tempbuf, BUFLEN, "%ld;",targob->id); } else { strcpy(tempbuf, "-1;"); } strcat(castingbuf, tempbuf); if (targcell) { - sprintf(tempbuf, "%d;%d;%d;",targcell->map->id,targcell->x, targcell->y); + snprintf(tempbuf, BUFLEN, "%d;%d;%d;",targcell->map->id,targcell->x, targcell->y); } else { strcpy(tempbuf, "-1;-1;-1;"); } @@ -1687,9 +1716,7 @@ int demandbribe(lifeform_t *lf) { char buf[BUFLEN], answer[BUFLEN]; object_t *gold, *mongold; int satisfied = B_FALSE; - int nminions; int i,heard; - lifeform_t *minion[MAXCANDIDATES]; hd = gethitdice(lf); gold = hasob(player->pack, OT_GOLD); @@ -1712,7 +1739,7 @@ int demandbribe(lifeform_t *lf) { int doagain = B_TRUE; more(); while (doagain) { - sprintf(buf, "How much gold will you give %s (you have $%d)", lfname, totmoney); + snprintf(buf, BUFLEN, "How much gold will you give %s (you have $%d)", lfname, totmoney); askstring(buf, '?', answer, BUFLEN, NULL); amtgiven = atoi(answer); if (amtgiven > totmoney) { @@ -1737,7 +1764,7 @@ int demandbribe(lifeform_t *lf) { mongold->amt += amtgiven; } else { char gbuf[BUFLEN]; - sprintf(gbuf, "%d gold", amtgiven); + snprintf(gbuf, BUFLEN, "%d gold", amtgiven); mongold = addob(lf->pack, gbuf); } @@ -1758,8 +1785,11 @@ int demandbribe(lifeform_t *lf) { // if you gave the gold, mosnter becomes peaceful if (satisfied) { + int nminions; + lifeform_t *minion[MAXCANDIDATES]; makepeaceful(lf); // also make any of its minions peaceful + getminions(lf, minion, &nminions); for (i = 0; i < nminions; i++) { makepeaceful(minion[i]); } @@ -1845,6 +1875,11 @@ void die(lifeform_t *lf) { } } + if (lf->race->id == R_GLOWBUG) { + // final spell... + castspell(lf, OT_S_FLASH, NULL, NULL, lf->cell); + } + // revert to your original form first. if (lfhasflag(lf, F_POLYMORPHED)) { if (lfhasflag(lf, F_ORIGRACE)) { @@ -1952,7 +1987,7 @@ void die(lifeform_t *lf) { numbones += rnd(1,10); } // drop bones - sprintf(bonestring, "%d bones",numbones); + snprintf(bonestring, BUFLEN, "%d bones",numbones); addob(lf->cell->obpile, bonestring); } else { char corpseprefix[BUFLEN]; @@ -1975,9 +2010,9 @@ void die(lifeform_t *lf) { f = lfhasflag(lf, F_CORPSETYPE); if (f) { - sprintf(corpsename, "%s%s", corpseprefix, f->text); + snprintf(corpsename, BUFLEN, "%s%s", corpseprefix, f->text); } else { - sprintf(corpsename, "%s%s corpse", corpseprefix, lf->race->name); + snprintf(corpsename, BUFLEN, "%s%s corpse", corpseprefix, lf->race->name); } corpse = addob(lf->cell->obpile, corpsename); @@ -2022,7 +2057,7 @@ void die(lifeform_t *lf) { object_t *headob; char headname[BUFLEN]; // drop head too - sprintf(headname, "%s head",lf->race->name); + snprintf(headname, BUFLEN, "%s head",lf->race->name); headob = addob(lf->cell->obpile, headname); colourmatchob(headob, lf); } @@ -2057,7 +2092,7 @@ void die(lifeform_t *lf) { lf->hp = lf->maxhp; if (corpse) { char cid[BUFLEN]; - sprintf(cid, "%ld",corpse->id); + snprintf(cid, BUFLEN, "%ld",corpse->id); addflag(lf->flags, F_MYCORPSE, NA, NA, NA, cid); } } else { @@ -2154,7 +2189,7 @@ void dumpxp(void) { dblog(""); for (i = 2; i < 30; i++) { char buf[BUFLEN]; - sprintf(buf, "Lev %d",i); + snprintf(buf, BUFLEN, "Lev %d",i); dblog("%-10s%ld",buf, getxpforlev(i)); } } @@ -2352,13 +2387,13 @@ void dumplev(void) { if ((rarity >= prevmin) && (rarity <= prevmax)) { // only print if dlev is 1 if (i == 1) { - sprintf(buf, "%s, ", r->name); + snprintf(buf, BUFLEN, "%s, ", r->name); } } else { // ie. new mosnter for this lev - //sprintf(buf, "*%s*, ", r->name); + //snprintf(buf, BUFLEN, "*%s*, ", r->name); //makeuppercase(buf); - sprintf(buf, "%s, ", r->name); + snprintf(buf, BUFLEN, "%s, ", r->name); } fprintf(logfile, "%s", buf); } @@ -2389,13 +2424,13 @@ void dumplev(void) { if ((rarity >= prevmin) && (rarity <= prevmax)) { // only print if dlev is 1 if (i == 1) { - sprintf(buf, "%s, ", ot->name); + snprintf(buf, BUFLEN, "%s, ", ot->name); } } else { // ie. new object for this lev - //sprintf(buf, "*%s*, ", r->name); + //snprintf(buf, BUFLEN, "*%s*, ", r->name); //makeuppercase(buf); - sprintf(buf, "%s, ", ot->name); + snprintf(buf, BUFLEN, "%s, ", ot->name); } fprintf(logfile, "%s", buf); } @@ -2543,7 +2578,7 @@ int eat(lifeform_t *lf, object_t *o) { startpcteaten,pcteaten, eateachturn,turnstoeat,fullyeaten ? "YES" : "NO"); */ - sprintf(buf, "%ld",o->id); + snprintf(buf, BUFLEN, "%ld",o->id); alreadyeating = lfhasflagval(lf, F_EATING, NA, NA, NA, buf); // announce @@ -2599,9 +2634,9 @@ int eat(lifeform_t *lf, object_t *o) { } // food poisoning for 20 turns if (drinking) { - sprintf(dambuf, "%s",obname); + snprintf(dambuf, BUFLEN, "%s",obname); } else { - sprintf(dambuf, "a bad %s",noprefix(obname)); + snprintf(dambuf, BUFLEN, "a bad %s",noprefix(obname)); } poison(lf, 20, P_FOOD, 1, dambuf); } @@ -2774,7 +2809,7 @@ void enhanceskills(lifeform_t *lf) { // increase str/int etc if we can f = lfhasflag(lf, F_STATGAINREADY); while (f && (f->val[2] > 0)) { - enum ATTRIB att; + enum ATTRIB att = A_NONE; if (isplayer(lf)) { char ch; more(); @@ -2836,17 +2871,17 @@ void enhanceskills(lifeform_t *lf) { if (skillstolearn) { char buf[BUFLEN]; if (skillstoenhance) { - sprintf(buf, "(E)nhance skills, (L)earn skills, or (N)either (%d points left)?",lf->skillpoints); + snprintf(buf, BUFLEN, "(E)nhance skills, (L)earn skills, or (N)either (%d points left)?",lf->skillpoints); eorl = askchar(buf,"eln","e", B_TRUE); } else { - sprintf(buf,"Learn a new skill (%d points left)?",lf->skillpoints); + snprintf(buf, BUFLEN,"Learn a new skill (%d points left)?",lf->skillpoints); ch = askchar(buf,"yn","y", B_TRUE); if (ch == 'y') eorl = 'l'; else eorl = 'n'; } } else if (skillstoenhance) { char buf[BUFLEN]; - sprintf(buf,"Enhance your current skills (%d points left)?",lf->skillpoints); + snprintf(buf, BUFLEN,"Enhance your current skills (%d points left)?",lf->skillpoints); ch = askchar(buf,"yn","y", B_TRUE); if (ch == 'y') eorl = 'e'; else eorl = 'n'; @@ -2861,8 +2896,8 @@ void enhanceskills(lifeform_t *lf) { if (skillstoenhance) { char ques[BUFLEN],ques2[BUFLEN]; int done = B_FALSE; - sprintf(ques, "Enhance which skill (%d points left)?", lf->skillpoints); - sprintf(ques2, "Describe which skill?"); + snprintf(ques, BUFLEN, "Enhance which skill (%d points left)?", lf->skillpoints); + snprintf(ques2, BUFLEN, "Describe which skill?"); initprompt(&prompt, ques); addpromptq(&prompt, ques2); @@ -2873,7 +2908,7 @@ void enhanceskills(lifeform_t *lf) { cost = getskilllevcost(f->val[1] + 1); if (lf->skillpoints >= cost) { char buf[BUFLEN]; - sprintf(buf, "%s (%s, %d points)", getskillname(f->val[0]), + snprintf(buf, BUFLEN, "%s (%s, %d points)", getskillname(f->val[0]), getskilllevelname(f->val[1] + 1), cost); addchoice(&prompt, ch++, getskillname(f->val[0]), buf, f); } @@ -2911,8 +2946,8 @@ void enhanceskills(lifeform_t *lf) { if (skillstolearn) { int done = B_FALSE; char ques[BUFLEN],ques2[BUFLEN]; - sprintf(ques, "Learn which new skill (%d points left)?", player->skillpoints); - sprintf(ques2, "Describe which skill?"); + snprintf(ques, BUFLEN, "Learn which new skill (%d points left)?", player->skillpoints); + snprintf(ques2, BUFLEN, "Describe which skill?"); initprompt(&prompt, ques); addpromptq(&prompt, ques2); @@ -2920,7 +2955,7 @@ void enhanceskills(lifeform_t *lf) { for (sk = firstskill ; sk ; sk = sk->next) { if (!getskill(player, sk->id) && canlearn(player, sk->id)) { char buf[BUFLEN]; - sprintf(buf, "%-18s(%s)", getskillname(sk->id), getskilldesc(sk->id)); + snprintf(buf, BUFLEN, "%-18s(%s)", getskillname(sk->id), getskilldesc(sk->id)); addchoice(&prompt, ch++, getskillname(sk->id), buf, sk); } } @@ -3599,7 +3634,7 @@ int freezelf(lifeform_t *freezee, lifeform_t *freezer, int howlong) { if (freezer) { char lfname[BUFLEN]; getlfname(freezer, lfname); - sprintf(buf, "being frozen by %s",lfname); + snprintf(buf, BUFLEN, "being frozen by %s",lfname); } else { strcpy(buf, "being frozen"); } @@ -4505,7 +4540,7 @@ int getbodyparthitchance(enum BODYPART bp) { case BP_FEET: return 3; case BP_LEGS: return 4; case BP_SHOULDERS: return 4; - case BP_BODY: return 5; + case BP_BODY: return 6; default: break; } return 0; // ie rings, weapon @@ -4840,8 +4875,10 @@ int getlfaccuracy(lifeform_t *lf, object_t *wep) { } else if (f->id == F_ARMOURPENALTY) { acc -= adjustarmourpenalty(lf, f->val[0]); } else if (f->id == F_INJURY) { - if (f->val[0] == BP_HANDS) { - acc -= 25; + if (f->val[0] == IJ_FINGERBROKEN) { + acc -= 10; + } else if (f->val[0] == IJ_SHOULDERDISLOCATED) { + acc -= 20; } } } @@ -4984,11 +5021,12 @@ enum SKILLLEVEL getmaxskilllevel(lifeform_t *lf, enum SKILL skid) { int getminions(lifeform_t *lf, lifeform_t **minion, int *nminions) { flag_t *f; lifeform_t *min; - *nminions = 0; int i; flag_t *retflag[MAXCANDIDATES]; int nretflags; + *nminions = 0; + getflags(lf->flags, retflag, &nretflags, F_MINION, F_NONE); for (i = 0; i < nretflags; i++) { f = retflag[i]; @@ -5249,6 +5287,11 @@ float getmaxcarryweight(lifeform_t *lf) { } max = getlfweight(lf, B_NOOBS) * mod; + + if (lfhasflagval(lf, F_INJURY, IJ_RIBCRACKED, NA, NA, NULL)) { + max /= 2; + } + limitf(&max, 0, NA); return max; } @@ -5315,6 +5358,10 @@ int getvisrange(lifeform_t *lf) { range = MAXVISRANGE; } + if (lfhasflagval(lf, F_INJURY, IJ_BLACKEYE, NA, NA, NULL)) { + range /= 2; + } + // can't see as far if you're on the ground if (isprone(lf)) { range /= 2; @@ -5377,8 +5424,10 @@ int getmovespeed(lifeform_t *lf) { } else if ((f->id == F_FASTMOVE) || (f->id == F_FASTACTMOVE)) { speed -= f->val[0]; } else if (f->id == F_INJURY) { - if (f->val[0] == BP_LEGS) { + if (f->val[0] == IJ_LEGBRUISE) { speed += 5; + } else if (f->val[0] == IJ_LEGBROKEN) { + speed += 10; } } else if (f->id == F_SPRINTING) { if (f->val[0]) { @@ -5391,6 +5440,11 @@ int getmovespeed(lifeform_t *lf) { } } + // flying in low gravity? + if (lfhasflag(lf, F_GRAVLESSENED) && lfhasflag(lf, F_FLYING)) { + speed -= 5; + } + switch (isburdened(lf)) { case BR_NONE: break; @@ -5540,17 +5594,17 @@ char *real_getlfname(lifeform_t *lf, char *buf, int usevis) { if (!lfhasflag(lf, F_NOJOBTEXT) && !lfhasflag(lf, F_NAME) && !lfhasflag(lf, F_UNIQUE)) { j = getjob(lf); if (j) { - sprintf(jobstring, " %s", j->name); + snprintf(jobstring, BUFLEN, " %s", j->name); jobstring[1] = tolower(jobstring[1]); } } if (isplayer(lf)) { - sprintf(buf, "you"); + snprintf(buf, BUFLEN, "you"); } else { //if (isblind(player)) { if (usevis && !cansee(player, lf)) { - sprintf(buf, "something"); + snprintf(buf, BUFLEN, "something"); } else { if (lf->race->id == R_DANCINGWEAPON) { object_t *wep; @@ -5558,30 +5612,30 @@ char *real_getlfname(lifeform_t *lf, char *buf, int usevis) { if (wep) { char obname[BUFLEN]; real_getobname(wep, obname, 1, B_TRUE, B_FALSE, B_FALSE, B_FALSE, B_FALSE); - sprintf(buf, "%s%s%s",the,descstring,noprefix(obname)); + snprintf(buf, BUFLEN, "%s%s%s",the,descstring,noprefix(obname)); } else { - sprintf(buf, "%s%s%s%s",the,descstring,lname,jobstring); + snprintf(buf, BUFLEN, "%s%s%s%s",the,descstring,lname,jobstring); } } else if (lfhasflag(lf, F_FEIGNINGDEATH)) { if (lfhasflag(lf, F_NAME)) { // ie. "jimbo's corpse" - sprintf(buf, "%s%s corpse", lname, getpossessive(lname)); + snprintf(buf, BUFLEN, "%s%s corpse", lname, getpossessive(lname)); } else { // ie. "a wolf corpse" - sprintf(buf, "%s %s corpse", needan(lname) ? "an" : "a", lname); + snprintf(buf, BUFLEN, "%s %s corpse", needan(lname) ? "an" : "a", lname); } } else if (lfhasflag(lf, F_NAME)) { - sprintf(buf, "%s%s", descstring, lname); + snprintf(buf, BUFLEN, "%s%s", descstring, lname); } else { char zombiestring[BUFLEN]; f = hasflag(lf->flags, F_LFSUFFIX); strcpy(zombiestring, ""); if (f) { - sprintf(zombiestring, " %s", f->text); + snprintf(zombiestring, BUFLEN, " %s", f->text); } - sprintf(buf, "%s%s%s%s%s",the,descstring,lname,jobstring,zombiestring); + snprintf(buf, BUFLEN, "%s%s%s%s%s",the,descstring,lname,jobstring,zombiestring); } } } @@ -5594,7 +5648,7 @@ char *getlfnamea(lifeform_t *lf, char *buf) { char *real_getlfnamea(lifeform_t *lf, char *buf, int usevis) { if (isplayer(lf)) { - sprintf(buf, "you"); + snprintf(buf, BUFLEN, "you"); } else { char buf2[BUFLEN]; char the[6]; @@ -5615,7 +5669,7 @@ char *real_getlfnamea(lifeform_t *lf, char *buf, int usevis) { } } - sprintf(buf, "%s%s", the, noprefix(buf2)); + snprintf(buf, BUFLEN, "%s%s", the, noprefix(buf2)); } return buf; } @@ -5703,9 +5757,9 @@ char *getplayernamefull(char *buf) { j = getjob(player); if (j) { - sprintf(buf, "%s the %s", pname, j->name); + snprintf(buf, BUFLEN, "%s the %s", pname, j->name); } else { - sprintf(buf, "%s the %s", pname, player->race->name); + snprintf(buf, BUFLEN, "%s the %s", pname, player->race->name); } return buf; } @@ -5861,13 +5915,13 @@ enum BODYPART getrandomcorebp(lifeform_t *lf) { if (hasbp(lf, BP_LEGS)) bp[nparts++] = BP_LEGS; if (hasbp(lf, BP_HEAD)) bp[nparts++] = BP_HEAD; for (i = 0;i < nparts; i++) { - int n; - cutoff[i] = getbodyparthitchance(bp[i]); - for (n = 0; n < i; n++) { - cutoff[i] += cutoff[n]; + if (i == 0) { + cutoff[i] = getbodyparthitchance(bp[i]); + } else { + cutoff[i] = cutoff[i-1] + getbodyparthitchance(bp[i]); } - max += cutoff[i]; } + max = cutoff[nparts-1]; num = rnd(1,max); for (i = 0;i < nparts; i++) { if (num <= cutoff[i]) { @@ -5877,6 +5931,7 @@ enum BODYPART getrandomcorebp(lifeform_t *lf) { } if (selbp == BP_NONE) { dblog("error in getrandomcorebodypart!"); + msg("error in getrandomcorebodypart!"); } return selbp; } @@ -6106,48 +6161,48 @@ int getsounddist(int volume) { } char *getspeedname(int speed, char *buf) { - sprintf(buf, "unknownspeed"); + snprintf(buf, BUFLEN, "unknownspeed"); if (speed <= SP_GODLIKE) { - sprintf(buf, "insanely fast"); + snprintf(buf, BUFLEN, "insanely fast"); } else if (speed <= SP_ULTRAFAST) { - sprintf(buf, "extremely fast"); + snprintf(buf, BUFLEN, "extremely fast"); } else if (speed <= SP_VERYFAST) { - sprintf(buf, "very fast"); + snprintf(buf, BUFLEN, "very fast"); } else if (speed <= SP_FAST) { - sprintf(buf, "fast"); + snprintf(buf, BUFLEN, "fast"); } else if (speed <= SP_NORMAL) { - sprintf(buf, "normal"); + snprintf(buf, BUFLEN, "normal"); } else if (speed <= SP_SLOW) { - sprintf(buf, "slow"); + snprintf(buf, BUFLEN, "slow"); } else if (speed <= SP_VERYSLOW) { - sprintf(buf, "very slow"); + snprintf(buf, BUFLEN, "very slow"); } else if (speed <= SP_ULTRASLOW) { - sprintf(buf, "extremely slow"); + snprintf(buf, BUFLEN, "extremely slow"); } else { - sprintf(buf, "insanely slow"); + snprintf(buf, BUFLEN, "insanely slow"); } return buf; } char *getspeednameshort(int speed, char *buf) { - sprintf(buf, "unknownspeed"); + snprintf(buf, BUFLEN, "unknownspeed"); if (speed <= SP_GODLIKE) { - sprintf(buf, "fast+++"); + snprintf(buf, BUFLEN, "fast+++"); } else if (speed <= SP_ULTRAFAST) { - sprintf(buf, "fast++"); + snprintf(buf, BUFLEN, "fast++"); } else if (speed <= SP_VERYFAST) { - sprintf(buf, "fast+"); + snprintf(buf, BUFLEN, "fast+"); } else if (speed <= SP_FAST) { - sprintf(buf, "fast"); + snprintf(buf, BUFLEN, "fast"); } else if (speed <= SP_NORMAL) { - sprintf(buf, "normal"); + snprintf(buf, BUFLEN, "normal"); } else if (speed <= SP_SLOW) { - sprintf(buf, "slow"); + snprintf(buf, BUFLEN, "slow"); } else if (speed <= SP_VERYSLOW) { - sprintf(buf, "slow+"); + snprintf(buf, BUFLEN, "slow+"); } else if (speed <= SP_ULTRASLOW) { - sprintf(buf, "slow++"); + snprintf(buf, BUFLEN, "slow++"); } else { - sprintf(buf, "slow+++"); + snprintf(buf, BUFLEN, "slow+++"); } return buf; } @@ -6704,6 +6759,8 @@ void giveobflags(lifeform_t *lf, object_t *o, enum FLAG whattype) { } else { lifetimeval = FROMOBACTIVATE; } + } else { + assert(1 == 0); } for (f = o->flags->first ; f ; f = f->next) { @@ -6955,7 +7012,7 @@ void givestartobs(lifeform_t *lf, object_t *targob, flagpile_t *fp) { } if (db) { - sprintf(buf2, "calling givestartobs for %s",lf->race->name); + snprintf(buf2, BUFLEN, "calling givestartobs for %s",lf->race->name); } // handle autoweapon @@ -6984,7 +7041,7 @@ void givestartobs(lifeform_t *lf, object_t *targob, flagpile_t *fp) { // note: we use getplayername here even if this isn't a player, // since in that case the prompt will never be displayed. getplayernamefull(buf2); - sprintf(buf, "%s, select your starting weapon:", buf2); + snprintf(buf, BUFLEN, "%s, select your starting weapon:", buf2); initprompt(&prompt, buf); for (i = 0; i < nposs; i++) { @@ -7097,29 +7154,29 @@ void givestartobs(lifeform_t *lf, object_t *targob, flagpile_t *fp) { } else if (id == F_STARTOBDT) { if (rnd(1,100) <= val[0]) { if (db) { - sprintf(buf2, "calling startobdt"); + snprintf(buf2, BUFLEN, "calling startobdt"); } if ( real_getrandomob(targmap, buf, RO_DAMTYPE, val[1], NA, NA, maxobsize)) { - if (db) sprintf(buf2, "finished startobdt successfuly."); + if (db) snprintf(buf2, BUFLEN, "finished startobdt successfuly."); o = addob(op, buf); } else { - if (db) sprintf(buf2, "finished startobdt, failed."); + if (db) snprintf(buf2, BUFLEN, "finished startobdt, failed."); } //assert(strlen(buf) > 0); } } else if (id == F_STARTOBCLASS) { if (rnd(1,100) <= val[0]) { if (db) { - sprintf(buf2, "calling startobclass"); + snprintf(buf2, BUFLEN, "calling startobclass"); } //obdb = B_TRUE; //if (getrandomobwithclass(targmap, val[1], buf, val[2])) { if (real_getrandomob(targmap, buf, RO_OBCLASS, val[1], getmapdifficulty(targmap) + val[2], NA, maxobsize)) { - if (db) sprintf(buf2, "finished startobclass, success."); + if (db) snprintf(buf2, BUFLEN, "finished startobclass, success."); o = addob(op, buf); } else { //obdb = B_FALSE; - if (db) sprintf(buf2, "finished startobclass. couldnt find an object."); + if (db) snprintf(buf2, BUFLEN, "finished startobclass. couldnt find an object."); } //if (strlen(buf) <= 0); } @@ -7231,11 +7288,16 @@ job_t *hasjob(lifeform_t *lf, enum JOB job) { return j; } +// where shoudl always be body, hands, legs or head +// damtype should be bash or slash int injure(lifeform_t *lf, enum BODYPART where, enum DAMTYPE damtype) { char lfname[BUFLEN]; + char *desc = NULL; + enum INJURY inj = IJ_NONE; + object_t *wep = NULL; if (where == BP_NONE) return B_TRUE; if (!hasbp(lf, where)) return B_TRUE; - if (lfhasflagval(lf, F_INJURY, where, damtype, NA, NULL)) return B_TRUE; + if (lfhasflagval(lf, F_INJURY, NA, where, NA, NULL)) return B_TRUE; // special cases for head... if (where == BP_HEAD) { @@ -7251,8 +7313,71 @@ int injure(lifeform_t *lf, enum BODYPART where, enum DAMTYPE damtype) { } } - addtempflag(lf->flags, F_INJURY, where, damtype, NA, NULL,rnd(5,30)); + if (damtype == DT_BASH) { + switch (where) { + case BP_BODY: inj = IJ_RIBCRACKED; desc = strdup("ribs are cracked^carrying capacity halved"); break; + case BP_HANDS: + switch (rnd(1,2)) { + case 1: + inj = IJ_FINGERBROKEN; desc = strdup("finger is broken^-10% accuracy"); break; + case 2: + inj = IJ_SHOULDERDISLOCATED; desc = strdup("shoulder is dislocated^-20% accuracy, cannot weild heavy weapons"); break; + } + break; + case BP_HEAD: + if (!eyesshaded(lf)) { + inj = IJ_BLACKEYE; + desc = strdup("eye is bruised^vision range halved"); + } + break; // maybe move this to an 'eye' injury? + case BP_LEGS: + if (onein(3)) { + inj = IJ_LEGBROKEN; + desc = strdup("leg is broken^movement speed greatly lowered"); break; + } else { + inj = IJ_LEGBRUISE; + desc = strdup("leg is bruised^movement speed lowered"); break; + } + default: break; + } + } else if (damtype == DT_SLASH) { + switch (where) { + case BP_BODY: inj = IJ_CHESTBLEED; desc = strdup("chest is bleeding^damage from enemies is increased"); break; + case BP_HANDS: + switch (rnd(1,2)) { + case 1: + inj = IJ_HANDBLEED; desc = strdup("hand is bleeding^attacking will cause damage"); break; + case 2: + inj = IJ_TENDONCUT; desc = strdup("right flexor tendon is cut^cannot weild weapons"); break; + } + break; + case BP_HEAD: break; // special case handled above + case BP_LEGS: inj = IJ_LEGBLEED; desc = strdup("leg is bleeding^movement will cause damage"); break; + default: break; + } + } + + if (inj == IJ_NONE) { + if (desc) free(desc); + return B_TRUE; + } else { + addtempflag(lf->flags, F_INJURY, inj, where, damtype, desc,rnd(5,30)); + } + if (desc) free(desc); + // special effects from taking injuries + switch (inj) { + case IJ_TENDONCUT: + wep = getweapon(lf); + if (wep) drop(wep, wep->amt); + break; + case IJ_SHOULDERDISLOCATED: + wep = getweapon(lf); + if (wep && isheavyweapon(wep)) drop(wep, wep->amt); + break; + default: + break; + } return B_FALSE; } @@ -8642,7 +8767,7 @@ void initrace(void) { addflag(lastrace->flags, F_STARTSKILL, SK_SS_LIFE, PR_MASTER, NA, NULL); addflag(lastrace->flags, F_STARTSKILL, SK_FIRSTAID, PR_SKILLED, NA, NULL); addflag(lastrace->flags, F_STARTSKILL, SK_SPELLCASTING, PR_SKILLED, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gestures imperiously"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gestures imperiously"); // god abilities addflag(lastrace->flags, F_GODOF, NA, NA, NA, "Purity"); addflag(lastrace->flags, F_FLEEONHPPCT, 10, NA, NA, NULL); @@ -8692,7 +8817,7 @@ void initrace(void) { addflag(lastrace->flags, F_STARTSKILL, SK_BACKSTAB, PR_MASTER, NA, NULL); addflag(lastrace->flags, F_STARTSKILL, SK_THROWING, PR_MASTER, NA, NULL); addflag(lastrace->flags, F_STARTSKILL, SK_CLIMBING, PR_MASTER, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "waves his hand"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "waves his hand"); // god abilities addflag(lastrace->flags, F_GODOF, NA, NA, NA, "Thieves"); addflag(lastrace->flags, F_FLEEONHPPCT, 10, NA, NA, NULL); @@ -8812,7 +8937,8 @@ void initrace(void) { addflag(lastrace->flags, F_CANWILL, OT_S_SUCK, NA, NA, "pw:2;"); addflag(lastrace->flags, F_CANWILL, OT_S_PARALYZE, NA, NA, "pw:2;"); addflag(lastrace->flags, F_HASATTACK, OT_TEETH, NA, NA, "2d4"); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gazes at you"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gazes"); + addflag(lastrace->flags, F_CASTTYPE, CT_GAZE, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SHOULDERS, NA, NA, NULL); @@ -8912,7 +9038,7 @@ void initrace(void) { addflag(lastrace->flags, F_CANWILL, OT_S_DARKNESS, 7, 7, "pw:3;"); addflag(lastrace->flags, F_CANWILL, OT_A_GRAB, NA, NA, NULL); addflag(lastrace->flags, F_CANWILL, OT_A_CRUSH, NA, NA, "dam:0d0+5;"); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "waves its tentacles"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "waves its tentacles"); addflag(lastrace->flags, F_HASATTACK, OT_TENTACLE, NA, NA, "2d6"); addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); @@ -8941,7 +9067,8 @@ void initrace(void) { addflag(lastrace->flags, F_MPREGEN, 12, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_DISPERSAL, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_GRAVBOOST, NA, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gazes at you"); + addflag(lastrace->flags, F_CASTTYPE, CT_GAZE, NA, NA, NULL); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gazes"); addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SHOULDERS, NA, NA, NULL); @@ -9421,7 +9548,7 @@ void initrace(void) { addflag(lastrace->flags, F_DTRESIST, DT_FIRE, B_TRUE, NA, NULL); addflag(lastrace->flags, F_SEEINDARK, 3, NA, NA, NULL); addflag(lastrace->flags, F_HUMANOID, B_TRUE, NA, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "spits"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "spits"); addflag(lastrace->flags, F_CANWILL, OT_S_POISONBOLT, 5, 5, "pw:5;"); addflag(lastrace->flags, F_HASSKILL, SK_PERCEPTION, PR_SKILLED, NA, NULL); @@ -9702,7 +9829,7 @@ void initrace(void) { addflag(lastrace->flags, F_MPDICE, 0, 4, NA, NULL); addflag(lastrace->flags, F_MPREGEN, 4, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_TELEKINESIS, NA, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gestures"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gestures"); addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SHOULDERS, NA, NA, NULL); @@ -9806,7 +9933,7 @@ void initrace(void) { addflag(lastrace->flags, F_MPDICE, 0, 4, NA, NULL); addflag(lastrace->flags, F_MPREGEN, 1, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_FIREDART, NA, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gestures"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gestures"); addflag(lastrace->flags, F_HASATTACK, OT_CLAWS, NA, NA, "1d3"); addflag(lastrace->flags, F_PRODUCESLIGHT, 2, NA, NA, NULL); addflag(lastrace->flags, F_DTIMMUNE, DT_FIRE, NA, NA, NULL); @@ -9833,7 +9960,7 @@ void initrace(void) { addflag(lastrace->flags, F_CANCAST, OT_S_FROSTBITE, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_FREEZEOB, NA, NA, NULL); addflag(lastrace->flags, F_CANCAST, OT_S_ICICLE, NA, NA, NULL); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "gestures"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "gestures"); addflag(lastrace->flags, F_HASATTACK, OT_CLAWS, NA, NA, "1d3"); addflag(lastrace->flags, F_DTIMMUNE, DT_COLD, NA, NA, NULL); addflag(lastrace->flags, F_HASSKILL, SK_SPELLCASTING, PR_NOVICE, NA, NULL); @@ -10559,7 +10686,7 @@ void initrace(void) { addflag(lastrace->flags, F_NOSPELLS, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_DTVULN, DT_COLD, NA, NA, NULL); addflag(lastrace->flags, F_DTIMMUNE, DT_POISON, NA, NA, NULL); - addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^hissing"); + addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^slithering"); addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); addrace(R_SNAKECARPET, "carpet snake", 3, 's', C_GREY, MT_FLESH, RC_ANIMAL); @@ -10580,7 +10707,7 @@ void initrace(void) { addflag(lastrace->flags, F_NOPACK, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_NOSPELLS, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_DTVULN, DT_COLD, NA, NA, NULL); - addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^hissing"); + addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^slithering"); addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); addrace(R_SNAKETREE, "tree snake", 3, 's', C_GREEN, MT_FLESH, RC_ANIMAL); @@ -10606,7 +10733,7 @@ void initrace(void) { addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_CANWILL, OT_A_CHARGE, 2, 2, NULL); addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); - addrace(R_SNAKECOBRA, "giant cobra", 3, 's', C_BLUE, MT_FLESH, RC_ANIMAL); + addrace(R_SNAKECOBRABLACK, "black cobra", 3, 's', C_BLUE, MT_FLESH, RC_ANIMAL); addflag(lastrace->flags, F_RARITY, H_DUNGEON, 78, NA, ""); addflag(lastrace->flags, F_RARITY, H_FOREST, 78, NA, ""); addflag(lastrace->flags, F_COLDBLOOD, B_TRUE, NA, NA, NULL); @@ -10626,10 +10753,36 @@ void initrace(void) { addflag(lastrace->flags, F_NOSPELLS, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_DTVULN, DT_COLD, NA, NA, NULL); addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^hissing"); - addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "spits"); + addflag(lastrace->flags, F_CANWILL, OT_S_POISONBOLT, 4, 4, "pw:3;"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "spits"); addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_DTIMMUNE, DT_POISON, NA, NA, NULL); - addflag(lastrace->flags, F_CANWILL, OT_S_POISONBOLT, 4, 4, "pw:3;"); + addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); + addrace(R_SNAKECOBRAGOLDEN, "golden cobra", 3, 's', C_YELLOW, MT_FLESH, RC_ANIMAL); + addflag(lastrace->flags, F_RARITY, H_DUNGEON, 76, NA, ""); + addflag(lastrace->flags, F_RARITY, H_FOREST, 79, NA, ""); + addflag(lastrace->flags, F_COLDBLOOD, B_TRUE, NA, NA, NULL); + addflag(lastrace->flags, F_HOSTILE, B_TRUE, NA, NA, NULL); + addflag(lastrace->flags, F_STARTATT, A_IQ, IQ_ANIMAL, NA, NULL); + addflag(lastrace->flags, F_ACTIONSPEED, SP_NORMAL, NA, NA, ""); + addflag(lastrace->flags, F_SIZE, SZ_SMALL, NA, NA, NULL); + addflag(lastrace->flags, F_MOVESPEED, SP_NORMAL, NA, NA, ""); + addflag(lastrace->flags, F_HITDICE, 2, 2, NA, ""); + addflag(lastrace->flags, F_HASATTACK, OT_TEETH, NA, NA, "1d3+1"); + addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); + addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); + addflag(lastrace->flags, F_NOBODYPART, BP_SHOULDERS, NA, NA, NULL); + addflag(lastrace->flags, F_NOBODYPART, BP_HANDS, NA, NA, NULL); + addflag(lastrace->flags, F_NOBODYPART, BP_FEET, NA, NA, NULL); + addflag(lastrace->flags, F_NOPACK, B_TRUE, NA, NA, NULL); + addflag(lastrace->flags, F_NOSPELLS, B_TRUE, NA, NA, NULL); + addflag(lastrace->flags, F_DTVULN, DT_COLD, NA, NA, NULL); + addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^hissing"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, B_APPENDYOU, "spits"); + addflag(lastrace->flags, F_CASTTYPE, CT_EYESPIT, NA, NA, NULL); + addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); + addflag(lastrace->flags, F_DTIMMUNE, DT_POISON, NA, NA, NULL); + addflag(lastrace->flags, F_CANWILL, OT_S_BLINDNESS, 4, 4, "pw:3;range:2;"); addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); addrace(R_SNAKECONSTRICTOR, "constrictor", 3, 's', C_MAGENTA, MT_FLESH, RC_ANIMAL); addflag(lastrace->flags, F_RARITY, H_DUNGEON, 68, NA, ""); @@ -10678,7 +10831,7 @@ void initrace(void) { addflag(lastrace->flags, F_NOSPELLS, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_DTVULN, DT_COLD, NA, NA, NULL); addflag(lastrace->flags, F_DTIMMUNE, DT_POISON, NA, NA, NULL); - addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^hissing"); + addflag(lastrace->flags, F_NOISETEXT, N_WALK, 1, NA, "^slithering"); addflag(lastrace->flags, F_DEAF, B_TRUE, NA, NA, NULL); addflag(lastrace->flags, F_TREMORSENSE, 10, NA, NA, NULL); addrace(R_SPIDER, "giant spider", 5, 'S', C_GREY, MT_FLESH, RC_ANIMAL); @@ -10934,6 +11087,8 @@ void initrace(void) { addflag(lastrace->flags, F_HITDICE, 1, 0, NA, ""); addflag(lastrace->flags, F_EVASION, 60, NA, NA, NULL); addflag(lastrace->flags, F_HASATTACK, OT_ZAPPER, NA, NA, "1d2-1"); + addflag(lastrace->flags, F_CANWILL, OT_S_FLASH, 15, 15, "pw:4;"); + addflag(lastrace->flags, F_SPELLCASTTEXT, NA, NA, NA, "pulses"); addflag(lastrace->flags, F_NOBODYPART, BP_WEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SECWEAPON, NA, NA, NULL); addflag(lastrace->flags, F_NOBODYPART, BP_SHOULDERS, NA, NA, NULL); @@ -11250,7 +11405,7 @@ int isbleeding(lifeform_t *lf) { if (hppct <= 40) return B_TRUE; - if (lfhasflagval(lf, F_INJURY, NA, DT_SLASH, NA, NULL)) { + if (lfhasflagval(lf, F_INJURY, NA, NA, DT_SLASH, NULL)) { return B_TRUE; } return B_FALSE; @@ -11959,7 +12114,7 @@ void addtrail(lifeform_t *lf, int dir) { fpflag->val[1] = fpdir; } else { char buf[BUFLENTINY]; - sprintf(buf, "%d", lf->id); + snprintf(buf, BUFLENTINY, "%d", lf->id); footprint = addobfast(lf->cell->obpile, OT_FOOTPRINT); addtempflag(footprint->flags, F_TRAIL, lf->race->id, fpdir, S_SIGHT, buf, getfootprinttime(lf)); } @@ -11972,7 +12127,7 @@ void addtrail(lifeform_t *lf, int dir) { fpflag->lifetime = TM_SCENT; } else { char buf[BUFLENTINY]; - sprintf(buf, "%d", lf->id); + snprintf(buf, BUFLENTINY, "%d", lf->id); scent = addobfast(lf->cell->obpile, OT_SCENT); addtempflag(scent->flags, F_TRAIL, lf->race->id, dir, S_SMELL, buf, TM_SCENT); } @@ -12243,7 +12398,7 @@ void applywalkdam(lifeform_t *lf, int dam, enum DAMTYPE damtype, object_t *o) { fromlfflag = hasflag(o->flags, F_CREATEDBY); if (fromlfflag) { - sprintf(damstring, "%s^created by %s",buf, fromlfflag->text); + snprintf(damstring, BUFLEN, "%s^created by %s",buf, fromlfflag->text); } else { strcpy(damstring, buf); } @@ -12263,7 +12418,7 @@ void applywalkdam(lifeform_t *lf, int dam, enum DAMTYPE damtype, object_t *o) { char lfname[BUFLEN]; char buf2[BUFLEN]; getlfname(lf, lfname); - sprintf(buf2, "^%c%s %ss %s!", getlfcol(lf, CC_BAD), buf, getattackverb(NULL, NULL, damtype, dam,lf->maxhp), lfname); + snprintf(buf2, BUFLEN, "^%c%s %ss %s!", getlfcol(lf, CC_BAD), buf, getattackverb(NULL, NULL, damtype, dam,lf->maxhp), lfname); msg("%s", buf2); } } @@ -12310,9 +12465,9 @@ int askforpayment(lifeform_t *shk, lifeform_t *lf) { totcost = getowing(lf, shopid, &nitems); if (nitems == 1) { - sprintf(saybuf, "That will cost you $%d.", totcost); + snprintf(saybuf, BUFLEN, "That will cost you $%d.", totcost); } else { - sprintf(saybuf, "That brings your bill to $%d.", totcost); + snprintf(saybuf, BUFLEN, "That brings your bill to $%d.", totcost); } say(shk, saybuf, SV_TALK); return B_FALSE; @@ -12841,9 +12996,11 @@ int losehp_real(lifeform_t *lf, int amt, enum DAMTYPE damtype, lifeform_t *froml getflags(lf->flags, retflag, &nretflags, F_INJURY, F_NONE); for (i = 0; i < nretflags; i++) { f = retflag[i]; - if ((f->val[1] == DT_BASH) && (f->lifetime > 0)) { - f->lifetime -= 5; - limit(&f->lifetime, 1, NA); + if (f->lifetime > 0) { + if ((f->val[0] == IJ_LEGBRUISE) || (f->val[0] == IJ_BLACKEYE)) { + f->lifetime -= 5; + limit(&f->lifetime, 1, NA); + } } } } else if (damtype == DT_FIRE) { @@ -12872,14 +13029,14 @@ int losehp_real(lifeform_t *lf, int amt, enum DAMTYPE damtype, lifeform_t *froml // replace 'the' at start of damsrc with 'a' if (strstr(damsrc, "the ") == damsrc) { - sprintf(buf, "a %s", (damsrc+4)); + snprintf(buf, BUFLEN, "a %s", (damsrc+4)); } else { strcpy(buf, damsrc); } // fill in damage amount - sprintf(buf2, "^%d damage",amt); + snprintf(buf2, BUFLEN, "^%d damage",amt); strcat(buf, buf2); setlastdam(lf, buf); @@ -13036,7 +13193,7 @@ int makenauseated(lifeform_t *lf, int amt, int howlong) { void makenoise(lifeform_t *lf, enum NOISETYPE nid) { flag_t *f; char *verb = NULL, *noun = NULL; - int volume; + int volume = 1; if (lfhasflag(lf, F_FROZEN)) { // can't make noise if frozen! @@ -13058,7 +13215,7 @@ void makenoise(lifeform_t *lf, enum NOISETYPE nid) { noun = strtok_r(NULL, "^", &dummy); } - sprintf(noisetext, "%s.",noun); + snprintf(noisetext, BUFLEN, "%s.",noun); if (nid == N_WALK) { volume += getarmournoise(lf); } @@ -13418,13 +13575,13 @@ int noise(cell_t *c, lifeform_t *noisemaker, enum NOISECLASS nt, int volume, cha difficulty = 0; } else { //difficulty = (int) ( ((float)getcelldist(l->cell, c) / (float)gethearingrange(l)) * 20); - difficulty = (int) ( ((float)getcelldist(l->cell, c) / ((float)gethearingrange(l) + volume)) * 20); + difficulty = (int) ( ((float)getcelldist(l->cell, c) / ((float)gethearingrange(l) + volume)) * 14); } - // listen bonus is the sound volume + // listen bonus is based on sound volume lbonus = volume; if (lfhasflag(l, F_ASLEEP)) { - lbonus -= 5; + lbonus -= 4; limit(&lbonus, 0, NA); } @@ -13925,7 +14082,7 @@ void precalclos_new(lifeform_t *lf) { for (ix = start; ix < end; ix++) { c = getcellat(lf->cell->map, ix, iy); if (c) { - if (db) dblog("N:endcell[%d] = %d,%d",nn,c->x, c->y); + if (db) dblog("N:endcell[%d] = %d,%d",nendcells,c->x, c->y); endcell[nendcells++] = c; } assert(nendcells < MAXVISLIMIT); @@ -13941,7 +14098,7 @@ void precalclos_new(lifeform_t *lf) { for (iy = start; iy < end; iy++) { c = getcellat(lf->cell->map, ix, iy); if (c) { - if (db) dblog("E:endcell[%d] = %d,%d",nn,c->x, c->y); + if (db) dblog("E:endcell[%d] = %d,%d",nendcells,c->x, c->y); endcell[nendcells++] = c; } assert(nendcells < MAXVISLIMIT); @@ -13957,7 +14114,7 @@ void precalclos_new(lifeform_t *lf) { for (ix = start; ix > end; ix--) { c = getcellat(lf->cell->map, ix, iy); if (c) { - if (db) dblog("S:endcell[%d] = %d,%d",nn,c->x, c->y); + if (db) dblog("S:endcell[%d] = %d,%d",nendcells,c->x, c->y); endcell[nendcells++] = c; } assert(nendcells < MAXVISLIMIT); @@ -13973,7 +14130,7 @@ void precalclos_new(lifeform_t *lf) { for (iy = start; iy > end; iy--) { c = getcellat(lf->cell->map, ix, iy); if (c) { - if (db) dblog("W:endcell[%d] = %d,%d",nn,c->x, c->y); + if (db) dblog("W:endcell[%d] = %d,%d",nendcells,c->x, c->y); endcell[nendcells++] = c; } assert(nendcells < MAXVISLIMIT); @@ -14162,7 +14319,7 @@ int recruit(lifeform_t *lf) { if (askingprice > countmoney(player)) { } else { char ch; - sprintf(buf, "Pay $%d to hire %s", askingprice, lfname); + snprintf(buf, BUFLEN, "Pay $%d to hire %s", askingprice, lfname); ch = askchar(buf, "yn","n", B_TRUE); if (ch == 'y') { dohire = B_TRUE; @@ -14433,8 +14590,8 @@ int say(lifeform_t *lf, char *text, int volume) { strcpy(noun, "a bellow:"); } - sprintf(seebuf, "%s \"%s\"", verb, text); - sprintf(hearbuf, "%s \"%s\"", noun, text); + snprintf(seebuf, BUFLEN, "%s \"%s\"", verb, text); + snprintf(hearbuf, BUFLEN, "%s \"%s\"", noun, text); return noise(lf->cell, lf, NC_SPEECH, volume, hearbuf, seebuf); } @@ -14446,25 +14603,25 @@ int sayphrase(lifeform_t *lf, enum SAYPHRASE what, int volume, int val0, char *t switch (what) { case SP_BEG: switch (rnd(1,3)) { - case 1: sprintf(buf, "Spare a coin, mister?"); break; - case 2: sprintf(buf, "Alms for the poor!"); break; - case 3: sprintf(buf, "Alms!"); break; + case 1: snprintf(buf, BUFLEN, "Spare a coin, mister?"); break; + case 2: snprintf(buf, BUFLEN, "Alms for the poor!"); break; + case 3: snprintf(buf, BUFLEN, "Alms!"); break; } rv = say(lf, buf, volume); break; case SP_BEGATTACK: switch (rnd(1,3)) { - case 1: sprintf(buf, "Now give me the everything else!"); break; - case 2: sprintf(buf, "Rich fool!"); break; - case 3: sprintf(buf, "Is that all?"); break; + case 1: snprintf(buf, BUFLEN, "Now give me the everything else!"); break; + case 2: snprintf(buf, BUFLEN, "Rich fool!"); break; + case 3: snprintf(buf, BUFLEN, "Is that all?"); break; } rv = say(lf, buf, volume); break; case SP_BEGTHANKS: switch (rnd(1,3)) { - case 1: sprintf(buf, "A thousand thanks, good sir!"); break; - case 2: sprintf(buf, "Oh thank you!"); break; - case 3: sprintf(buf, "My family shall eat tonight!"); break; + case 1: snprintf(buf, BUFLEN, "A thousand thanks, good sir!"); break; + case 2: snprintf(buf, BUFLEN, "Oh thank you!"); break; + case 3: snprintf(buf, BUFLEN, "My family shall eat tonight!"); break; } rv = say(lf, buf, volume); break; @@ -14490,9 +14647,9 @@ int sayphrase(lifeform_t *lf, enum SAYPHRASE what, int volume, int val0, char *t break; case SP_PAYWARN: switch (rnd(1,3)) { - case 1: sprintf(buf, "Hey! Where do you think you're going?"); break; - case 2: sprintf(buf, "AHEM!"); break; - case 3: sprintf(buf, "I hope you are going to pay for %s!", text); break; + case 1: snprintf(buf, BUFLEN, "Hey! Where do you think you're going?"); break; + case 2: snprintf(buf, BUFLEN, "AHEM!"); break; + case 3: snprintf(buf, BUFLEN, "I hope you are going to pay for %s!", text); break; } rv = say(lf, buf, volume); break; @@ -14505,30 +14662,30 @@ int sayphrase(lifeform_t *lf, enum SAYPHRASE what, int volume, int val0, char *t break; case SP_PAYTHANKS: switch (rnd(1,3)) { - case 1: sprintf(buf, "Pleasure doing business with you!"); break; - case 2: sprintf(buf, "Thank you, come again!"); break; - case 3: sprintf(buf, "Another satisfied customer!"); break; + case 1: snprintf(buf, BUFLEN, "Pleasure doing business with you!"); break; + case 2: snprintf(buf, BUFLEN, "Thank you, come again!"); break; + case 3: snprintf(buf, BUFLEN, "Another satisfied customer!"); break; } rv = say(lf, buf, volume); break; case SP_RECRUIT_ACCEPT: if (lf->race->id == R_PRISONER) { if (text) { - sprintf(buf, "Thank you! My name is %s.", text); + snprintf(buf, BUFLEN, "Thank you! My name is %s.", text); } else { - sprintf(buf, "Thank you!"); + snprintf(buf, BUFLEN, "Thank you!"); } } else { if (text) { - sprintf(buf, "I will join you - my name is %s.", text); + snprintf(buf, BUFLEN, "I will join you - my name is %s.", text); } else { - sprintf(buf, "I will join you."); + snprintf(buf, BUFLEN, "I will join you."); } } rv = say(lf, buf, volume); break; case SP_RECRUIT_ASKPRICE: - sprintf(buf, "My services will cost you $%d.",val0); + snprintf(buf, BUFLEN, "My services will cost you $%d.",val0); rv = say(lf, buf, volume); break; case SP_RECRUIT_DECLINE: @@ -14705,7 +14862,7 @@ void setrace(lifeform_t *lf, enum RACE rid, int frompolymorph) { } if (frompolymorph && (gamemode == GM_GAMESTARTED) && lf->race) { - race_t *origrace; + race_t *origrace = NULL; // remove 'become a ghost' flag killflagsofid(lf->flags, F_RISEASGHOST); @@ -15190,15 +15347,15 @@ void initskills(void) { } if (rc) { char buf[BUFLEN]; - sprintf(buf, "^gYou now know basic information about %s.", rc->pluralname); + snprintf(buf, BUFLEN, "^gYou now know basic information about %s.", rc->pluralname); addskilldesc(sk->id, PR_NOVICE, buf, B_TRUE); - sprintf(buf, "^gYou can now determine how much damage %s will deal.", rc->pluralname); + snprintf(buf, BUFLEN, "^gYou can now determine how much damage %s will deal.", rc->pluralname); addskilldesc(sk->id, PR_BEGINNER, buf, B_TRUE); - sprintf(buf, "^gYou can now determine how dangerous %s are.", rc->pluralname); + snprintf(buf, BUFLEN, "^gYou can now determine how dangerous %s are.", rc->pluralname); addskilldesc(sk->id, PR_ADEPT, buf, B_TRUE); - sprintf(buf, "^gYou can now anticipate how %s will react.", rc->pluralname); + snprintf(buf, BUFLEN, "^gYou can now anticipate how %s will react.", rc->pluralname); addskilldesc(sk->id, PR_SKILLED, buf, B_TRUE); - sprintf(buf, "^gYou now know everything there is to know about %s.", rc->pluralname); + snprintf(buf, BUFLEN, "^gYou now know everything there is to know about %s.", rc->pluralname); addskilldesc(sk->id, PR_MASTER, buf, B_TRUE); } } @@ -15320,9 +15477,9 @@ int real_skillcheck(lifeform_t *lf, enum CHECKTYPE ct, int diff, int mod, int *r flag_t *f; if (lfhasflag(lf, F_DEBUG)) { - if (ct != SC_STEALTH) { // dont show debug info for stealth checks + //if (ct != SC_STEALTH) { // dont show debug info for stealth checks db = B_TRUE; - } + //} } switch (ct) { @@ -15341,6 +15498,9 @@ int real_skillcheck(lifeform_t *lf, enum CHECKTYPE ct, int diff, int mod, int *r case SC_CHA: // if you're bleeding you're less attractive! attrib = pctof(gethppct(lf), getattr(lf, A_CHA)); + if (lfhasflagval(lf, F_INJURY, IJ_BLACKEYE, NA, NA, NULL)) { + attrib -= 3; + } break; case SC_WIS: attrib = getattr(lf, A_WIS); @@ -15408,6 +15568,12 @@ int real_skillcheck(lifeform_t *lf, enum CHECKTYPE ct, int diff, int mod, int *r case SC_STEALTH: attrib = (getskill(lf, SK_STEALTH)*3); break; + default: + // invalid checktype + dblog("warning: invalid checktype %d", (int)ct); + msg("warning: invalid checktype %d", (int)ct); + attrib = 0; + break; } // level modifier @@ -15498,7 +15664,7 @@ int real_skillcheck(lifeform_t *lf, enum CHECKTYPE ct, int diff, int mod, int *r roll = rolldie(1, 20); if (db) { - sprintf(mbuf, "%s skillcheck (%d) - need %d, got %d(rll)+%d(attr)+%d(lvm)+%d(othmod)+%d(mod)=",lf->race->name, + snprintf(mbuf, BUFLEN, "%s skillcheck (%d) - need %d, got %d(rll)+%d(attr)+%d(lvm)+%d(othmod)+%d(mod)=",lf->race->name, ct, diff, roll, attrib,levmod, othermod,mod); } modroll = roll; @@ -15601,7 +15767,7 @@ int slipon(lifeform_t *lf, object_t *o) { char damstring[BUFLEN]; msg("%s slip%s on %s and fall%s to the ground.",lfname, isplayer(lf) ? "" : "s", obname, isplayer(lf) ? "" : "s"); - sprintf(damstring, "slipping on %s",obname); + snprintf(damstring, BUFLEN, "slipping on %s",obname); losehp(lf, 1, DT_FALL, NULL, damstring); } @@ -15722,7 +15888,7 @@ int steal(lifeform_t *lf, obpile_t *op, enum FLAG wantflag) { // what do we steal? for (i = 0; i < nsteals; i++) { char buf[BUFLEN]; - sprintf(buf, "Steal what (%d of %d)?", i+1, nsteals); + snprintf(buf, BUFLEN, "Steal what (%d of %d)?", i+1, nsteals); initprompt(&prompt, buf); for (o = op->first ; o ; o = o->next) { int ok = B_TRUE; @@ -15811,7 +15977,7 @@ int stone(lifeform_t *lf) { getlfname(lf, lfname); - sprintf(statname, "statue of a %s", lf->race->name); + snprintf(statname, BUFLEN, "statue of a %s", lf->race->name); addob(lf->cell->obpile, statname); // kill lifeform @@ -16471,7 +16637,7 @@ void turneffectslf(lifeform_t *lf) { power = lf->level / 3; if (power < 1) power = 1; if (power > 10) power = 10; - sprintf(pwbuf, "pw:%d;",power); + snprintf(pwbuf, BUFLEN, "pw:%d;",power); f = addflag(lf->flags, F_CANWILL, OT_S_POSSESSION, NA, NA, pwbuf); f->lifetime = FROMRACE; } @@ -16673,7 +16839,7 @@ void turneffectslf(lifeform_t *lf) { taketime(lf, getactspeed(lf)); } - sprintf(buf, "poisoning^from %s",f->text); + snprintf(buf, BUFLEN, "poisoning^from %s",f->text); losehp(lf, f->val[1], DT_DIRECT, NULL, buf); if (!asleep) { @@ -16984,7 +17150,7 @@ int touch(lifeform_t *lf, object_t *o) { } // use real name here... real_getobname(o, obname, o->amt, B_TRUE, B_FALSE, B_FALSE, B_TRUE, B_FALSE); - sprintf(buf, "touching %s",obname); + snprintf(buf, BUFLEN, "touching %s",obname); losehp(lf, 2, DT_HOLY, NULL, buf); // drop the object if we're holding it if (o->pile->owner == lf) { @@ -17004,7 +17170,7 @@ int touch(lifeform_t *lf, object_t *o) { msg("^bOw! You cut your finger on %s.", obname); } - sprintf(buf, "touching %s", obname); + snprintf(buf, BUFLEN, "touching %s", obname); losehp(lf, rnd(1,2), DT_SLASH, NULL, buf); } } @@ -17030,7 +17196,7 @@ int touch(lifeform_t *lf, object_t *o) { } else if (cansee(player, lf)) { msg("%s burns itself on %s.",lfname, obname); } - sprintf(buf, "touching %s",obname); + snprintf(buf, BUFLEN, "touching %s",obname); losehp(lf, 2, DT_FIRE, NULL, buf); return B_TRUE; } @@ -17176,7 +17342,7 @@ int usestairs(lifeform_t *lf, object_t *o, int onpurpose) { cell_t *obcell; cell_t *newcell; int dir; - int newdepth; + int newdepth = 0; // should always be replaced char lfname[BUFLEN]; char obname[BUFLEN]; int isportal = B_FALSE; @@ -17243,7 +17409,7 @@ int usestairs(lifeform_t *lf, object_t *o, int onpurpose) { // ok. } else { char buf[BUFLEN]; - sprintf(buf, "the %s", noprefix(obname)); + snprintf(buf, BUFLEN, "the %s", noprefix(obname)); if (tryclimb(lf, obcell, buf)) { // failed return B_TRUE; @@ -17420,6 +17586,8 @@ int usestairs(lifeform_t *lf, object_t *o, int onpurpose) { // take fall damage. 2d6 per level. losehp(lf, rolldie(howfar*2, 6), DT_FALL, NULL, "falling"); killflagsofid(lf->flags, F_FALLDISTANCE); + // injure legs + injure(lf, BP_LEGS, DT_BASH); // fall over fall(lf, NULL, B_FALSE); } @@ -17798,10 +17966,10 @@ int rest(lifeform_t *lf, int onpurpose) { } } else if (resting) { // just asleep/resting - wantclearmsg = B_FALSE; flag_t *hf; int fullpartyrest = B_FALSE; + wantclearmsg = B_FALSE; // resting if (lf->hp >= lf->maxhp) { hf = lfhasflag(lf, F_RESTUNTILHP); @@ -17966,7 +18134,7 @@ int wear(lifeform_t *lf, object_t *o) { msg("You cannot remove your %s.", noprefix(buf)); } else { // take offending item off first - this takes extra time. - sprintf(buf2, "Remove your %s",noprefix(buf)); + snprintf(buf2, BUFLEN, "Remove your %s",noprefix(buf)); ch = askchar(buf2, "yn","y", B_TRUE); if (ch == 'y') { if (isarmour(inway)) { @@ -18122,7 +18290,7 @@ int weild(lifeform_t *lf, object_t *o) { if (o) { getobname(o, buf, o->amt); } else { - sprintf(buf, "nothing"); + snprintf(buf, BUFLEN, "nothing"); } if (!canweild(lf, o)) { @@ -18159,6 +18327,9 @@ int weild(lifeform_t *lf, object_t *o) { case E_LOWWIS: msg("You are not wise enough to use this weapon."); break; + case E_INJURED: + msg("Your injuries prevent you from using this weapon."); + break; default: msg("For some reason, you weild this!"); break; @@ -18198,7 +18369,7 @@ int weild(lifeform_t *lf, object_t *o) { if (getskill(lf, SK_TWOWEAPON) && oo && !hasflag(oo->flags, F_TWOHANDED)) { char buf2[BUFLEN]; char ch; - sprintf(buf2, "Weild %s in your left hand?",buf); + snprintf(buf2, BUFLEN, "Weild %s in your left hand?",buf); ch = askchar(buf2, "yn","y", B_TRUE); if (ch == 'y') { enum BODYPART temp; @@ -18225,7 +18396,7 @@ int weild(lifeform_t *lf, object_t *o) { } else { getobname(oo, inwayname, oo->amt); // prompt before taking it off. - sprintf(buf2, "Remove your %s",noprefix(inwayname)); + snprintf(buf2, BUFLEN, "Remove your %s",noprefix(inwayname)); ch = askchar(buf2, "yn","y", B_TRUE); } } else { @@ -18289,7 +18460,7 @@ int weild(lifeform_t *lf, object_t *o) { } else { // prompt before taking it off. getobname(oo, inwayname, oo->amt); - sprintf(buf2, "Remove your %s",noprefix(inwayname)); + snprintf(buf2, BUFLEN, "Remove your %s",noprefix(inwayname)); ch = askchar(buf2, "yn","y", B_TRUE); } } else { @@ -18344,7 +18515,7 @@ int weild(lifeform_t *lf, object_t *o) { if (isplayer(lf)) { char buf2[BUFLEN]; - sprintf(buf2, "You are now weilding %c - %s", o->letter, buf); + snprintf(buf2, BUFLEN, "You are now weilding %c - %s", o->letter, buf); if (twohanded) { strcat(buf2, " (both hands)"); } else if (weildloc == BP_SECWEAPON) { diff --git a/lf.h b/lf.h index 6b0874d..78309b6 100644 --- a/lf.h +++ b/lf.h @@ -103,7 +103,7 @@ int getarmourrating(lifeform_t *lf, object_t **hitob, int *hitchance, int *narms int getattackspeed(lifeform_t *lf); int getattpoints(lifeform_t *lf); int getattr(lifeform_t *lf, enum ATTRIB attr); -enum ATTRBRACKET getattrbracket(int attrval, enum ATTRIB whichatt, char *buf); +enum ATTRBRACKET getattrbracket(int attrval, enum ATTRIB whichatt, /*@null@*/char *buf); int real_getattr(lifeform_t *lf, enum ATTRIB attr, int ignoreattrset); int getavgdam(lifeform_t *lf, int forxp); float getequippedweight(lifeform_t *lf); @@ -213,9 +213,9 @@ job_t *hasjob(lifeform_t *lf, enum JOB job); int injure(lifeform_t *lf, enum BODYPART where, enum DAMTYPE damtype); int lfcanbestoned(lifeform_t *lf); flag_t *lfhasflag(lifeform_t *lf, enum FLAG fid); -flag_t *lfhasflagval(lifeform_t *lf, enum FLAG fid, int val0, int val1, int val2, char *text); +flag_t *lfhasflagval(lifeform_t *lf, enum FLAG fid, int val0, int val1, int val2, /*@null@*/ char *text); flag_t *lfhasknownflag(lifeform_t *lf, enum FLAG fid); -flag_t *lfhasknownflagval(lifeform_t *lf, enum FLAG fid, int val0, int val1, int val2, char *text); +flag_t *lfhasknownflagval(lifeform_t *lf, enum FLAG fid, int val0, int val1, int val2, /*@null@*/ char *text); int lfproduceslight(lifeform_t *lf); int lockpick(lifeform_t *lf, object_t *target, object_t *device); void loseobflags(lifeform_t *lf, object_t *o, int kind); diff --git a/map.c b/map.c index 373db7f..cfcf835 100644 --- a/map.c +++ b/map.c @@ -198,7 +198,7 @@ lifeform_t *addmonster(cell_t *c, enum RACE rid, char *racename, int jobok, int if (db) { char buf[BUFLEN]; - sprintf(buf, "addmonster for '%s'->%s",racename, r->name); + snprintf(buf, BUFLEN, "addmonster for '%s'->%s",racename, r->name); dbtimestart(buf); } @@ -2286,7 +2286,7 @@ void createmap(map_t *map, int depth, region_t *region, map_t *parentmap, int ex // we now have the map name! getregionname(buf2, map, B_TRUE); - sprintf(buf, "%s (id #%d)",buf2, map->id); + snprintf(buf, BUFLEN, "%s (id #%d)",buf2, map->id); map->name = strdup(buf); // get a list of what things are here based on the region's outline @@ -2971,7 +2971,7 @@ int linkexits(map_t *m, int roomid) { vault_t *v; c = getrandomroomcell(m, roomid); v = getcellvault(c); - sprintf(buf, "*** linkexits for roomid %d (%s) [%d,%d-%d,%d]", roomid, + snprintf(buf, BUFLEN, "*** linkexits for roomid %d (%s) [%d,%d-%d,%d]", roomid, v ? v->id : "novault", minx,miny,maxx,maxy); dblog("%s", buf); @@ -3244,9 +3244,9 @@ void dumpoutlines(void) { char loctext[BUFLEN]; rt = &r->outline->thing[i]; if (rt->depth == NA) { - sprintf(loctext, "%d,%d",rt->x, rt->y); + snprintf(loctext, BUFLEN, "%d,%d",rt->x, rt->y); } else { - sprintf(loctext, "depth %d",rt->depth); + snprintf(loctext, BUFLEN, "depth %d",rt->depth); } if (rt->whatkind == RT_REGIONLINK) { regiontype_t *rtype; @@ -3330,9 +3330,9 @@ void explodesinglecell(cell_t *c, int dam, int killwalls, object_t *o, cell_t *c char buf[BUFLEN]; if (o) { getobname(o, obname, 1); - sprintf(buf, "an exploding %s",strchr(obname, ' ')+1); + snprintf(buf, BUFLEN, "an exploding %s",strchr(obname, ' ')+1); } else { - sprintf(buf, "an explosion"); + snprintf(buf, BUFLEN, "an explosion"); } // take damage @@ -3439,6 +3439,10 @@ cell_t *findmapentrypoint(map_t *m, int side, lifeform_t *lf) { yinc = 1; bestcell = getcellat(m, 0, lf->cell->y); break; + default: + dblog("error: invalid side given to mapentrypoint."); + msg("error: invalid side given to mapentrypoint."); + return NULL; } for (;(x < m->w) && (y < m->h);) { @@ -3783,16 +3787,16 @@ char *getregionname(char *buf, map_t *m, int withlevel) { } switch (r->rtype->id) { case RG_WORLDMAP: - sprintf(buf, "the surface(%d,%d)",x,y); + snprintf(buf, BUFLEN, "the surface(%d,%d)",x,y); break; case RG_FIRSTDUNGEON: - sprintf(buf, "dungeon L%d", m->depth); + snprintf(buf, BUFLEN, "dungeon L%d", m->depth); break; case RG_HEAVEN: - sprintf(buf, "the realm of gods"); + snprintf(buf, BUFLEN, "the realm of gods"); break; case RG_PIT: - sprintf(buf, "a pit L%d", m->depth); + snprintf(buf, BUFLEN, "a pit L%d", m->depth); break; default: strcpy(buf, "?unknownregiontype??"); @@ -3807,10 +3811,10 @@ char *getregionname(char *buf, map_t *m, int withlevel) { strcpy(buf, "a dungeon"); break; case RG_HEAVEN: - sprintf(buf, "the realm of gods"); + snprintf(buf, BUFLEN, "the realm of gods"); break; case RG_PIT: - sprintf(buf, "a pit"); + snprintf(buf, BUFLEN, "a pit"); break; default: strcpy(buf, "?unknownregiontype??"); @@ -4263,7 +4267,7 @@ int isinscanrange(cell_t *c, void **thing, char *desc, glyph_t *glyph) { if (desc) { char *p; p = getsizetext(getlfsize(c->lf)); - sprintf(desc, "%s %s monster", isvowel(*p) ? "an" : "a", p); + snprintf(desc, BUFLEN, "%s %s monster", isvowel(*p) ? "an" : "a", p); } if (glyph) { // select glyph based on size @@ -4284,7 +4288,7 @@ int isinscanrange(cell_t *c, void **thing, char *desc, glyph_t *glyph) { glyph->ch = '*'; glyph->colour = C_GREY; } - if (desc) sprintf(desc, "something metallic"); + if (desc) snprintf(desc, BUFLEN, "something metallic"); return TT_MONSTER; } else { object_t *o; @@ -4295,7 +4299,7 @@ int isinscanrange(cell_t *c, void **thing, char *desc, glyph_t *glyph) { glyph->ch = '*'; glyph->colour = C_GREY; } - if (desc) sprintf(desc, "something metallic"); + if (desc) snprintf(desc, BUFLEN, "something metallic"); return TT_OBJECT; } } @@ -4382,15 +4386,15 @@ int isloopdirok(cell_t *cell, int dir) { int isnewcellok(cell_t *cell, char *err) { if ( !cell) { // can't go that way - if (err) sprintf(err,"goes off the map."); + if (err) snprintf(err, BUFLEN,"goes off the map."); return B_FALSE; } else if ( !cell->type->solid) { // already an empty space there - if (err) sprintf(err,"goes to an empty space (%d,%d)",cell->x,cell->y); + if (err) snprintf(err, BUFLEN,"goes to an empty space (%d,%d)",cell->x,cell->y); return B_FALSE; } // ok! - if (err) sprintf(err, "OK!"); + if (err) snprintf(err, BUFLEN, "OK!"); return B_TRUE; } @@ -4576,10 +4580,10 @@ int linkstairs(object_t *o, object_t *o2) { if (o2) { char obid[BUFLEN]; // link it to here! - sprintf(obid, "%ld", o->id); + snprintf(obid, BUFLEN, "%ld", o->id); addflag(o2->flags, F_MAPLINK, stairmap->id, NA, NA, obid); // link me to there - sprintf(obid, "%ld", o2->id); + snprintf(obid, BUFLEN, "%ld", o2->id); addflag(o->flags, F_MAPLINK, othermap->id, NA, NA, obid); // now mark that we are not a new staircase to a new region anymore f = hasflag(o->flags, F_CLIMBABLE); @@ -4756,7 +4760,7 @@ enum RACE parserace(char *name, flagpile_t *wantflags, enum JOB *wantjob) { for (j = firstjob ; j ; j = j->next) { char *ep; char jobname[BUFLEN]; - sprintf(jobname, " %s", j->name); + snprintf(jobname, BUFLEN, " %s", j->name); jobname[1] = tolower(jobname[1]); ep = strends(name, jobname); if (ep) { @@ -4904,12 +4908,12 @@ int shattercell(cell_t *c, lifeform_t *fromlf, char *damstring) { if (c->type->material->id == MT_GLASS) { int numshards; numshards = rnd(50,100); - sprintf(buf, "%d pieces of broken glass",numshards); + snprintf(buf, BUFLEN, "%d pieces of broken glass",numshards); addob(c->obpile, buf); } else if (c->type->material->id == MT_ICE) { int numshards; numshards = rnd(50,100); - sprintf(buf, "%d chunks of ice",numshards); + snprintf(buf, BUFLEN, "%d chunks of ice",numshards); addob(c->obpile, buf); } } @@ -5019,6 +5023,8 @@ int wallstoleftright(cell_t *c, int dir) { case D_E: case D_W: d1 = D_N; d2 = D_S; break; + default: + return B_FALSE; } if (iswallindir(c,d1) && iswallindir(c,d2)) { return B_TRUE; diff --git a/move.c b/move.c index 37fcc7b..f3404a1 100644 --- a/move.c +++ b/move.c @@ -733,7 +733,7 @@ int knockback(lifeform_t *lf, int dir, int howfar, lifeform_t *pusher, int fallc getobname(rdata, thing, 1); } if (seen) msg("%s slam%s into %s!",lfname,isplayer(lf) ? "" : "s", thing); - sprintf(buf, "slamming into %s", thing); + snprintf(buf, BUFLEN, "slamming into %s", thing); losehp(lf, rnd(1,6), DT_BASH, pusher, buf); // stop moving i = howfar; @@ -883,7 +883,7 @@ int moveeffects(lifeform_t *lf) { int didmsg = B_FALSE; if (isbleeding(lf)) { - if (lfhasflagval(lf, F_INJURY, BP_LEGS, DT_SLASH, NA, NULL)) { + if (lfhasflagval(lf, F_INJURY, NA, BP_LEGS, DT_SLASH, NULL)) { bleed(lf); losehp(lf, 1, DT_DIRECT, NULL, "blood loss"); } else { @@ -1112,7 +1112,7 @@ int movelf(lifeform_t *lf, cell_t *newcell) { msg("%s steps on %s!",lfname, obname); didmsg = B_TRUE; } - sprintf(buf, "stepping on %s", obname); + snprintf(buf, BUFLEN, "stepping on %s", obname); losehp(lf, rnd(f->val[0],f->val[1]), DT_SLASH, NULL, buf); } } @@ -1502,7 +1502,7 @@ int opendoor(lifeform_t *lf, object_t *o) { if (hasflagval(o->flags, F_TRAPPED, NA, NA, B_TRUE, NULL)) { if (getattrbracket(getattr(lf, A_WIS), A_WIS, NULL) >= AT_AVERAGE) { char ch; - sprintf(buf,"Really open %s?", obname); + snprintf(buf, BUFLEN,"Really open %s?", obname); ch = askchar(buf,"yn","n", B_TRUE); if (ch != 'y') { msg("Cancelled."); @@ -1519,7 +1519,7 @@ int opendoor(lifeform_t *lf, object_t *o) { if (pastdoorcell && getcellwaterdepth(pastdoorcell, NULL)) { if (getattrbracket(getattr(lf, A_WIS), A_WIS, NULL) >= AT_AVERAGE) { char ch; - sprintf(buf,"Your hear running water behind %s. Really open it?", obname); + snprintf(buf, BUFLEN,"Your hear running water behind %s. Really open it?", obname); ch = askchar(buf,"yn","n", B_TRUE); if (ch != 'y') { msg("Cancelled."); @@ -1741,7 +1741,7 @@ int trysneak(lifeform_t *lf, int dir) { if (isplayer(lf)) { char ques[BUFLEN]; char ch; - sprintf(ques, "Carefully %s in which direction (- to cancel)", getmoveverb(lf)); + snprintf(ques, BUFLEN, "Carefully %s in which direction (- to cancel)", getmoveverb(lf)); ch = askchar(ques, "yuhjklbn.-","-", B_FALSE); dir = chartodir(ch); if (dir == D_NONE) return B_TRUE; @@ -1979,7 +1979,7 @@ int initiatemove(lifeform_t *lf, cell_t *cell, int *didmsg) { taketime(lf, getmovespeed(lf)); reason = E_OK; // avoid this object in future - sprintf(buf, "%ld",o->id); + snprintf(buf, BUFLEN, "%ld",o->id); addflag(lf->flags, F_AVOIDOB, B_CURSED, NA, NA, buf); return B_TRUE; } else if (lfhasflagval(lf, F_AVOIDOBTYPE, o->type->id, NA, NA, NULL)) { @@ -1994,7 +1994,7 @@ int initiatemove(lifeform_t *lf, cell_t *cell, int *didmsg) { taketime(lf, getmovespeed(lf)); reason = E_OK; // avoid this object in future - sprintf(buf, "%ld",o->id); + snprintf(buf, BUFLEN, "%ld",o->id); addflag(lf->flags, F_AVOIDOB, NA, NA, NA, buf); return B_TRUE; } @@ -2132,9 +2132,9 @@ int trymove(lifeform_t *lf, int dir, int onpurpose) { object_t *avoidob; avoidob = (object_t *)rdata; getobname(avoidob, obname, avoidob->amt); - sprintf(ques, "Really %s into %s?", getmoveverb(lf), obname); + snprintf(ques, BUFLEN, "Really %s into %s?", getmoveverb(lf), obname); } else { - sprintf(ques, "Really %s there?", getmoveverb(lf)); + snprintf(ques, BUFLEN, "Really %s there?", getmoveverb(lf)); } ch = askchar(ques, "yn","n", B_TRUE); if (ch != 'y') { @@ -2280,7 +2280,7 @@ int trymove(lifeform_t *lf, int dir, int onpurpose) { if (isplayer(lf)) { // only take damage if we didn't know about this if ((cell && !cell->known) || isdrunk(lf)) { - sprintf(buf, "%sing into a %s", getmoveverb(lf), + snprintf(buf, BUFLEN, "%sing into a %s", getmoveverb(lf), cell ? cell->type->name : "wall"); losehp(lf, 1, DT_BASH, NULL, buf); if (cell) { @@ -2291,7 +2291,7 @@ int trymove(lifeform_t *lf, int dir, int onpurpose) { if (onpurpose) taketime(lf, getmovespeed(lf)); } } else { - sprintf(buf, "%sing into a %s", getmoveverb(lf), + snprintf(buf, BUFLEN, "%sing into a %s", getmoveverb(lf), cell ? cell->type->name : "wall"); losehp(lf, 1, DT_BASH, NULL, buf); if (onpurpose) taketime(lf, getmovespeed(lf)); @@ -2311,7 +2311,7 @@ int trymove(lifeform_t *lf, int dir, int onpurpose) { } else { msg("Ouch! You %s into a door.", getmoveverb(lf)); setcellknown(cell, B_FALSE); - sprintf(buf, "%sing into a door", getmoveverb(lf)); + snprintf(buf, BUFLEN, "%sing into a door", getmoveverb(lf)); losehp(lf, 1, DT_BASH, NULL, buf); if (onpurpose) taketime(lf, getmovespeed(lf)); } @@ -2320,7 +2320,7 @@ int trymove(lifeform_t *lf, int dir, int onpurpose) { getlfname(lf, buf); msg("%s %ss into a door.", buf, getmoveverb(lf)); } - sprintf(buf, "%sing into a door", getmoveverb(lf)); + snprintf(buf, BUFLEN, "%sing into a door", getmoveverb(lf)); losehp(lf, 1, DT_BASH, NULL, buf); if (onpurpose) taketime(lf, getmovespeed(lf)); } @@ -2658,7 +2658,7 @@ int willmove(lifeform_t *lf, int dir, enum ERROR *error) { // look for avoided objects (because they are cursed). for (o = cell->obpile->first ; o ; o = o->next) { flag_t *f; - sprintf(buf, "%ld",o->id); + snprintf(buf, BUFLEN, "%ld",o->id); f = lfhasflagval(lf, F_AVOIDOB, NA, NA, NA, buf); if (f) { // still cursed? diff --git a/nexus.c b/nexus.c index 06cd7b7..3526a51 100644 --- a/nexus.c +++ b/nexus.c @@ -159,6 +159,7 @@ int main(int argc, char **argv) { cell_t *where; int dir; flag_t *f; + region_t *wregion, *dregion,*hregion; map_t *dmap; // populate scroll, potion, etc names @@ -195,27 +196,23 @@ int main(int argc, char **argv) { } } - // if no maps (ie. ALWAYS now that maps aren't persistent), // make the initial level - if (!firstmap) { - region_t *wregion, *dregion,*hregion; - newworld = B_TRUE; - // create world map. - wregion = addregion(RG_WORLDMAP, NULL, -1); - assert(wregion); - addmap(); - createmap(firstmap, 1, wregion, NULL, D_NONE, NULL); - // create first dungeon - dregion = findregionbytype(RG_FIRSTDUNGEON); - assert(dregion); - dmap = addmap(); - createmap(dmap, 1, dregion, firstmap, D_DOWN, NULL); - // create heaven - hregion = addregion(RG_HEAVEN, NULL, -1); - assert(hregion); - heaven = addmap(); - createmap(heaven, 1, hregion, NULL, D_NONE, NULL); - } + newworld = B_TRUE; + // create world map. + wregion = addregion(RG_WORLDMAP, NULL, -1); + assert(wregion); + addmap(); + createmap(firstmap, 1, wregion, NULL, D_NONE, NULL); + // create first dungeon + dregion = findregionbytype(RG_FIRSTDUNGEON); + assert(dregion); + dmap = addmap(); + createmap(dmap, 1, dregion, firstmap, D_DOWN, NULL); + // create heaven + hregion = addregion(RG_HEAVEN, NULL, -1); + assert(hregion); + heaven = addmap(); + createmap(heaven, 1, hregion, NULL, D_NONE, NULL); // find staircase where = findobinmap(dmap, OT_STAIRSUP); @@ -307,12 +304,12 @@ int main(int argc, char **argv) { } getplayernamefull(pname); - sprintf(welcomemsg, "Greetings %s, welcome to %snexus!", pname, newworld ? "the new " : ""); + snprintf(welcomemsg, BUFLEN, "Greetings %s, welcome to %snexus!", pname, newworld ? "the new " : ""); // 00:00 - 23:59 curtime = rnd(0,DAYSECS-1); } else { - sprintf(welcomemsg, "Welcome back!"); + snprintf(welcomemsg, BUFLEN, "Welcome back!"); } // start game - this will cause debug messages to now @@ -599,7 +596,7 @@ void donextturn(map_t *map) { long obid; lifeform_t *targlf; object_t *targob; - cell_t *targcell; + cell_t *targcell = NULL; map_t *targmap; enum OBTYPE sid; @@ -727,7 +724,7 @@ void donextturn(map_t *map) { //char buf[BUFLEN]; // do ai move //real_getlfname(who, lfname, B_FALSE); - //sprintf(buf, "aimove %s",lfname); + //snprintf(buf, BUFLEN, "aimove %s",lfname); //dbtimestart(buf); aiturn(who); //dbtimeend(buf); @@ -840,7 +837,7 @@ void getrarityrange(int depth, int *min, int *max, int range, int oodok) { mid = 100 - (depth * 3); *min = mid - range; if (*min < 0) *min = 0; - //*max = mid + range; if (*max > 100) *max = 100; + // *max = mid + range; if (*max > 100) *max = 100; *max = 100; //if (*min > 85) *min = 85; diff --git a/objects.c b/objects.c index c5d1da0..df5abc2 100644 --- a/objects.c +++ b/objects.c @@ -236,7 +236,7 @@ brand_t *addbrand(enum BRAND id, char *suffix, enum BODYPART bp) { // props a->id = id; a->bp = bp; - sprintf(buf, " %s",suffix); + snprintf(buf, BUFLEN, " %s",suffix); a->suffix = strdup(buf); a->flags = addflagpile(NULL, NULL); @@ -572,7 +572,7 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes // water flags for (n = DP_MAX; n >= DP_FIRST; n--) { char wpre[BUFLEN]; - sprintf(wpre, "%s ", getwaterdepthname(n)); + snprintf(wpre, BUFLEN, "%s ", getwaterdepthname(n)); if (strstarts(p, wpre)) { wantdepth = n; p += strlen(wpre); @@ -694,7 +694,7 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes for (;*p2 != ' ';p2++); p2++; // now at start of name - sprintf(racename, "%s",p2); + snprintf(racename, BUFLEN, "%s",p2); corpserace = findracebyname(racename); ot = findot(OT_STATUE); @@ -790,7 +790,7 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes int i; int matched = B_FALSE; for (i = 0; i < oc->nnouns; i++) { - sprintf(tempname, "random %s", oc->noun[i]); + snprintf(tempname, BUFLEN, "random %s", oc->noun[i]); if (strstarts(p, tempname) || streq(p, oc->noun[i])) { matched = B_TRUE; } @@ -1052,6 +1052,7 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes int n; for (n = 0; n < ndoorflags; n++) { int val[3]; + int ok = B_FALSE; if (obloc) { // fill in flag vals switch (doorflag[n]) { @@ -1059,20 +1060,26 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int wantlinkholes val[0] = B_TRUE; val[1] = getdoorlockdiff(obloc->map->depth); val[2] = NA; + ok = B_TRUE; break; case F_JAMMED: val[0] = rnd(1,obloc->map->depth+3); val[1] = NA; val[2] = NA; + ok = B_TRUE; break; case F_SECRET: val[0] = getdoorsecretdiff(obloc->map->depth); val[1] = NA; val[2] = NA; + ok = B_TRUE; + break; + default: break; - default: break; } - addflag(o->flags, doorflag[n], val[0], val[1], val[2], NULL); + if (ok) { + addflag(o->flags, doorflag[n], val[0], val[1], val[2], NULL); + } } } } @@ -1622,7 +1629,7 @@ obmod_t *addobmod(enum OBMOD id, char *prefix) { // props a->id = id; - sprintf(buf, "%s ",prefix); + snprintf(buf, BUFLEN, "%s ",prefix); a->prefix = strdup(buf); a->flags = addflagpile(NULL, NULL); @@ -2318,16 +2325,16 @@ int changemat(object_t *o, enum MATERIAL mat) { return B_FALSE; } -objecttype_t *checkobnames(char *haystack, char *needle) { - objecttype_t *ot; +int checkobnames(char *haystack, char *needle) { char *pluralname; int db = B_FALSE; + // search for exact match if (!strcmp(haystack, needle)) { // found it! if (db) dblog("checkobnames(): got exact match: '%s'",haystack); - return ot; + return B_TRUE; } // search for words ending in "s" (eg. "swords") @@ -2340,7 +2347,7 @@ objecttype_t *checkobnames(char *haystack, char *needle) { if (!strcmp(haystack, pluralname)) { if (db) dblog("checkobnames(): got match after stripping 's': '%s' -> '%s'",pluralname, needle); free(pluralname); - return ot; + return B_TRUE; } // search for words ending in "es" (eg. tomatoes) @@ -2355,13 +2362,13 @@ objecttype_t *checkobnames(char *haystack, char *needle) { if (!strcmp(haystack, pluralname)) { if (db) dblog("checkobnames(): got match after stripping 'es': '%s' -> '%s'",pluralname, needle); free(pluralname); - return ot; + return B_TRUE; } } } free(pluralname); - return NULL; + return B_FALSE; } @@ -3117,7 +3124,7 @@ int getobaccuracy(object_t *wep, lifeform_t *weilder) { int getobbonus(object_t *o) { int bonus = 0,i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; getflags(o->flags, retflag, &nretflags, F_BONUS, F_NONE); for (i = 0; i < nretflags; i++) { @@ -3190,7 +3197,7 @@ int getobvalue(object_t *o) { int rarity = 0,i; enum RARITY rr = RR_COMMON; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (o->type->id == OT_GOLD) { return o->amt; @@ -3443,7 +3450,7 @@ object_t *getrandomammo(lifeform_t *lf) { flag_t *f; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; gun = getfirearm(lf); if (!gun) { return NULL; @@ -3883,10 +3890,10 @@ char *getobdesc(object_t *o, char *buf) { if (f) { race_t *corpserace; corpserace = findrace(f->val[0]); - sprintf(buf, "The dead body of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", + snprintf(buf, BUFLEN, "The dead body of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", corpserace->name); } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else if (o->type->id == OT_HEAD) { flag_t *f; @@ -3894,10 +3901,10 @@ char *getobdesc(object_t *o, char *buf) { if (f) { race_t *corpserace; corpserace = findrace(f->val[0]); - sprintf(buf, "The decapitated head of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", + snprintf(buf, BUFLEN, "The decapitated head of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", corpserace->name); } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else if (o->type->id == OT_STATUE) { flag_t *f; @@ -3905,10 +3912,10 @@ char *getobdesc(object_t *o, char *buf) { if (f) { race_t *corpserace; corpserace = findrace(f->val[0]); - sprintf(buf, "A stone statue of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", + snprintf(buf, BUFLEN, "A stone statue of %s %s.", isvowel(corpserace->name[0]) ? "an" : "a", corpserace->name); } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else if (o->type->id == OC_SCROLL) { flag_t *f; @@ -3917,18 +3924,18 @@ char *getobdesc(object_t *o, char *buf) { objecttype_t *spelltype; spelltype = findot(f->val[0]); if (spelltype) { - sprintf(buf, "%s", spelltype->desc); + snprintf(buf, BUFLEN, "%s", spelltype->desc); } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else if (o->type->id == OT_WATERDEEP) { - sprintf(buf, "%s water.", getwaterdepthname(getobdepth(o, player))); + snprintf(buf, BUFLEN, "%s water.", getwaterdepthname(getobdepth(o, player))); capitalise(buf); } else { - sprintf(buf, "%s", o->type->desc); + snprintf(buf, BUFLEN, "%s", o->type->desc); } } else { objecttype_t *ot = NULL; @@ -3939,9 +3946,9 @@ char *getobdesc(object_t *o, char *buf) { } if (ot) { - sprintf(buf, "%s", ot->desc); + snprintf(buf, BUFLEN, "%s", ot->desc); } else { - sprintf(buf, "%s", o->type->obclass->desc); + snprintf(buf, BUFLEN, "%s", o->type->obclass->desc); } } return buf; @@ -4011,15 +4018,15 @@ char *getobextrainfo(object_t *o, char *buf) { char chargestr[BUFLEN]; if (o->type->obclass->id == OC_GODSTONE) { if (f->val[0] == f->val[1]) { - sprintf(chargestr, " (charged)"); + snprintf(chargestr, BUFLEN, " (charged)"); } else { - sprintf(chargestr, " (depleted)"); + snprintf(chargestr, BUFLEN, " (depleted)"); } } else { if (f->val[0] > 0) { - sprintf(chargestr, " (%d charges left)",f->val[0]); + snprintf(chargestr, BUFLEN, " (%d charges left)",f->val[0]); } else { - sprintf(chargestr, " (empty)"); + snprintf(chargestr, BUFLEN, " (empty)"); } } strcat(buf, chargestr); @@ -4099,7 +4106,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan cell_t *where; int no_a = B_FALSE; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; // default to normal name if (hasflag(o->flags, F_VENDITEM)) { @@ -4144,14 +4151,14 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (who) { char lfname[BUFLEN]; real_getlfname(who, lfname, B_FALSE); - sprintf(buf, "%s%s %sscent",lfname,getpossessive(lfname), adjective); + snprintf(buf, BUFLEN, "%s%s %sscent",lfname,getpossessive(lfname), adjective); } else { - sprintf(buf, "%s %sscent",r->name, adjective); + snprintf(buf, BUFLEN, "%s %sscent",r->name, adjective); } strcat(basename, buf); strcat(basename, " leading "); - sprintf(dname, "%s", getdirname(f->val[1])); + snprintf(dname, BUFLEN, "%s", getdirname(f->val[1])); dname[0] = tolower(dname[0]); strcat(basename, dname); } else { @@ -4173,7 +4180,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan // adept and upwards get "monstername footprints" if (slev >= PR_ADEPT) { - sprintf(buf, "%s %s",r->name, o->type->name); + snprintf(buf, BUFLEN, "%s %s",r->name, o->type->name); strcat(basename, buf); } else { strcat(basename, o->type->name); @@ -4183,7 +4190,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (slev >= PR_SKILLED) { char dname[BUFLEN]; strcat(basename, " leading "); - sprintf(dname, "%s", getdirname(f->val[1])); + snprintf(dname, BUFLEN, "%s", getdirname(f->val[1])); dname[0] = tolower(dname[0]); strcat(basename, dname); } @@ -4194,19 +4201,19 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan flag_t *f; f = hasflag(o->flags, F_MAPTO); if (f && getskill(player, SK_CARTOGRAPHY)) { - sprintf(basename, "map to %s", f->text); + snprintf(basename, BUFLEN, "map to %s", f->text); } else { strcpy(basename, "map"); } } else if (o->type->id == OT_WATERDEEP) { - sprintf(basename, "%s water", getwaterdepthname(getobdepth(o, player))); + snprintf(basename, BUFLEN, "%s water", getwaterdepthname(getobdepth(o, player))); } else { strcpy(basename, ""); // show "lit candle" etc if (isactivated(o) && hasflag(o->flags, F_ACTIVATEPREFIX)) { f = hasflag(o->flags, F_ACTIVATEPREFIX); - sprintf(basename, "%s ", f->text); + snprintf(basename, BUFLEN, "%s ", f->text); } else if (hasflagval(o->flags, F_TRAPPED, NA, NA, B_TRUE, NULL)) { // known trap? strcpy(basename, "trapped "); @@ -4289,10 +4296,10 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan corpserace = findrace(f->val[0]); ff = hasflag(corpserace->flags, F_NAME); if (ff) { - sprintf(basename, "%s%s corpse",ff->text, getpossessive(ff->text)); + snprintf(basename, BUFLEN, "%s%s corpse",ff->text, getpossessive(ff->text)); no_a = B_TRUE; } else { - sprintf(basename, "%s corpse",corpserace->name); + snprintf(basename, BUFLEN, "%s corpse",corpserace->name); } } } else if (o->type->id == OT_FOUNTAIN) { @@ -4319,7 +4326,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (streq(buf, "of water")) { strcpy(basename, "water fountain"); } else { - sprintf(basename, "fountain %s",buf); + snprintf(basename, BUFLEN, "fountain %s",buf); } } else { char *dstp; @@ -4333,7 +4340,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan } *dstp = '\0'; // buf should now be something like "orange " - sprintf(basename, "%sfountain",buf); + snprintf(basename, BUFLEN, "%sfountain",buf); } } else { // should never happen @@ -4349,14 +4356,14 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (f) { race_t *corpserace; corpserace = findrace(f->val[0]); - sprintf(basename, "statue of a %s",corpserace->name); + snprintf(basename, BUFLEN, "statue of a %s",corpserace->name); } } else if ((o->type->id == OT_STEW) || (o->type->id == OT_JERKY)) { f = hasflag(o->flags, F_LINKRACE); if (f) { race_t *r; r = findrace(f->val[0]); - sprintf(basename, "%s %s",r->name, o->type->name); + snprintf(basename, BUFLEN, "%s %s",r->name, o->type->name); } } @@ -4460,7 +4467,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan int bonus; bonus = f->val[0]; if (bonus != 0) { - sprintf(buf2, "%s%d ", (bonus < 0) ? "-" : "+", abs(bonus)); + snprintf(buf2, BUFLENSMALL, "%s%d ", (bonus < 0) ? "-" : "+", abs(bonus)); strcat(localbuf, buf2); } } @@ -4475,7 +4482,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan case OT_RING_STR: f = hasflag(o->flags, F_EQUIPCONFER); if (f) { - sprintf(buf2, "+%d ",f->val[2]); + snprintf(buf2, BUFLENSMALL, "+%d ",f->val[2]); strcat(localbuf, buf2); } break; @@ -4536,7 +4543,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (newmap) { if (newmap->region == thismap->region) { char buf2[BUFLEN]; - sprintf(buf2, " to level %d", newmap->depth); + snprintf(buf2, BUFLEN, " to level %d", newmap->depth); strcat(localbuf, buf2); } else { char buf2[BUFLEN]; @@ -4567,6 +4574,11 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan // show if we've tried this if (gamemode == GM_GAMESTARTED) { strcpy(triedbuf, ""); + + if (hasflag(o->flags, F_BEINGUSED)) { + strcat(triedbuf, " [currently being read]"); + } + if (istried(o)) { if (strlen(triedbuf)) strcat(triedbuf, ", "); else strcpy(triedbuf, " ["); @@ -4601,7 +4613,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (f) { char pricebuf[BUFLEN]; // get price for _player_ - sprintf(pricebuf, " [$%d%s]", (int)getshopprice(o, player), o->pile->owner ? ", unpaid" : ""); + snprintf(pricebuf, BUFLEN, " [$%d%s]", (int)getshopprice(o, player), o->pile->owner ? ", unpaid" : ""); strcat(localbuf, pricebuf); } @@ -4613,7 +4625,7 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan if (no_a) { if (o->type->id == OT_GOLD) { - sprintf(prefix, "%d ",count); + snprintf(prefix, BUFLEN, "%d ",count); } else { // nothing. strcpy(prefix, ""); @@ -4631,11 +4643,11 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan } } else { // multiple objects? - sprintf(prefix, "%d ",count); + snprintf(prefix, BUFLEN, "%d ",count); } // prepend prefix on to buf - sprintf(buf, "%s%s", prefix, localbuf); + snprintf(buf, BUFLEN, "%s%s", prefix, localbuf); return buf; } @@ -4666,7 +4678,7 @@ char *getobconditionname(object_t *o, char *buf) { // you only know it's rotting if you are smart or a cook if (isrotting(o) && ( (iqb >= AT_GTAVERAGE) || getskill(player, SK_COOKING)) ) { - sprintf(buf, "rotting"); + snprintf(buf, BUFLEN, "rotting"); } else { strcpy(buf, ""); } @@ -4677,13 +4689,13 @@ char *getobconditionname(object_t *o, char *buf) { if (pct >= 100) { strcpy(buf, ""); } else if (pct >= 75) { - sprintf(buf, "battered"); + snprintf(buf, BUFLEN, "battered"); } else if (pct >= 50) { - sprintf(buf, "damaged"); + snprintf(buf, BUFLEN, "damaged"); } else if (pct >= 25) { - sprintf(buf, "very damaged"); + snprintf(buf, BUFLEN, "very damaged"); } else { - sprintf(buf, "critically damaged"); + snprintf(buf, BUFLEN, "critically damaged"); } } else { strcpy(buf, ""); @@ -4834,7 +4846,7 @@ char *real_getrandomob(map_t *map, char *buf, int cond, int cval, int forcedepth while (!done) { if (db) dblog("adding random object with rarity value between %d - %d and rr <= %d",raritymin,raritymax,wantrr); if (db) { - objectclass_t *oc; + objectclass_t *oc = NULL; switch (cond) { case RO_DAMTYPE: dblog(" (must have damtype = %s)",getdamname(cval)); @@ -4974,7 +4986,7 @@ char *real_getrandomob(map_t *map, char *buf, int cond, int cval, int forcedepth while (rnd(1,100) <= chance) { bonus += dir; } - sprintf(buf2, "%s%d ", (bonus >= 0) ? "+" : "", bonus); + snprintf(buf2, BUFLENSMALL, "%s%d ", (bonus >= 0) ? "+" : "", bonus); strcat(cursestr, buf2); } @@ -5009,7 +5021,7 @@ char *real_getrandomob(map_t *map, char *buf, int cond, int cval, int forcedepth } - sprintf(buf, "%d %s%s%s", amt, cursestr, pluralname,brandname); + snprintf(buf, BUFLEN, "%d %s%s%s", amt, cursestr, pluralname,brandname); if (db) dblog("random ob: %d x %s ('%s')", amt, ot->name,pluralname); @@ -5259,7 +5271,7 @@ char *gettopobname(cell_t *c, char *retbuf) { strcpy(retbuf, c->type->name); nother = countnoncosmeticobs(c->obpile, B_TRUE); if (nother) { - sprintf(buf, " (+%d other thing%s)", nother, (nother == 1) ? "" : "s"); + snprintf(buf, BUFLEN, " (+%d other thing%s)", nother, (nother == 1) ? "" : "s"); strcat(retbuf, buf); } return retbuf; @@ -5272,7 +5284,7 @@ char *gettopobname(cell_t *c, char *retbuf) { // other obs here too? nother = countnoncosmeticobs(c->obpile, B_TRUE) - 1; if (nother >= 1) { - sprintf(buf, " (+%d other thing%s)", nother, (nother == 1) ? "" : "s"); + snprintf(buf, BUFLEN, " (+%d other thing%s)", nother, (nother == 1) ? "" : "s"); strcat(retbuf, buf); } return retbuf; @@ -5465,11 +5477,11 @@ void initobjects(void) { for (n = 0; strlen(colour[n].name); n++) { char buf[BUFLEN]; // add it without an adjective - sprintf(buf, "%s book", colour[n].name); + snprintf(buf, BUFLEN, "%s book", colour[n].name); addhiddenname(OC_BOOK, buf); // add it with all known adjectives for (i = 0; strlen(bookadjective[i]) ; i++) { - sprintf(buf, "%s %s book",bookadjective[i], colour[n].name); + snprintf(buf, BUFLEN, "%s %s book",bookadjective[i], colour[n].name); addhiddenname(OC_BOOK, buf); } } @@ -5508,11 +5520,11 @@ void initobjects(void) { for (n = 0; strlen(colour[n].name); n++) { char buf[BUFLEN]; // add it without an adjective - sprintf(buf, "%s potion", colour[n].name); + snprintf(buf, BUFLEN, "%s potion", colour[n].name); addhiddenname(OC_POTION, buf); // add it with all known adjectives for (i = 0; strlen(potadjective[i]) ; i++) { - sprintf(buf, "%s %s potion",potadjective[i], colour[n].name); + snprintf(buf, BUFLEN, "%s %s potion",potadjective[i], colour[n].name); addhiddenname(OC_POTION, buf); } } @@ -5520,14 +5532,14 @@ void initobjects(void) { for (n = 0; strlen(gemtype[n].name); n++) { char buf[BUFLEN]; // add it without an adjective - sprintf(buf, "%s wand", gemtype[n].name); + snprintf(buf, BUFLEN, "%s wand", gemtype[n].name); addhiddenname(OC_WAND, buf); } for (n = 0; strlen(gemtype[n].name); n++) { char buf[BUFLEN]; // add it without an adjective - sprintf(buf, "%s ring", gemtype[n].name); + snprintf(buf, BUFLEN, "%s ring", gemtype[n].name); addhiddenname(OC_RING, buf); } @@ -5537,7 +5549,7 @@ void initobjects(void) { // add it with all known adjectives for (i = 0; strlen(techadjective[i]) ; i++) { char buf[BUFLEN]; - sprintf(buf, "%s %s",techadjective[i], technoun[n]); + snprintf(buf, BUFLEN, "%s %s",techadjective[i], technoun[n]); addhiddenname(OC_TECH, buf); } } @@ -6568,7 +6580,7 @@ void initobjects(void) { addflag(lastot->flags, F_LINKSPELL, OT_S_MAPPING, 4, NA, NULL); addflag(lastot->flags, F_RARITY, H_DUNGEON, 80, RR_UNCOMMON, NULL); - addot(OT_SCR_MINDSCAN, "scroll of mind scan", "Reveals detailed information about the target.", MT_PAPER, 0.5, OC_SCROLL, SZ_SMALL); + addot(OT_SCR_MINDSCAN, "scroll of mind scan", "Allows you to view the world through another creature's eyes.", MT_PAPER, 0.5, OC_SCROLL, SZ_SMALL); addflag(lastot->flags, F_LINKSPELL, OT_S_MINDSCAN, NA, NA, NULL); addflag(lastot->flags, F_RARITY, H_DUNGEON, 75, RR_UNCOMMON, NULL); @@ -8043,7 +8055,7 @@ void initobjects(void) { // tech - l2 addot(OT_FLASHBANG, "flashbang", "A stun grenade which temporarily blinds all within sight.", MT_METAL, 1, OC_TECH, SZ_TINY); - addflag(lastot->flags, F_RARITY, H_DUNGEON, 85, NA, NULL); + addflag(lastot->flags, F_RARITY, H_DUNGEON, 90, RR_UNCOMMON, NULL); addflag(lastot->flags, F_STACKABLE, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_OPERONOFF, B_TRUE, NA, NA, NULL); @@ -10077,6 +10089,13 @@ int isknownot(objecttype_t *ot) { +int isheavyweapon(object_t *o) { + if (getobunitweight(o) >= HEAVYWEPKG) { + return B_TRUE; + } + return B_FALSE; +} + // is the object fully identified? // ie. its type is known ("potion of healing" rather than "red potion") // AND @@ -10607,7 +10626,7 @@ void makeknown(enum OBTYPE otid) { int nobs = 0; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (player) { // if player is holding an object of that type with F_CONFER.. IFKNOWN... and isn't known... @@ -10688,7 +10707,7 @@ void makewet(object_t *o, int amt) { getobname(o,obname,o->amt); if (owner) { - sprintf(obnamefull, "%s%s %s",ownername, getpossessive(ownername), noprefix(obname)); + snprintf(obnamefull, BUFLEN, "%s%s %s",ownername, getpossessive(ownername), noprefix(obname)); } else { strcpy(obnamefull, obname); } @@ -11007,14 +11026,14 @@ void obdie(object_t *o) { f2 = hasflag(o->flags, F_DIECONVERTTEXT); } if (f2) { - sprintf(desc, "%s", f2->text); + snprintf(desc, BUFLEN, "%s", f2->text); } else if (oblastdamtype(o) == DT_DECAY) { // don't announce devay death while traning if (!lfhasflag(player, F_TRAINING)) { - sprintf(desc, "%s completed rotted away", (o->amt == 1) ? "has" : "have"); + snprintf(desc, BUFLEN, "%s completed rotted away", (o->amt == 1) ? "has" : "have"); } } else { - sprintf(desc, "%s destroyed", (o->amt == 1) ? "is" : "are"); + snprintf(desc, BUFLEN, "%s destroyed", (o->amt == 1) ? "is" : "are"); } if (strstr(o->type->name, "stain") || (o->type->id == OT_ROASTMEAT)) { assert(0 == 1); @@ -11060,13 +11079,13 @@ void obdie(object_t *o) { strcpy(desc, ""); f = hasflag(o->flags, F_OBDIETEXT); if (f) { - sprintf(desc, "%s", f->text); + snprintf(desc, BUFLEN, "%s", f->text); } else if (oblastdamtype(o) == DT_DECAY) { if (!lfhasflag(player, F_TRAINING)) { - sprintf(desc, "%s completely rotted away", (o->amt == 1) ? "has" : "have" ); + snprintf(desc, BUFLEN, "%s completely rotted away", (o->amt == 1) ? "has" : "have" ); } } else { - sprintf(desc, "%s destroyed", (o->amt == 1) ? "is" : "are"); + snprintf(desc, BUFLEN, "%s destroyed", (o->amt == 1) ? "is" : "are"); } if (strlen(desc)) { @@ -11126,7 +11145,7 @@ void obdie(object_t *o) { maxbones = o->weight / 5; if (minbones <= 0) minbones = 1; if (maxbones <= minbones) maxbones = 2; - sprintf(bonestr, "%d-%d bones",minbones,maxbones); + snprintf(bonestr, BUFLEN, "%d-%d bones",minbones,maxbones); addob(o->pile, bonestr); } } @@ -11345,7 +11364,7 @@ int obsfallthrough(cell_t *c, object_t *pit) { (oo->amt == 1) ? "s" : "", lfname); } - sprintf(dambuf, "a falling %s", oo->type->name); + snprintf(dambuf, BUFLEN, "a falling %s", oo->type->name); losehp(lf, getthrowdam(oo) * 6, DT_PROJECTILE, NULL, dambuf); } @@ -11408,7 +11427,7 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { if (hasflagval(o->flags, F_TRAPPED, NA, NA, B_TRUE, NULL)) { if (getattrbracket(getattr(lf, A_WIS), A_WIS, NULL) >= AT_AVERAGE) { char ch; - sprintf(buf,"Really operate %s?", obname); + snprintf(buf, BUFLEN,"Really operate %s?", obname); ch = askchar(buf,"yn","n", B_TRUE); if (ch != 'y') { msg("Cancelled."); @@ -11447,11 +11466,11 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { if (isplayer(lf)) { char subprompt[BUFLEN]; - sprintf(subprompt, "%s->Aim->", obname); + snprintf(subprompt, BUFLEN, "%s->Aim->", obname); if (strlen(f->text) > 0) { where = askcoords(f->text, subprompt, ttype, lf, UNLIMITED, LOF_NEED, B_TRUE); } else { - sprintf(buf, "Where will you aim %s?",obname); + snprintf(buf, BUFLEN, "Where will you aim %s?",obname); where = askcoords(buf, subprompt, ttype, lf, UNLIMITED, LOF_NEED, B_TRUE); if (!haslos(lf, where)) { msg("You can't see there!"); @@ -11537,19 +11556,19 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { if (hasflag(o->flags, F_CONTAINER) && (o->type->id != OT_VENDINGMACHINE)) { // loot it if (isplayer(lf)) { // only player can loot. char ch; - sprintf(buf, "Looting %s. Will you:",obname); + snprintf(buf, BUFLEN, "Looting %s. Will you:",obname); initprompt(&prompt, buf); if (countobs(lf->pack, B_FALSE)) { - sprintf(buf, "Put items in %s",obname); + snprintf(buf, BUFLEN, "Put items in %s",obname); addchoice(&prompt, 'i', buf, NULL, NULL); } if (countobs(o->contents, B_FALSE)) { - sprintf(buf, "Take items out of %s",obname); + snprintf(buf, BUFLEN, "Take items out of %s",obname); addchoice(&prompt, 'o', buf, NULL, NULL); } - sprintf(buf, "Both"); + snprintf(buf, BUFLEN, "Both"); addchoice(&prompt, 'b', buf, NULL, NULL); - sprintf(buf, "Neither"); + snprintf(buf, BUFLEN, "Neither"); addchoice(&prompt, 'n', buf, NULL, NULL); ch = getchoice(&prompt); switch (ch) { @@ -11585,11 +11604,11 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { } } if (nretobs <= 0) { - sprintf(buf, "You have no ammo for your %s!",noprefix(obname)); + snprintf(buf, BUFLEN, "You have no ammo for your %s!",noprefix(obname)); msg(buf); return B_TRUE; } else { - sprintf(buf, "Load %s with what ammo",obname); + snprintf(buf, BUFLEN, "Load %s with what ammo",obname); oo = askobject(lf->pack, buf, NULL, AO_SPECIFIED); if (oo) { loadfirearm(lf, o, oo); @@ -11841,7 +11860,7 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { int autoid = B_FALSE; object_t *newob; getobname(oo, liquidname, 1); - sprintf(ques, "Fill your %s from %s?", noprefix(obname), liquidname); + snprintf(ques, BUFLEN, "Fill your %s from %s?", noprefix(obname), liquidname); ch = askchar(ques, "yn", "y", B_TRUE); if (ch == 'y') { char newobname[BUFLEN]; @@ -12124,7 +12143,7 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { } else { char obname[BUFLEN]; getobname(o, obname, 1); - sprintf(buf, "Tighten the hinges on %s",obname); + snprintf(buf, BUFLEN, "Tighten the hinges on %s",obname); ch = askchar(buf, "yn", "y", B_TRUE); if (ch == 'y') { msg("You tighten the hinges on %s.", obname); @@ -12220,7 +12239,7 @@ int pour(lifeform_t *lf, object_t *o) { char buf[BUFLEN],obname[BUFLEN],lfname[BUFLEN],dstname[BUFLEN]; int playercansee; char ch; - object_t *dst; + object_t *dst = NULL; int doneask = B_FALSE; getobname(o, obname, 1); @@ -12242,7 +12261,7 @@ int pour(lifeform_t *lf, object_t *o) { object_t *door; door = hasobwithflag(c->obpile, F_DOOR); if (door) { - sprintf(buf, "Pour %s onto the door to the %s", obname, getdirname(d)); + snprintf(buf, BUFLEN, "Pour %s onto the door to the %s", obname, getdirname(d)); ch = askchar(buf, "yn", "n", B_TRUE); if (ch == 'y') { // finished asking where to pour @@ -12257,12 +12276,12 @@ int pour(lifeform_t *lf, object_t *o) { if (!doneask) { // tip onto what? - sprintf(buf, "Pour %s onto the ground", obname); + snprintf(buf, BUFLEN, "Pour %s onto the ground", obname); ch = askchar(buf, "yn", "y", B_TRUE); if (ch == 'y') { dst = NULL; } else { - sprintf(buf, "Pour %s onto what", obname); + snprintf(buf, BUFLEN, "Pour %s onto what", obname); // tip onto another object dst = askobject(lf->pack, buf, NULL, AO_NONE); if (!dst) { @@ -13198,7 +13217,9 @@ int readsomething(lifeform_t *lf, object_t *o) { // let player select ANY object (even if it won't // work). if (needsob && isplayer(lf) && !isknown(o)) { + f = addflag(o->flags, F_BEINGUSED, B_TRUE, NA, NA, NULL); targob = askobject(lf->pack, "Target which object", NULL, AO_NONE); + killflag(f); } dospelleffects(lf, f->val[0], power, NULL, targob, NULL, o->blessed, &seen, B_FALSE); @@ -13271,9 +13292,9 @@ int readsomething(lifeform_t *lf, object_t *o) { } else { char dirbuf[BUFLEN]; if (dist == 1) { - sprintf(buf, "%s is one area away to the ", f->text); + snprintf(buf, BUFLEN, "%s is one area away to the ", f->text); } else { - sprintf(buf, "%s is %d areas away to the ", f->text, dist); + snprintf(buf, BUFLEN, "%s is %d areas away to the ", f->text, dist); } strcpy(dirbuf, ""); if (tmy < lfmy) { @@ -13313,9 +13334,9 @@ int readsomething(lifeform_t *lf, object_t *o) { } else { char dirbuf[BUFLEN]; if (dist == 1) { - sprintf(buf, "%s is one area away to the ", f->text); + snprintf(buf, BUFLEN, "%s is one area away to the ", f->text); } else { - sprintf(buf, "%s is %d areas away to the ", f->text, dist); + snprintf(buf, BUFLEN, "%s is %d areas away to the ", f->text, dist); } strcpy(dirbuf, ""); if (tmy < lfmy) { @@ -13344,11 +13365,11 @@ int readsomething(lifeform_t *lf, object_t *o) { } else { char dirbuf[BUFLEN]; char buf2[BUFLEN]; - sprintf(buf, "%s is at %d,%d",f->text, tmx,tmy); + snprintf(buf, BUFLEN, "%s is at %d,%d",f->text, tmx,tmy); if (dist == 1) { - sprintf(buf2, " (one area away to the "); + snprintf(buf2, BUFLEN, " (one area away to the "); } else { - sprintf(buf2, " (%d areas away to the ", dist); + snprintf(buf2, BUFLEN, " (%d areas away to the ", dist); } strcpy(dirbuf, ""); if (tmy < lfmy) { @@ -13738,7 +13759,7 @@ int shatter(object_t *o, int hitlf, char *damstring, lifeform_t *fromlf) { if (o->pile->owner) { char lfname[BUFLEN]; getlfname(o->pile->owner, lfname); - sprintf(prefix, "%s%s ", lfname, getpossessive(lfname)); + snprintf(prefix, BUFLEN, "%s%s ", lfname, getpossessive(lfname)); // ie. "the kobold's" } else { strcpy(prefix, ""); @@ -13771,7 +13792,7 @@ int shatter(object_t *o, int hitlf, char *damstring, lifeform_t *fromlf) { int numshards; numshards = getnumshards(o); // place glass shards - sprintf(buf, "%d pieces of broken glass",numshards); + snprintf(buf, BUFLEN, "%d pieces of broken glass",numshards); addob(where->obpile, buf); } else if (o->material->id == MT_ICE) { int numshards; @@ -13779,7 +13800,7 @@ int shatter(object_t *o, int hitlf, char *damstring, lifeform_t *fromlf) { if (numshards < 1) numshards = 1; // ice - sprintf(buf, "%d chunks of ice",numshards); + snprintf(buf, BUFLEN, "%d chunks of ice",numshards); addob(where->obpile, buf); } @@ -14093,7 +14114,7 @@ int real_takedamage(object_t *o, unsigned int howmuch, int damtype, int wantanno char buf[BUFLEN]; char buf2[BUFLEN]; getobname(o, buf2, 1); - sprintf(buf, "a shattering %s", buf2); + snprintf(buf, BUFLEN, "a shattering %s", buf2); shatter(o, B_TRUE, buf, B_FALSE); return howmuch; } @@ -14227,13 +14248,13 @@ int real_takedamage(object_t *o, unsigned int howmuch, int damtype, int wantanno int nshards; char buf[BUFLEN]; nshards = getnumshards(o); - sprintf(buf, "%d pieces of broken glass", nshards); + snprintf(buf, BUFLEN, "%d pieces of broken glass", nshards); addob(o->pile, buf); } else if (o->material->id == MT_ICE) { // bashing breaks ice int nshards; char buf[BUFLEN]; nshards = getnumshards(o) / 15; - sprintf(buf, "%d chunks of ice", nshards); + snprintf(buf, BUFLEN, "%d chunks of ice", nshards); addob(o->pile, buf); } } @@ -14468,7 +14489,7 @@ int fireat(lifeform_t *thrower, object_t *o, int amt, cell_t *where, int speed, char throwstring[BUFLEN]; // a monster is throwing something - sprintf(throwstring, "%s %ss %s", throwername, throwverbpres, + snprintf(throwstring, BUFLEN, "%s %ss %s", throwername, throwverbpres, obname); if (target && haslos(player, where) && !hasflag(o->flags, F_POWDER)) { @@ -14491,10 +14512,10 @@ int fireat(lifeform_t *thrower, object_t *o, int amt, cell_t *where, int speed, if (o->pile->owner && cansee(player, o->pile->owner)) { char ownername[BUFLEN]; getlfname(o->pile->owner, ownername); - sprintf(throwstring, "%s%s %s %s through the air", ownername, getpossessive(ownername), + snprintf(throwstring, BUFLEN, "%s%s %s %s through the air", ownername, getpossessive(ownername), noprefix(obname), (amt == 1) ? "flies" : "fly"); } else { - sprintf(throwstring, "%s %s through the air", obname, (amt == 1) ? "flies" : "fly"); + snprintf(throwstring, BUFLEN, "%s %s through the air", obname, (amt == 1) ? "flies" : "fly"); } if (target && haslos(player, where)) { strcat(throwstring, " toward "); @@ -14541,7 +14562,7 @@ int fireat(lifeform_t *thrower, object_t *o, int amt, cell_t *where, int speed, } else if (o->type->id == OT_ASHEXPLODE) { char diebuf[BUFLEN]; // explosion! - sprintf(diebuf, "%dd6",o->amt); + snprintf(diebuf, BUFLEN, "%dd6",o->amt); if (haslos(player, srcloc)) { msg("%s dispers%s and explod%s!", obname, @@ -14782,15 +14803,15 @@ int fireat(lifeform_t *thrower, object_t *o, int amt, cell_t *where, int speed, // announce if (seen) { char buf2[BUFLEN]; - sprintf(buf2, "%s hit%s %s.",obname,(amt == 1) ? "s" : "", targetname); + snprintf(buf2, BUFLEN, "%s hit%s %s.",obname,(amt == 1) ? "s" : "", targetname); if (lfhasflag(player, F_EXTRAINFO)) { char damstring[BUFLEN]; - sprintf(damstring, " [%d dmg]",dam); + snprintf(damstring, BUFLEN, " [%d dmg]",dam); strcat(buf2, damstring); } msg("%s", buf2); } - sprintf(damstring, "%s (%s by %s)",obname,throwverbpast, realthrowernamea); + snprintf(damstring, BUFLEN, "%s (%s by %s)",obname,throwverbpast, realthrowernamea); reduceamt = getarmourdamreduction(target, o, dam, DT_PROJECTILE); @@ -14858,7 +14879,7 @@ int fireat(lifeform_t *thrower, object_t *o, int amt, cell_t *where, int speed, if (willshatter(newob->material->id)) { char dambuf[BUFLEN]; - sprintf(dambuf, "%s (%s by %s)",obname,throwverbpast, realthrowernamea); + snprintf(dambuf, BUFLEN, "%s (%s by %s)",obname,throwverbpast, realthrowernamea); shatter(newob, youhit, dambuf, thrower); } else { // object only gets damaged if it hit someone/something @@ -14885,7 +14906,7 @@ void timeeffectsob(object_t *o) { char obname[BUFLEN],ownername[BUFLEN]; int i; flag_t *retflag[MAXCANDIDATES]; - int nretflags; + int nretflags = 0; if (hasflag(o->flags, F_DEAD)) return; @@ -15270,7 +15291,7 @@ void timeeffectsob(object_t *o) { // in case the obpile doesn't have space // to fit both the new and old ones. // place item of this type here! - sprintf(buf, "%d %s", o->amt, f->text); + snprintf(buf, BUFLEN, "%d %s", o->amt, f->text); newob = addob(o->pile, buf); if (newob) { int cansee; @@ -15435,7 +15456,7 @@ void trapeffects(object_t *trapob, enum OBTYPE oid, cell_t *c) { noise(c, NULL, NC_OTHER, 10, "a blaring siren!", NULL); } else if ((oid == OT_TRAPARROW) || (oid == OT_TRAPARROWP)) { int dir,bestdir = D_NONE; - cell_t *src; + cell_t *src = NULL; int maxdist=-1; // get furthest wall @@ -15456,7 +15477,7 @@ void trapeffects(object_t *trapob, enum OBTYPE oid, cell_t *c) { src = prevc; } } - if (bestdir != D_NONE) { + if (src && (bestdir != D_NONE)) { object_t *o; if (oid == OT_TRAPARROWP) { o = addob(src->obpile, "poisoned arrow"); @@ -15471,6 +15492,9 @@ void trapeffects(object_t *trapob, enum OBTYPE oid, cell_t *c) { msg("ERROR: arrow trap failed."); dblog("ERROR: arrow trap failed."); } + } else { + msg("ERROR: arrow trap failed (no dir)."); + dblog("ERROR: arrow trap failed (no dir)."); } } else if (oid == OT_TRAPEBLAST) { if (haslos(player, c)) { @@ -15890,7 +15914,7 @@ int getcritchance(lifeform_t *lf, object_t *o) { f = hasflag(o->flags, F_CRITCHANCE); if (f) { - return chance += f->val[0]; + chance += f->val[0]; } if (lf) { @@ -15905,6 +15929,10 @@ int getcritchance(lifeform_t *lf, object_t *o) { } } + if (isplayer(lf)) { + // oooooo + chance = 100; + } return chance; } diff --git a/objects.h b/objects.h index 5848a40..464353c 100644 --- a/objects.h +++ b/objects.h @@ -33,7 +33,7 @@ int canseeob(lifeform_t *lf, object_t *o); object_t *canstackob(obpile_t *op, object_t *match); object_t *canstacknewot(obpile_t *op, objecttype_t *match); int changemat(object_t *o, enum MATERIAL mat); -objecttype_t *checkobnames(char *haystack, char *needle); +int checkobnames(char *haystack, char *needle); void colourmatchob(object_t *o, lifeform_t *lf); void copyobprops(object_t *dst, object_t *src); int countnames(char **list); @@ -164,6 +164,7 @@ int isfirearm(object_t *o); int isflammable(object_t *o); int isknown(object_t *o); int isknownot(objecttype_t *ot); +int isheavyweapon(object_t *o); int isidentified(object_t *o); int isimpassableob(object_t *o, lifeform_t *lf); int ismagical(object_t *o); diff --git a/save.c b/save.c index 7a8c705..cc3152f 100644 --- a/save.c +++ b/save.c @@ -285,7 +285,7 @@ map_t *loadmap(char *basefile) { int regionid; if (db) dblog("Loading map from %s...",basefile); - sprintf(filename, "%s/%s",MAPDIR,basefile); + snprintf(filename, BUFLEN, "%s/%s",MAPDIR,basefile); f = fopen(filename, "rt"); // create map @@ -311,7 +311,7 @@ map_t *loadmap(char *basefile) { m->name = strdup(buf + 5); // after 'name:' fscanf(f, "habitat:%d\n",(int *)&habitatid); // habitat m->habitat = findhabitat(habitatid); - fscanf(f, "seed:%d\n",&m->seed); // seed + fscanf(f, "seed:%u\n",&m->seed); // seed fscanf(f, "lastplayervisit:%ld\n",&m->lastplayervisit); fscanf(f, "dims:%d,%d\n",&m->w, &m->h); // map dimensons fscanf(f, "nextmaps:\n"); @@ -608,7 +608,7 @@ int loadregions(void) { int db = B_FALSE; // TODO: check that map dir exists - sprintf(filename, "%s/regions.dat",MAPDIR); + snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR); f = fopen(filename, "rt"); if (!f) { return B_TRUE; @@ -689,7 +689,7 @@ int loadsavegame(void) { p = ent->d_name + strlen(ent->d_name) - 4; // load this savegame if (!strcmp(p, ".sav") ) { - sprintf(filename, "%s/%s",SAVEDIR,ent->d_name); + snprintf(filename, BUFLEN, "%s/%s",SAVEDIR,ent->d_name); dblog("Trying to load from %s\n",filename); f = fopen(filename, "rt"); if (!f) { @@ -839,7 +839,7 @@ int savegame(void) { return B_TRUE; } // save player + their objects - sprintf(buf, "%s/game.sav",SAVEDIR); + snprintf(buf, BUFLEN, "%s/game.sav",SAVEDIR); f = fopen(buf, "wt"); if (!f) { msg("Could not open save file!"); @@ -865,7 +865,7 @@ int savemap(map_t *m) { int obcount = 0; // TODO: check that map dir exists - sprintf(filename, "%s/map%d.map",MAPDIR, m->id); + snprintf(filename, BUFLEN, "%s/map%d.map",MAPDIR, m->id); f = fopen(filename, "wt"); // save map info @@ -874,7 +874,7 @@ int savemap(map_t *m) { fprintf(f, "depth:%d\n",m->depth); // map depth fprintf(f, "name:%s\n",m->name); // map name fprintf(f, "habitat:%d\n",m->habitat->id); // habitat - fprintf(f, "seed:%d\n",m->seed); // seed + fprintf(f, "seed:%u\n",m->seed); // seed fprintf(f, "lastplayervisit:%ld\n",m->lastplayervisit); fprintf(f, "dims:%d,%d\n",m->w, m->h); // map dimensons fprintf(f, "nextmaps:\n"); @@ -977,7 +977,7 @@ int saveregions(void) { int numoutlines = 0,numregions = 0; // TODO: check that map dir exists - sprintf(filename, "%s/regions.dat",MAPDIR); + snprintf(filename, BUFLEN, "%s/regions.dat",MAPDIR); f = fopen(filename, "wt"); for (ro = firstregionoutline ; ro ; ro = ro->next) { numoutlines++; @@ -1050,7 +1050,7 @@ int showhiscores(lifeform_t *lf, int min, int max) { hilitescore = -1; } // open database - sprintf(filename, "%s/hiscores.db", DATADIR); + snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR); rc = sqlite3_open(filename, &db); if (rc) { msg("error opening hiscore file '%s'.\n",filename); @@ -1059,10 +1059,10 @@ int showhiscores(lifeform_t *lf, int min, int max) { } // show top ten - //sprintf(cmd, "select * from hiscores order by score desc limit 10;"); + //snprintf(cmd, BUFLEN, "select * from hiscores order by score desc limit 10;"); asprintf(&cmd, "select (select count(*) from hiscores b where b.score > a.score) + 1 as rank, score,name,job,killedby from hiscores a where (rank >= %d) and (rank <= %d) order by score desc limit 10;", min, max); - sprintf(hilitescoretext, "%ld",hilitescore); + snprintf(hilitescoretext, BUFLEN, "%ld",hilitescore); rc = sqlite3_exec(db, cmd, showhiscoreline, hilitescoretext, &errmsg); if (rc != SQLITE_OK) { msg("error writing hiscores: '%s'", errmsg); @@ -1086,13 +1086,13 @@ int writehiscore(lifeform_t *lf, int *rank) { char *errmsg = NULL; sqlite3_stmt *smt; job_t *j; - long minscore; + long minscore = 0; long score; score = calcscore(lf); // open database - sprintf(filename, "%s/hiscores.db", DATADIR); + snprintf(filename, BUFLEN, "%s/hiscores.db", DATADIR); rc = sqlite3_open(filename, &db); if (rc) { msg("error opening hiscore file '%s'.\n",filename); @@ -1102,7 +1102,7 @@ int writehiscore(lifeform_t *lf, int *rank) { getplayername(pname); j = getjob(player); - sprintf(jobname, "Lv%d %s", player->level, j->name); + snprintf(jobname, BUFLEN, "Lv%d %s", player->level, j->name); makekillertext(killedby, lf->lastdam, B_FALSE); @@ -1147,10 +1147,12 @@ int writehiscore(lifeform_t *lf, int *rank) { minscore = atol(p); rc = sqlite3_step(smt); } - // we now have a minimum score - delete everything lower than it. - asprintf(&cmd, "delete from hiscores where score < %ld;", minscore); - rc = sqlite3_exec(db, cmd, NULL, NULL, &errmsg); - free(cmd); + if (minscore > 0) { + // we now have a minimum score - delete everything lower than it. + asprintf(&cmd, "delete from hiscores where score < %ld;", minscore); + rc = sqlite3_exec(db, cmd, NULL, NULL, &errmsg); + free(cmd); + } sqlite3_close(db); return 0; diff --git a/spell.c b/spell.c index eaec35c..ecb3300 100644 --- a/spell.c +++ b/spell.c @@ -44,6 +44,8 @@ extern int ngodlfs; extern enum ERROR reason; +extern void (*precalclos)(lifeform_t *); + extern int needredraw, statdirty; int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifeform_t *target, flag_t *cwflag) { @@ -120,7 +122,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (!targcell) { if (isplayer(user)) { - sprintf(buf, "Charge who (max range %d)?",range); + snprintf(buf, BUFLEN, "Charge who (max range %d)?",range); // TODO: ask for direction targcell = askcoords(buf, "Charge->", TT_MONSTER, user, range, LOF_NEED, B_TRUE); if (!targcell) { @@ -207,7 +209,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef } } else if (abilid == OT_A_COOK) { object_t *water,*o; - race_t *r; + race_t *r = NULL; char buf[BUFLEN]; if (!isplayer(user)) { return B_TRUE; @@ -271,9 +273,9 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (!targcell) { if (isplayer(user)) { if (range != UNLIMITED) { - sprintf(buf, "Darkwalk to where (max range %d)?", range); + snprintf(buf, BUFLEN, "Darkwalk to where (max range %d)?", range); } else { - sprintf(buf, "Darkwalk to where?"); + snprintf(buf, BUFLEN, "Darkwalk to where?"); } targcell = askcoords(buf, "Darkwalk->", TT_NONE, user, range, LOF_DONTNEED, B_FALSE); } else { @@ -458,7 +460,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (f) killflag(f); f = hasflagval(lf->flags, F_TARGETCELL, user->cell->x, user->cell->y, NA, NULL); if (f) killflag(f); - sprintf(buf, "%d\n",user->id); + snprintf(buf, BUFLENTINY, "%d\n",user->id); f = hasflagval(lf->flags, F_TARGETCELL, NA, NA, MR_LF, buf); if (f) killflag(f); } @@ -660,7 +662,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (!targcell) { - sprintf(buf, "Jump where (max distance %d)?", maxrange); + snprintf(buf, BUFLEN, "Jump where (max distance %d)?", maxrange); while (!targcell) { // ask where targcell = askcoords(buf, "Jump->", TT_NONE, user, maxrange, LOF_DONTNEED, B_TRUE); @@ -669,12 +671,12 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef } else if (getcelldist(user->cell, targcell) > maxrange) { targcell = NULL; if (isplayer(user)) { - sprintf(buf, "You can't jump that far! Jump where (max distance %d)?", maxrange); + snprintf(buf, BUFLEN, "You can't jump that far! Jump where (max distance %d)?", maxrange); } } else if (!haslos(user, targcell)) { targcell = NULL; if (isplayer(user)) { - sprintf(buf, "You can't see where to land! Jump where (max distance %d)?", maxrange); + snprintf(buf, BUFLEN, "You can't see where to land! Jump where (max distance %d)?", maxrange); } } } @@ -770,7 +772,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (lfhasflag(user, F_EXTRAINFO) || lfhasflag(user, F_OMNIPOTENT)) { msg("[%s takes %d damage]",victimname,dam); } - sprintf(buf, "a falling %s", user->race->name); + snprintf(buf, BUFLEN, "a falling %s", user->race->name); losehp(victim, dam, DT_BASH, user, buf); } } @@ -844,7 +846,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef // 1.compile a list of repairable objects // sk_armour lets you repair armour up to xx% (depends on skill) initprompt(&prompt, "Repair which object?"); - addchoice(&prompt, '-', "Cancel", "Cancel", o); + addchoice(&prompt, '-', "Cancel", "Cancel", NULL); for (o = user->pack->first ; o ; o = o->next) { int ok = B_FALSE; int cutoff = 0; @@ -1117,7 +1119,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (!targcell) { if (isplayer(user)) { - sprintf(buf, "Swoop who (max range %d)?",srange); + snprintf(buf, BUFLEN, "Swoop who (max range %d)?",srange); // TODO: ask for direction targcell = askcoords(buf, "Swoop->", TT_MONSTER, user, srange, LOF_NEED, B_TRUE); if (!targcell) { @@ -1220,7 +1222,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef } if (!targcell) { - sprintf(buf, "Tumble where (max distance 2)?"); + snprintf(buf, BUFLEN, "Tumble where (max distance 2)?"); while (!targcell) { // ask where targcell = askcoords(buf, "Tumble->", TT_NONE, user, 2, LOF_NEED, B_TRUE); @@ -1230,12 +1232,12 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef } else if (!haslos(user, targcell)) { targcell = NULL; if (isplayer(user)) { - sprintf(buf, "You can't see where to land! Tumble where (max distance 2)?"); + snprintf(buf, BUFLEN, "You can't see where to land! Tumble where (max distance 2)?"); } } else if (!haslof(user->cell, targcell, LOF_NEED, NULL)) { targcell = NULL; if (isplayer(user)) { - sprintf(buf, "You don't have a clear line of fire to there!"); + snprintf(buf, BUFLEN, "You don't have a clear line of fire to there!"); } } } @@ -1341,7 +1343,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef lf = godlf[i]; real_getlfname(lf, buf, B_FALSE); f = hasflag(lf->flags, F_GODOF); - sprintf(godof, " (%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); + snprintf(godof, BUFLEN, " (%s of %s)", (f->val[0] == B_FEMALE) ? "Goddess" : "God", f->text); strcat(buf, godof); addchoice(&prompt, 'a', buf, NULL, lf); } @@ -1361,7 +1363,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef initprompt(&prompt, "Which skill will you learn?"); ch = 'a'; for (sk = firstskill ; sk ; sk = sk->next) { - sprintf(buf, "%s (%s)",getskillname(sk->id), getskilldesc(sk->id)); + snprintf(buf, BUFLEN, "%s (%s)",getskillname(sk->id), getskilldesc(sk->id)); addchoice(&prompt, ch++, getskillname(sk->id), buf, sk); } getchoicestr(&prompt, B_FALSE, B_TRUE); @@ -1371,7 +1373,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef ch = 'a'; initprompt(&prompt, "How much will you learn this skill?"); for (i = getskill(user, sk->id) + 1 ; i <= PR_MASTER; i++) { - sprintf(buf, "%s",getskilllevelname(i)); + snprintf(buf, BUFLEN, "%s",getskilllevelname(i)); addchoice(&prompt, ch++, buf, buf, NULL); } if (prompt.nchoices <= 0) { @@ -1456,7 +1458,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef c = NULL; while (!c) { char ques[BUFLEN]; - sprintf(ques,"%s combination in which direction (- to cancel)", nhits ? "Continue" : "Start"); + snprintf(ques, BUFLEN,"%s combination in which direction (- to cancel)", nhits ? "Continue" : "Start"); dirch = askchar("%s combination in which direction (- to cancel)", "yuhjklbn-","-", B_FALSE); if (dirch == '-') { break; @@ -1514,7 +1516,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef target = where->lf; getlfname(target, lfname); - sprintf(question, "What job will you assign to %s",lfname); + snprintf(question, BUFLEN, "What job will you assign to %s",lfname); askstring(question, '?', buf, BUFLEN, NULL); j = findjobbyname(buf); if (j) { @@ -1561,7 +1563,6 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef char dirch; char targetname[BUFLEN]; flag_t *f; - int heavyamt = 5; int badweapon = B_FALSE; if (isswimming(user) && !lfhasflag(user, F_AQUATIC)) { @@ -1574,12 +1575,12 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (!hasjob(user, J_MONK)) { badweapon = B_TRUE; } - } else if (!ismeleeweapon(wep) || (getobunitweight(wep) < heavyamt)) { // ie. 8 is weight of a mace + } else if (!ismeleeweapon(wep) || !isheavyweapon(wep)) { badweapon = B_TRUE; } if (badweapon) { - if (isplayer(user)) msg("You need a heavy weapon (%dkg or more) to perform a heavy blow!", heavyamt); + if (isplayer(user)) msg("You need a heavy weapon (%dkg or more) to perform a heavy blow!", HEAVYWEPKG); return B_TRUE; } @@ -1722,8 +1723,8 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef // stealing from a lifeform // ask for direction if (!targcell) { - dirch = askchar("Steal in which direction (- to cancel)", "yuhjklbn-","-", B_FALSE); int dir; + dirch = askchar("Steal in which direction (- to cancel)", "yuhjklbn-","-", B_FALSE); dir = chartodir(dirch); if (dir == D_NONE) { if (isplayer(user)) msg("Cancelled."); @@ -1904,7 +1905,7 @@ int abilityeffects(lifeform_t *user, enum OBTYPE abilid, cell_t *targcell, lifef if (classok && !isknown(o)) { char buf[BUFLEN]; getobname(o, buf, o->amt); - addchoice(&prompt, o->letter, buf, NULL, f); + addchoice(&prompt, o->letter, buf, NULL, o); } } getchoice(&prompt); @@ -1982,7 +1983,8 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char castername[BUFLEN]; int rv = B_FALSE; objecttype_t *sp; - + flag_t *casttype; + sp = findot(spellid); if (caster) { @@ -2042,6 +2044,18 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ } } + // special: spit attacks need an animation + casttype = lfhasflag(caster, F_CASTTYPE); + if (casttype && (casttype->val[0] == CT_EYESPIT)) { + enum COLOUR col; + if (casttype->val[1] == NA) { + col = C_GREEN; + } else { + col = casttype->val[1]; + } + anim(caster->cell, targcell, '}', col); + } + // switch based on spell effects... if (spellid == OT_S_ABSORBMETAL) { int i; @@ -2125,8 +2139,8 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ dir = getdirtowards(caster->cell, targcell, target, B_FALSE, DT_COMPASS); } else { int dirch; - dirch = askchar("Airblast in which direction (- to cancel)", "yuhjklbn.-","-", B_FALSE); - if ((dirch == '.') || (dir == '-')) { + dirch = askchar("Airblast in which direction (- to cancel)", "yuhjklbn.-","-", B_FALSE); + if ((dirch == '.') || (dirch == '-')) { fizzle(caster); return B_TRUE; } @@ -2421,7 +2435,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ msg("%s burn%s!",buf,isplayer(c->lf) ? "" : "s"); } real_getlfname(caster, realcname, B_FALSE); - sprintf(damstring, "%s%s wave of fire", realcname, getpossessive(realcname)); + snprintf(damstring, BUFLEN, "%s%s wave of fire", realcname, getpossessive(realcname)); losehp(c->lf, rolldie(2,10), DT_FIRE, caster, damstring); } } @@ -2632,7 +2646,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ int range; int nsides = 6; - range = getspellrange(spellid, power); + range = getspellrange(caster, spellid, power); if (!validatespellcell(caster, &targcell, TT_MONSTER, spellid, power, frompot)) return B_TRUE; @@ -3048,7 +3062,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ askstring("Create what kind of monster", '?', buf, BUFLEN, NULL); } else { r = getreallyrandomrace(RC_ANY); - sprintf(buf, "%s", r->name); + snprintf(buf, BUFLEN, "%s", r->name); } // add the monster @@ -3719,7 +3733,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (isplayer(caster) || cansee(player, caster)) { if (seenbyplayer) *seenbyplayer = B_TRUE; } - brightflash(caster->cell, 2 + (power/4), player); + brightflash(caster->cell, 2 + (power/4), caster); } else if (spellid == OT_S_FLOATINGDISC) { lifeform_t *newlf; // get random adjacent cell @@ -4298,7 +4312,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (targcell->lf && cansee(player, targcell->lf)) { char lfname[BUFLEN]; getlfname(targcell->lf, lfname); - sprintf(underbuf, " under %s",lfname); + snprintf(underbuf, BUFLEN, " under %s",lfname); } else { strcpy(underbuf, ""); } @@ -4663,7 +4677,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char dambuf[BUFLEN]; char cname[BUFLEN]; real_getlfname(caster, cname, B_FALSE); - sprintf(dambuf, "%s%s infinite death spell", cname, getpossessive(cname)); + snprintf(dambuf, BUFLEN, "%s%s infinite death spell", cname, getpossessive(cname)); losehp(l, 500, DT_NECROTIC, NULL, dambuf); } } @@ -4679,7 +4693,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char dambuf[BUFLEN]; char cname[BUFLEN]; real_getlfname(caster, cname, B_FALSE); - sprintf(dambuf, "%s%s infinite death spell", cname, getpossessive(cname)); + snprintf(dambuf, BUFLEN, "%s%s infinite death spell", cname, getpossessive(cname)); losehp(caster, 500, DT_NECROTIC, NULL, dambuf); } } else if (spellid == OT_S_MANASPIKE) { @@ -4850,13 +4864,17 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (targcell && haslos(caster, targcell) && haslf(targcell)) { char targname[BUFLEN]; lifeform_t *oldplayer; + + // calc view + precalclos(targcell->lf); + // temporarily change player pointer... oldplayer = player; player = targcell->lf; // getlfname(targcell->lf, targname); - sprintf(buf, "Mindscanning %s, ESC to quit.", targname); + snprintf(buf, BUFLEN, "Mindscanning %s, 'v' to view info, ESC to quit.", targname); doexplain(buf); // restore player pointer @@ -5088,7 +5106,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (isplayer(caster)) { char buf[BUFLEN]; char ch; - sprintf(buf, "You may be stuck in %s%s body - proceed?", targname, + snprintf(buf, BUFLEN, "You may be stuck in %s%s body - proceed?", targname, getpossessive(targname)); ch = askchar(buf, "yn", "n", B_TRUE); if (ch != 'y') { @@ -5296,7 +5314,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (min < 1) min = 1; // ask which level - sprintf(query, "Create a portal to which level (%d-%d)",min,max); + snprintf(query, BUFLEN, "Create a portal to which level (%d-%d)",min,max); askstring(query, '?', buf, BUFLEN, NULL); newdepth = atoi(buf); @@ -5682,7 +5700,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ // ask for object askstring("Locate what kind of object", '?', wantname, BUFLEN, NULL); // find it in all maps! - sprintf(buf, "Locations of '%s':", wantname); + snprintf(buf, BUFLEN, "Locations of '%s':", wantname); initprompt(&prompt, buf); prompt.maycancel = B_TRUE; for (m = firstmap ; m ; m = m->next) { @@ -5972,9 +5990,9 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ getobname(o, obname, o->amt); if (isplayer(caster)) { - sprintf(fullobname, "Your %s", noprefix(obname)); + snprintf(fullobname, BUFLEN, "Your %s", noprefix(obname)); } else if (cansee(player, caster)) { - sprintf(fullobname, "%s%s %s", castername, getpossessive(castername), noprefix(obname)); + snprintf(fullobname, BUFLEN, "%s%s %s", castername, getpossessive(castername), noprefix(obname)); } else { strcpy(fullobname, ""); } @@ -6111,7 +6129,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char buf2[BUFLEN]; char targname[BUFLEN]; getlfname(target, targname); - sprintf(buf2, "What will you transform %s into", targname); + snprintf(buf2, BUFLEN, "What will you transform %s into", targname); askstring(buf2, '?', buf, BUFLEN, NULL); } r = findracebyname(buf); @@ -6435,7 +6453,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char buf[BUFLEN]; if (!validatespellcell(caster, &targcell,TT_NONE, spellid, power, frompot)) return B_TRUE; - sprintf(buf, "%s%s shatter spell", castername, getpossessive(castername)); + snprintf(buf, BUFLEN, "%s%s shatter spell", castername, getpossessive(castername)); if (!shattercell(targcell, caster, buf)) { fizzle(caster); } @@ -6579,9 +6597,9 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ redrawpause(); // add snow as follows (3 = medium, 2 = medium, 1 = smell) - // o - // ooo - // o + // * + // *** + // * if (targcell->lf) { losehp(targcell->lf, 1, DT_COLD, caster, "a snowball"); } else { @@ -6689,7 +6707,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ char buf[BUFLEN],corpsename[BUFLEN]; char ch; getobname(corpse, corpsename, 1); - sprintf(buf, "What will you ask %s?", corpsename); + snprintf(buf, BUFLEN, "What will you ask %s?", corpsename); initprompt(&prompt, buf); addchoice(&prompt, 'a', "How did you die?", NULL, NULL); addchoice(&prompt, '-', "(nothing)", NULL, NULL); @@ -6699,7 +6717,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ flag_t *f; char *p; - sprintf(buf, "%s whispers:", corpsename); + snprintf(buf, BUFLEN, "%s whispers:", corpsename); msg(buf); f = hasflag(corpse->flags, F_CORPSEOF); @@ -6712,7 +6730,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ } else { strcpy(weapon, ""); } - sprintf(buf, "\"I was killed by %s", killer); + snprintf(buf, BUFLEN, "\"I was killed by %s", killer); if (strlen(weapon)) { strcat(buf, ", "); strcat(buf, weapon); @@ -6969,7 +6987,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ } } else if (power >= 8) { // controlled - sprintf(buf, "Where will you teleport to?"); + snprintf(buf, BUFLEN, "Where will you teleport to?"); while (!c) { int ch; c = askcoords(buf, "Teleport->",TT_NONE, caster, UNLIMITED, LOF_DONTNEED, B_FALSE); @@ -6997,7 +7015,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ // semicontrolled // ask for dir dirch = askchar("Teleport in which direction (- to cancel)", "yuhjklbn.-","-", B_FALSE); - if ((dirch == '.') || (dir == '-')) { + if ((dirch == '.') || (dirch == '-')) { fizzle(caster); return B_TRUE; } else { @@ -7060,6 +7078,9 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ xmax = target->cell->x - 1; ymax = target->cell->y - 1; break; + default: // should never happen + fizzle(caster); + return B_FALSE; } if (xmin < 0) xmin = 0; @@ -7129,14 +7150,14 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ rv = B_FALSE; } else if (spellid == OT_S_TELEKINESIS) { - cell_t *where; + cell_t *where = NULL; int failed = B_FALSE; float maxweight; // if no target object... if (!targob) { // ask for a target cell (to take objects from) - sprintf(buf, "Where will you focus your telekinetic power?"); + snprintf(buf, BUFLEN, "Where will you focus your telekinetic power?"); where = askcoords(buf, "Telekinesis->", TT_OBJECT | TT_DOOR, caster, UNLIMITED, LOF_DONTNEED, B_FALSE); if (where && haslos(caster, where)) { if (where->obpile->first) { @@ -7169,9 +7190,9 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (!targcell) { char obname[BUFLEN],buf2[BUFLEN]; getobname(targob, obname, 1); - sprintf(buf, "Where will you throw %s to?", obname); + snprintf(buf, BUFLEN, "Where will you throw %s to?", obname); // TODO: start trail from the object - sprintf(buf2, "Telekinesis->%s->",obname); + snprintf(buf2, BUFLEN, "Telekinesis->%s->",obname); targcell = askcoords(buf, buf2,TT_MONSTER | TT_PLAYER, caster, UNLIMITED, LOF_DONTNEED, B_FALSE); } @@ -7341,7 +7362,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ f = hasflag(o->flags, F_DAM); if (f) { char buf[BUFLEN]; - sprintf(buf, "2d%d",power); + snprintf(buf, BUFLEN, "2d%d",power); changeflagtext(f, buf); } } else { @@ -7691,7 +7712,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ } } if (ch == 'a') { // wealth (gold, bad: goldtouch) - sprintf(buf, "1000-2000 gold coins"); + snprintf(buf, BUFLEN, "1000-2000 gold coins"); } else if (ch == 'b') { // power (weapons, bad: battery) skill_t *sk,*poss[MAXSKILLS]; int nposs = 0; @@ -7721,12 +7742,12 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ n++; } } - sprintf(buf, "excellent branded %s", ot->name); + snprintf(buf, BUFLEN, "excellent branded %s", ot->name); } else { - sprintf(buf, "stick"); + snprintf(buf, BUFLEN, "stick"); } } else { - sprintf(buf, "stick"); + snprintf(buf, BUFLEN, "stick"); } } else if (ch == 'c') { // protection. bad: turn to stone enum BODYPART bp,poss[MAXBODYPARTS]; @@ -7757,12 +7778,12 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ n++; } } - sprintf(buf, "excellent branded %s", ot->name); + snprintf(buf, BUFLEN, "excellent branded %s", ot->name); } else { - sprintf(buf, "sun hat"); + snprintf(buf, BUFLEN, "sun hat"); } } else { - sprintf(buf, "sun hat"); + snprintf(buf, BUFLEN, "sun hat"); } } else if (ch == 'd') { // fame (allies bad: useless allies) lifeform_t *lf; @@ -7840,7 +7861,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ if (nposs) { // pick a random spell from this list ot = poss[rnd(0,nposs-1)]; - sprintf(buf, "spellbook of %s",ot->name); + snprintf(buf, BUFLEN, "spellbook of %s",ot->name); } else { strcpy(buf, ""); } @@ -7879,9 +7900,9 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ // ask for an object if (spellid == OT_S_GIFT) { - sprintf(question, "What gift will %s receive",lfname); + snprintf(question, BUFLEN, "What gift will %s receive",lfname); } else { - sprintf(question, "For what do you wish"); + snprintf(question, BUFLEN, "For what do you wish"); } askstring(question, '?', buf, BUFLEN, NULL); addob(target->cell->obpile, buf); @@ -8047,10 +8068,10 @@ char *getspellcosttext(lifeform_t *lf, enum OBTYPE spellid, int power, char *buf if (hasflag(ot->flags, F_ONGOING)) ongoing = B_TRUE; if (hasflag(ot->flags, F_VARPOWER)) { - sprintf(buf, "%d-%d MP%s", cost, + snprintf(buf, BUFLEN, "%d-%d MP%s", cost, cost * power, ongoing ? ", ongoing" : ""); } else { - sprintf(buf, "%d MP%s", cost, ongoing ? ", ongoing" : ""); + snprintf(buf, BUFLEN, "%d MP%s", cost, ongoing ? ", ongoing" : ""); } return buf; @@ -8355,9 +8376,23 @@ enum SKILLLEVEL getspellskill(lifeform_t *lf, enum OBTYPE spellid) { return slev; } -int getspellrange(enum OBTYPE spellid, int power) { +int getspellrange(lifeform_t *lf, enum OBTYPE spellid, int power) { objecttype_t *st; int range = UNLIMITED; + + // If we can _will_ this to occur then we might have a set + // range + if (lf) { + flag_t *f; + f = lfhasflagval(lf, F_CANWILL, spellid, NA, NA, NULL); + if (f && strlen(f->text)) { + texttospellopts(f->text, NULL, NULL, NULL, &range); + if (range > 0) { + return range; + } + } + } + st = findot(spellid); if (st) { flag_t *f; @@ -8395,20 +8430,20 @@ char *getvarpowerspelldesc(enum OBTYPE spellid, int power, char *buf) { strcpy(buf, ""); switch (spellid) { case OT_S_PSYARMOUR: - sprintf(buf, "+%d Armour Rating", power*4); + snprintf(buf, BUFLEN, "+%d Armour Rating", power*4); break; case OT_S_SUMMONWEAPON: - sprintf(buf, "Create a 2d%d damage magical weapon",power); + snprintf(buf, BUFLEN, "Create a 2d%d damage magical weapon",power); break; case OT_S_TRUESTRIKE: if (power == 1) { - sprintf(buf, "Next attack automatically hits"); + snprintf(buf, BUFLEN, "Next attack automatically hits"); } else { - sprintf(buf, "Next %d attacks automatically hit",power); + snprintf(buf, BUFLEN, "Next %d attacks automatically hit",power); } break; case OT_S_WINDSHIELD: - sprintf(buf, "Protection from missiles <= %d km/h",speedtokph(power)); + snprintf(buf, BUFLEN, "Protection from missiles <= %d km/h",speedtokph(power)); break; default: break; @@ -8440,7 +8475,7 @@ void pullobto(object_t *o, lifeform_t *lf) { int dir; cell_t *obloc,*newcell; - sprintf(buf, "a flying %s", noprefix(obname)); + snprintf(buf, BUFLEN, "a flying %s", noprefix(obname)); if (isplayer(lf) || haslos(player, lf->cell)) { msg("%s %s into %s!", obname, (o->amt == 1) ? "slams" : "slam", lfname); @@ -8694,8 +8729,8 @@ lifeform_t *validateabillf(lifeform_t *user, enum OBTYPE aid, lifeform_t **targe if (isplayer(user)) { cell_t *where; char buf[BUFLEN],buf2[BUFLEN]; - sprintf(buf, "Where will you target your %s?",ot->name); - sprintf(buf2, "%s->",ot->name); + snprintf(buf, BUFLEN, "Where will you target your %s?",ot->name); + snprintf(buf2, BUFLEN, "%s->",ot->name); where = askcoords(buf, buf2, TT_MONSTER, user, maxrange, LOF_DONTNEED, B_FALSE); if (where) { if (!haslf(where)) { @@ -8748,8 +8783,7 @@ cell_t *validatespellcell(lifeform_t *caster, cell_t **targcell, int targtype, e needlos = B_FALSE; } - - maxrange = getspellrange(spellid, power); + maxrange = getspellrange(caster, spellid, power); if (*targcell) where = *targcell; @@ -8802,11 +8836,11 @@ cell_t *validatespellcell(lifeform_t *caster, cell_t **targcell, int targtype, e char ques[BUFLEN]; int ch; if (isplayer(where->lf)) { - sprintf(ques,"Really target yourself"); + snprintf(ques, BUFLEN,"Really target yourself"); } else { char lfname[BUFLEN]; getlfname(where->lf, lfname); - sprintf(ques, "Really target %s", lfname); + snprintf(ques, BUFLEN, "Really target %s", lfname); } ch = askchar(ques,"yn","n", B_TRUE); if (ch != 'y') { @@ -8830,11 +8864,11 @@ cell_t *validatespellcell(lifeform_t *caster, cell_t **targcell, int targtype, e objecttype_t *ot; ot = findot(spellid); if (maxrange == UNLIMITED) { - sprintf(buf, "Where will you target your %s?", ot->name); + snprintf(buf, BUFLEN, "Where will you target your %s?", ot->name); } else { - sprintf(buf, "Where will you target your %s [max range %d]?",ot->name, maxrange); + snprintf(buf, BUFLEN, "Where will you target your %s [max range %d]?",ot->name, maxrange); } - sprintf(buf2, "%s->",ot->name); + snprintf(buf2, BUFLEN, "%s->",ot->name); where = askcoords(buf, buf2, targtype, caster, maxrange, needlof, needlof ? B_TRUE : B_FALSE); if (!where) { int ch; @@ -8861,6 +8895,38 @@ cell_t *validatespellcell(lifeform_t *caster, cell_t **targcell, int targtype, e } } + // eye protection will stop some spells! + if (*targcell && (*targcell)->lf) { + flag_t *casttype; + lifeform_t *victim; + victim = (*targcell)->lf; + casttype = lfhasflag(caster, F_CASTTYPE); + if (casttype) { + object_t *glasses = NULL; + switch (casttype->val[0]) { + case CT_EYESPIT: + case CT_GAZE: + glasses = eyesshaded(victim); + if (glasses) { + if (isplayer(victim)) { + char gbuf[BUFLEN]; + getobname(glasses, gbuf, glasses->amt); + msg("Your %s protects you.", noprefix(gbuf)); + } else if (cansee(player, victim)) { + char lfname[BUFLEN],gbuf[BUFLEN]; + getobname(glasses, gbuf, glasses->amt); + getlfname(caster, lfname); + msg("%s%s %s protects it.", lfname, getpossessive(lfname), noprefix(gbuf) ); + } + *targcell = NULL; + } + break; + default: + break; + } + } + } + return *targcell; } @@ -8916,31 +8982,3 @@ int getmpcost(lifeform_t *lf, enum OBTYPE oid) { } -/* -lifeform_t *validatespelllf(lifeform_t *caster, lifeform_t **target) { - if (!caster) { - return *target; - } - if (*target) { - return *target; - } - // ask for a target lifeform - if (isplayer(caster)) { - cell_t *where; - char buf[BUFLEN]; - sprintf(buf, "Where will you target your spell?"); - where = askcoords(buf, TT_MONSTER, caster, UNLIMITED); - if (where && haslos(caster, where) && haslf(where)) { - *target = haslf(where); - } else { - fizzle(caster); - return NULL; - } - } else { - // TODO: fill in monster code? - fizzle(caster); - return NULL; - } - return *target; -} -*/ diff --git a/spell.h b/spell.h index 3f3be2b..bbe6f86 100644 --- a/spell.h +++ b/spell.h @@ -19,7 +19,7 @@ int getspellpower(lifeform_t *lf, enum OBTYPE spellid); enum SPELLSCHOOL getspellschool(enum OBTYPE spellid); enum SPELLSCHOOL getspellschoolknown(lifeform_t *lf, enum OBTYPE spellid); enum SKILLLEVEL getspellskill(lifeform_t *lf, enum OBTYPE spellid); -int getspellrange(enum OBTYPE spellid, int power); +int getspellrange(lifeform_t *lf, enum OBTYPE spellid, int power); char *getvarpowerspelldesc(enum OBTYPE spellid, int power, char *buf); void pullobto(object_t *o, lifeform_t *lf); int schoolappearsinbooks(enum SPELLSCHOOL ss); diff --git a/text.c b/text.c index 98100c9..2d83f6d 100644 --- a/text.c +++ b/text.c @@ -97,22 +97,22 @@ char *dicetotext(int ndice, int nsides, int bonus, int *min, int *max, char *dic if (dicebuf) { if ((ndice == 0) || (nsides == 0)) { - sprintf(dicebuf, "%d", bonus); + snprintf(dicebuf, BUFLEN, "%d", bonus); } else { if (bonus) { - sprintf(dicebuf, "%dd%d%c%d", ndice, nsides, + snprintf(dicebuf, BUFLEN, "%dd%d%c%d", ndice, nsides, (bonus > 0) ? '+' : '-', abs(bonus)); } else { - sprintf(dicebuf, "%dd%d", ndice, nsides); + snprintf(dicebuf, BUFLEN, "%dd%d", ndice, nsides); } } } if (minmaxbuf) { if (localmin == localmax) { - sprintf(minmaxbuf, "%d", localmin); + snprintf(minmaxbuf, BUFLEN, "%d", localmin); } else { - sprintf(minmaxbuf, "%d-%d", localmin, localmax); + snprintf(minmaxbuf, BUFLEN, "%d-%d", localmin, localmax); } } return dicebuf; @@ -193,7 +193,7 @@ char *getattrname(enum ATTRIB att) { int gethitconferlifetime(char *text, int *min, int *max) { int howlong; - int localmin,localmax; + int localmin = -1,localmax = -1; if (text) { char loctext[BUFLEN]; char *word, *dummy; @@ -332,7 +332,7 @@ char *gettimetext(char *retbuf) { int hours,mins,secs; splittime(&hours, &mins, &secs); - sprintf(retbuf, "%02d:%02d:%02d",hours,mins,secs); + snprintf(retbuf, BUFLEN, "%02d:%02d:%02d",hours,mins,secs); return retbuf; } @@ -347,17 +347,17 @@ char *gettimetextfuzzy(char *retbuf, int wantpm) { } if (mins == 0) { - sprintf(retbuf, "exactly %d o'clock", hours); + snprintf(retbuf, BUFLEN, "exactly %d o'clock", hours); } else if (mins <= 15) { - sprintf(retbuf, "a little after %d o'clock", hours); + snprintf(retbuf, BUFLEN, "a little after %d o'clock", hours); } else if (mins <= 25) { - sprintf(retbuf, "nearly half past %d", hours); + snprintf(retbuf, BUFLEN, "nearly half past %d", hours); } else if (mins <= 35) { - sprintf(retbuf, "around half past %d", hours); + snprintf(retbuf, BUFLEN, "around half past %d", hours); } else if (mins <= 45) { - sprintf(retbuf, "coming up to %d o'clock", (hours == 12) ? 1 : (hours+1)); + snprintf(retbuf, BUFLEN, "coming up to %d o'clock", (hours == 12) ? 1 : (hours+1)); } else { - sprintf(retbuf, "nearly %d o'clock", (hours == 12) ? 1 : (hours+1)); + snprintf(retbuf, BUFLEN, "nearly %d o'clock", (hours == 12) ? 1 : (hours+1)); } if (wantpm) { @@ -404,15 +404,15 @@ char *getwaterdepthname(enum DEPTH d) { char *getweighttext(float weight, char *buf) { if (weight == 0) { - sprintf(buf, "nothing"); + snprintf(buf, BUFLEN, "nothing"); } else if (weight >= 1) { if ((int)weight == weight) { // ie. is weight an integer? - sprintf(buf, "%0.0f kg",weight); + snprintf(buf, BUFLEN, "%0.0f kg",weight); } else { - sprintf(buf, "%0.1f kg",weight); + snprintf(buf, BUFLEN, "%0.1f kg",weight); } } else { - sprintf(buf, "%0.0f grams", weight * 1000); + snprintf(buf, BUFLEN, "%0.0f grams", weight * 1000); } return buf; } @@ -441,7 +441,7 @@ char *makekillertext(char *retbuf, char *lastdam, int wantextra) { if (!strcmp(p, "you")) { strcpy(retbuf, "Committed suicide."); } else { - sprintf(retbuf, "Killed by %s.",p); + snprintf(retbuf, BUFLEN, "Killed by %s.",p); } if (wantextra) { p = strtok_r(NULL, "^", &dummy); @@ -579,37 +579,37 @@ char *noprefix(char *obname) { char *numtotext(int num, char *buf) { switch (num) { case 1: - sprintf(buf, "a"); + snprintf(buf, BUFLEN, "a"); break; case 2: - sprintf(buf, "two"); + snprintf(buf, BUFLEN, "two"); break; case 3: - sprintf(buf, "three"); + snprintf(buf, BUFLEN, "three"); break; case 4: - sprintf(buf, "four"); + snprintf(buf, BUFLEN, "four"); break; case 5: - sprintf(buf, "five"); + snprintf(buf, BUFLEN, "five"); break; case 6: - sprintf(buf, "six"); + snprintf(buf, BUFLEN, "six"); break; case 7: - sprintf(buf, "seven"); + snprintf(buf, BUFLEN, "seven"); break; case 8: - sprintf(buf, "eight"); + snprintf(buf, BUFLEN, "eight"); break; case 9: - sprintf(buf, "nine"); + snprintf(buf, BUFLEN, "nine"); break; case 10: - sprintf(buf, "ten"); + snprintf(buf, BUFLEN, "ten"); break; default: - sprintf(buf, "%d",num); + snprintf(buf, BUFLEN, "%d",num); break; } return buf;