X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=d4c995597011c11e2960a6ba275421acad68f920;hb=3a93b2b5f08351c3e87d4f41c5c61273c42e9420;hp=b6230ec618454ede5a1d3dfb11fe97faf5697060;hpb=deb61e3dcd060dac685feb71aa21e52165fd8691;p=open-adventure.git diff --git a/misc.c b/misc.c index b6230ec..d4c9955 100644 --- a/misc.c +++ b/misc.c @@ -21,16 +21,6 @@ void* xmalloc(size_t size) return (ptr); } -char* xstrdup(const char* s) -{ - char* ptr = strdup(s); - if (ptr == NULL) { - fprintf(stderr, "Out of memory!\n"); - exit(EXIT_FAILURE); - } - return (ptr); -} - void packed_to_token(long packed, char token[6]) { // Unpack and map back to ASCII. @@ -111,6 +101,8 @@ void vspeak(const char* msg, va_list ap) size--; } else { long arg = va_arg(ap, long); + if (arg == -1) + arg = 0; i++; // Integer specifier. In order to accommodate the fact that PARMS can have both legitimate integers *and* packed tokens, stringify everything. Future work may eliminate the need for this. if (msg[i] == 'd') { @@ -169,17 +161,29 @@ void speak(const char* msg, ...) va_end(ap); } -void pspeak(vocab_t msg, int skip, ...) -/* Find the skip+1st message from msg and print it. msg should be - * the index of the inventory message for object. (INVEN+N+1 message - * is game.prop=N message). */ +void pspeak(vocab_t msg, enum speaktype mode, int skip, ...) +/* Find the skip+1st message from msg and print it. Modes are: + * feel = for inventory, what you can touch + * look = the long description for the state the object is in + * listen = the sound for the state the object is in + * study = text on the object. */ { va_list ap; va_start(ap, skip); - if (skip >= 0) - vspeak(object_descriptions[msg].longs[skip], ap); - else + switch (mode) { + case touch: vspeak(object_descriptions[msg].inventory, ap); + break; + case look: + vspeak(object_descriptions[msg].longs[skip], ap); + break; + case hear: + vspeak(object_descriptions[msg].sounds[skip], ap); + break; + case study: + vspeak(object_descriptions[msg].texts[skip], ap); + break; + } va_end(ap); }