X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=misc.c;h=35c4e4b46b1f41dbf60f2aac877d6c6bd88b8dbf;hb=9af3ab4ecddbd6dd0347a4adc54a98b5153a9fb6;hp=6db040a1fb3c0f755b3a741d5d9646845df698e5;hpb=5f4df123b40b8d9c01b88bc506ee5bb8b3c82d70;p=open-adventure.git diff --git a/misc.c b/misc.c index 6db040a..35c4e4b 100644 --- a/misc.c +++ b/misc.c @@ -35,6 +35,7 @@ static void* xcalloc(size_t size) /* I/O routines (speak, pspeak, rspeak, sspeak, get_input, yes) */ static void vspeak(const char* msg, bool blank, va_list ap) +/* Engine for various speak functions */ { // Do nothing if we got a null pointer. if (msg == NULL) @@ -122,6 +123,7 @@ static void vspeak(const char* msg, bool blank, va_list ap) } void speak(const char* msg, ...) +/* speak a specified string */ { va_list ap; va_start(ap, msg); @@ -130,6 +132,7 @@ void speak(const char* msg, ...) } void sspeak(const int msg, ...) +/* Speak a message from the arbitrary-messages list */ { va_list ap; va_start(ap, msg); @@ -211,7 +214,7 @@ static int word_count(char* str) static char* get_input(void) { // Set up the prompt - char input_prompt[] = "> "; + char input_prompt[] = PROMPT; if (!settings.prompt) input_prompt[0] = '\0'; @@ -220,7 +223,7 @@ static char* get_input(void) char* input; while (true) { - input = readline(input_prompt); + input = myreadline(input_prompt); if (input == NULL) // Got EOF; return with it. return (input); @@ -246,7 +249,7 @@ static char* get_input(void) return (input); } -bool silent_yes(void) +bool silent_yes_or_no(void) { bool outcome = false; @@ -295,7 +298,7 @@ bool silent_yes(void) } -bool yes(const char* question, const char* yes_response, const char* no_response) +bool yes_or_no(const char* question, const char* yes_response, const char* no_response) /* Print message X, wait for yes/no answer. If yes, print Y and return true; * if no, print Z and return false. */ { @@ -483,7 +486,7 @@ static void tokenize(char* raw, command_t *cmd) /* Bound prefix on the %s would be needed to prevent buffer * overflow. but we shortstop this more simply by making each - * raw-input buffer as long as the entire input buffer. */ + * raw-input buffer as int as the entire input buffer. */ sscanf(raw, "%s%s", cmd->word[0].raw, cmd->word[1].raw); /* (ESR) In oldstyle mode, simulate the uppercasing and truncating @@ -544,7 +547,7 @@ bool get_command_input(command_t *command) const char *types[] = {"NO_WORD_TYPE", "MOTION", "OBJECT", "ACTION", "NUMERIC"}; /* needs to stay synced with enum speechpart */ const char *roles[] = {"unknown", "intransitive", "transitive"}; - printf("Command: role = %s type1 = %s, id1 = %ld, type2 = %s, id2 = %ld\n", + printf("Command: role = %s type1 = %s, id1 = %d, type2 = %s, id2 = %d\n", roles[command->part], types[command->word[0].type], command->word[0].id, @@ -556,6 +559,17 @@ bool get_command_input(command_t *command) return true; } +void clear_command(command_t *cmd) +/* Resets the state of the command to empty */ +{ + cmd->verb = ACT_NULL; + cmd->part = unknown; + game.oldobj = cmd->obj; + cmd->obj = NO_OBJECT; + cmd->state = EMPTY; +} + + void juggle(obj_t object) /* Juggle an object by picking it up and putting it down again, the purpose * being to get the object to the front of the chain of things at its loc. */ @@ -586,7 +600,7 @@ void move(obj_t object, loc_t where) drop(object, where); } -loc_t put(obj_t object, loc_t where, long pval) +loc_t put(obj_t object, loc_t where, int pval) /* put() is the same as move(), except it returns a value used to set up the * negated game.prop values for the repository objects. */ { @@ -599,7 +613,7 @@ void carry(obj_t object, loc_t where) * location. Incr holdng unless it was already being toted. If object>NOBJECTS * (moving "fixed" second loc), don't change game.place or game.holdng. */ { - long temp; + int temp; if (object <= NOBJECTS) { if (game.place[object] == CARRIED) @@ -622,7 +636,7 @@ void carry(obj_t object, loc_t where) void drop(obj_t object, loc_t where) /* Place an object at a given loc, prefixing it onto the game.atloc list. Decr - * game.holdng if the object was being toted. */ + * game.holdng if the object was being toted. No state change on the object. */ { if (object > NOBJECTS) game.fixed[object - NOBJECTS] = where; @@ -656,7 +670,7 @@ int atdwrf(loc_t where) if (game.dflag < 2) return at; at = -1; - for (long i = 1; i <= NDWARVES - 1; i++) { + for (int i = 1; i <= NDWARVES - 1; i++) { if (game.dloc[i] == where) return i; if (game.dloc[i] != 0) @@ -668,13 +682,13 @@ int atdwrf(loc_t where) /* Utility routines (setbit, tstbit, set_seed, get_next_lcg_value, * randrange) */ -long setbit(int bit) +int setbit(int bit) /* Returns 2**bit for use in constructing bit-masks. */ { return (1L << bit); } -bool tstbit(long mask, int bit) +bool tstbit(int mask, int bit) /* Returns true if the specified bit is set in the mask. */ { return (mask & (1 << bit)) != 0; @@ -717,8 +731,6 @@ void bug(enum bugtype num, const char *error_string) } // LCOV_EXCL_STOP -/* end */ - void state_change(obj_t obj, int state) /* Object must have a change-message list for this to be useful; only some do */ {