From 9481e41701a6872f7d30ea8c6d80fa2c76a315f5 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Tue, 26 Jul 2011 02:26:19 +0000 Subject: [PATCH] * [+] bag of holding - [+] change getobpileweight() to traverse into containers! --- defs.h | 9 +++++ io.c | 6 ++- lf.c | 2 +- objects.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++--- text.c | 2 + 5 files changed, 125 insertions(+), 7 deletions(-) diff --git a/defs.h b/defs.h index c64ed2b..5d4367e 100644 --- a/defs.h +++ b/defs.h @@ -1159,6 +1159,9 @@ enum OBTYPE { // tools - unique OT_ORBDUNGEONEXIT, // tools + OT_BAGOFHOLDING, + OT_BAGOFHOLDINGLARGE, + OT_BAGOFHOLDINGHUGE, OT_BLANKET, OT_BLINDFOLD, OT_BUGLAMP, @@ -1171,6 +1174,7 @@ enum OBTYPE { OT_PICKAXE, OT_ROPE, OT_SACK, + OT_SACKLARGE, OT_SACKHUGE, OT_SAFEBOX, OT_TORCH, @@ -1643,6 +1647,9 @@ enum FLAG { // -1 means "nutrition is weight x abs(val1)" // if v2=DONTKILL, this object does NOT die when drunk. F_OPERABLE, // can operate? + F_OPERWITHOUTID, // can operate without knowing what it is? + F_NOTRIED, // don't show '[tried]' or update knowledge + // after you have tried this object. F_POURABLE, // can pour? F_PUSHABLE, // can push this object F_PICKLOCKS, // can pick locks? val0=% change, @@ -1870,6 +1877,8 @@ enum FLAG { // v1 = depth modifier. can use 'RANDOM' F_CONTAINER, // this object is a container - you can use 'o' // to take stuff out or put it in. + F_HOLDING, // this container is a xxx of holding and makes objects + // inside become weightless F_STARTJOB, // val0 = %chance of starting with it, v1 = jobid F_STARTSKILL, // val0 = skill id F_STARTATT, // val0 = A_xxx, val0 = start bracket (ie. IQ_GENIUS) diff --git a/io.c b/io.c index ae359b7..404f371 100644 --- a/io.c +++ b/io.c @@ -4364,7 +4364,11 @@ void dodrop(obpile_t *op, int wantmulti, obpile_t *dst) { getobname(o, buf, o->amt); msg("You put %s into %s.",buf, toname); } else { - msg("You can't put %s into %s.",buf, toname); + if (reason == E_NOSPACE) { + msg("%s won't fit into %s.",buf, toname); + } else { + msg("You can't put %s into %s.",buf, toname); + } } } else { drop(o, count); diff --git a/lf.c b/lf.c index fa59c91..3d3c9c0 100644 --- a/lf.c +++ b/lf.c @@ -8065,7 +8065,7 @@ void initrace(void) { addflag(lastrace->flags, F_ACTIONSPEED, SP_SLOW, NA, NA, NULL); addflag(lastrace->flags, F_HASATTACK, OT_FISTS, NA, NA, "1d2"); addflag(lastrace->flags, F_STARTOB, 100, NA, NA, "blessed ring of hunger"); - addflag(lastrace->flags, F_STARTOB, 100, NA, NA, "10 huge sacks"); + addflag(lastrace->flags, F_STARTOB, 100, NA, NA, "10 huge bags of holding"); //addflag(lastrace->flags, F_WANTS, OT_GOLD, NA, NA, NULL); addflag(lastrace->flags, F_WANTSOBFLAG, F_RARITY, NA, NA, NULL); // ie. everything addflag(lastrace->flags, F_HUMANOID, B_TRUE, NA, NA, NULL); diff --git a/objects.c b/objects.c index cf70d64..74e4c44 100644 --- a/objects.c +++ b/objects.c @@ -2661,6 +2661,7 @@ objecttype_t *findotn(char *name) { // make some replacements //replace scrolls with scroll etc + modname = strrep(modname, "bags ", "bag ", NULL); modname = strrep(modname, "berries ", "berry ", NULL); modname = strrep(modname, "blocks ", "block ", NULL); modname = strrep(modname, "cans ", "can ", NULL); @@ -3868,7 +3869,18 @@ char *getobdesc(object_t *o, char *buf) { sprintf(buf, "%s", o->type->desc); } } else { - sprintf(buf, "%s", o->type->obclass->desc); + objecttype_t *ot = NULL; + flag_t *f; + f = hasflag(o->flags, F_HASHIDDENNAME); + if (f) { + ot = findotn(f->text); + } + + if (ot) { + sprintf(buf, "%s", ot->desc); + } else { + sprintf(buf, "%s", o->type->obclass->desc); + } } return buf; } @@ -4547,6 +4559,10 @@ char *real_getobname(object_t *o, char *buf, int count, int wantpremods, int wan float getobpileweight(obpile_t *op) { object_t *o; float weight = 0; + if (op->parentob && hasflag(op->parentob->flags, F_HOLDING)) { + return 0; + } + for (o = op->first ; o ; o = o->next) { weight += getobweight(o); } @@ -4632,6 +4648,13 @@ float getobweight(object_t *o) { float weight; weight = getobunitweight(o) * o->amt; + + // object contents + if (hasflag(o->flags, F_CONTAINER) && !hasflag(o->flags, F_HOLDING)) { + float containerweight = 0; + containerweight = getobpileweight(o->contents); + weight += containerweight; + } return weight; } @@ -4640,6 +4663,11 @@ float getobunitweight(object_t *o) { float weight; flag_t *f; + // bag of holding? + if (o->pile->parentob && hasflag(o->pile->parentob->flags, F_HOLDING)) { + return 0; + } + if (o->type->id == OT_WATERDEEP) { weight = 75 * getobdepth(o, NULL); } else { @@ -5641,6 +5669,7 @@ void initobjects(void) { addflag(lastobjectclass->flags, F_DTIMMUNE, DT_FIRE, NA, NA, NULL); addflag(lastobjectclass->flags, F_HASHIDDENNAME, B_TRUE, NA, NA, NULL); addflag(lastobjectclass->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); + addflag(lastobjectclass->flags, F_OPERWITHOUTID, B_TRUE, NA, NA, NULL); addflag(lastobjectclass->flags, F_OPERUSECHARGE, B_TRUE, NA, NA, NULL); addflag(lastobjectclass->flags, F_RNDCHARGES, 1, 8, NA, NULL); @@ -7550,7 +7579,7 @@ void initobjects(void) { addflag(lastot->flags, F_RARITY, H_FOREST, 75, NA, NULL); addflag(lastot->flags, F_HELPSCLIMB, 3, NA, NA, NULL); - addot(OT_SACK, "sack", "A small cloth sack.", MT_CLOTH, 1, OC_TOOLS, SZ_SMALL); + addot(OT_SACK, "sack", "A small cloth sack.", MT_CLOTH, 0.5, OC_TOOLS, SZ_SMALL); addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_COMMON, NULL); addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); @@ -7562,6 +7591,18 @@ void initobjects(void) { addflag(lastot->flags, F_STARTOBRND, 30, NA, NA, NULL); addflag(lastot->flags, F_STARTOBRND, 10, NA, NA, NULL); + addot(OT_SACKLARGE, "large sack", "A large cloth sack.", MT_CLOTH, 1, OC_TOOLS, SZ_MEDIUM); + addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); + addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_DAMAGABLE, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OBHP, 50, 50, NA, NULL); + addflag(lastot->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_CONTAINER, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addot(OT_SACKHUGE, "huge sack", "An enormous cloth sack.", MT_CLOTH, 1, OC_TOOLS, SZ_LARGE); addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); @@ -7578,6 +7619,55 @@ void initobjects(void) { addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + + addot(OT_BAGOFHOLDING, "bag of holding", "A magical sack which causes items placed inside it to become weightless.", MT_CLOTH, 0.5, OC_TOOLS, SZ_SMALL); + addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_RARE, NULL); + addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); + addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERWITHOUTID, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_NOTRIED, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_CONTAINER, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_HOLDING, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 30, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 10, NA, NA, NULL); + addflag(lastot->flags, F_HASHIDDENNAME, B_TRUE, NA, NA, "sack"); + + addot(OT_BAGOFHOLDINGLARGE, "large bag of holding", "A large magical sack which causes items placed inside it to become weightless.", MT_CLOTH, 0.5, OC_TOOLS, SZ_MEDIUM); + addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_RARE, NULL); + addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); + addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERWITHOUTID, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_NOTRIED, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_CONTAINER, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_HOLDING, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_HASHIDDENNAME, B_TRUE, NA, NA, "large sack"); + + addot(OT_BAGOFHOLDINGHUGE, "huge bag of holding", "An enormous magical sack which causes items placed inside it to become weightless.", MT_CLOTH, 0.5, OC_TOOLS, SZ_LARGE); + addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_VERYRARE, NULL); + addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); + addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERWITHOUTID, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_NOTRIED, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_OPERABLE, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_CONTAINER, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_HOLDING, B_TRUE, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 100, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_STARTOBRND, 50, NA, NA, NULL); + addflag(lastot->flags, F_HASHIDDENNAME, B_TRUE, NA, NA, "huge sack"); + addot(OT_SAFEBOX, "safebox", "A small metal container for safely storing valuables.", MT_METAL, 2, OC_TOOLS, SZ_SMALL); addflag(lastot->flags, F_RARITY, H_DUNGEON, 77, RR_UNCOMMON, NULL); addflag(lastot->flags, F_GLYPH, C_YELLOW, NA, NA, "("); @@ -10189,6 +10279,13 @@ void makeknown(enum OBTYPE otid) { void maketried(enum OBTYPE otid) { knowledge_t *k; + objecttype_t *ot; + + // avoid adding '[tried]' to certain objects + ot = findot(otid); + if (ot && hasflag(ot->flags, F_NOTRIED)) { + return; + } for (k = knowledge; k ; k = k->next) { if (k->id == otid) { @@ -10901,9 +10998,15 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) { // if not a wand, must know what a tool is before you can use it // also use the same message whn you try to operate something non-operable - // to avoid using this to identify mistletoe. - if (!isoperable(o) || - (!isknown(o) && (o->type->obclass->id != OC_WAND)) ) { + // to avoid using this to identify mistletoe, etc. + if (!isoperable(o)) { + if (isplayer(lf)) { + msg("You don't know how to use %s!", obname); + } + return B_TRUE; + } + + if (!isknown(o) && !hasflag(o->flags, F_OPERWITHOUTID)) { if (isplayer(lf)) { msg("You don't know how to use %s!", obname); } diff --git a/text.c b/text.c index 7741f06..92898a1 100644 --- a/text.c +++ b/text.c @@ -398,6 +398,8 @@ char *makeplural(char *text) { newtext = strdup(text); // scrolls + newtext = strrep(newtext, "bag ", "bags ", &rv); + if (rv) return newtext; newtext = strrep(newtext, "berry ", "berries ", &rv); if (rv) return newtext; newtext = strrep(newtext, "block ", "blocks ", &rv);