projects
/
open-adventure.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Purge magic numbers from C side of destination handling.
[open-adventure.git]
/
misc.c
diff --git
a/misc.c
b/misc.c
index a2626b4d3f02ae66ea69ed4dbf99c4c1939debe0..cef36519e82e5d9d250da92e4784373b234f8461 100644
(file)
--- a/
misc.c
+++ b/
misc.c
@@
-328,11
+328,12
@@
char* get_input()
if (input == NULL) // Got EOF; return with it.
return (input);
if (input == NULL) // Got EOF; return with it.
return (input);
-
else
if (input[0] == '#') { // Ignore comments.
+ if (input[0] == '#') { // Ignore comments.
free(input);
continue;
free(input);
continue;
- } else // We have a 'normal' line; leave the loop.
- break;
+ }
+ // We have a 'normal' line; leave the loop.
+ break;
}
// Strip trailing newlines from the input
}
// Strip trailing newlines from the input
@@
-351,7
+352,7
@@
char* get_input()
bool silent_yes()
{
bool silent_yes()
{
- bool outcome;
+ bool outcome
= false
;
for (;;) {
char* reply = get_input();
for (;;) {
char* reply = get_input();
@@
-362,6
+363,11
@@
bool silent_yes()
exit(EXIT_SUCCESS);
// LCOV_EXCL_STOP
}
exit(EXIT_SUCCESS);
// LCOV_EXCL_STOP
}
+ if (strlen(reply) == 0) {
+ free(reply);
+ rspeak(PLEASE_ANSWER);
+ continue;
+ }
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
@@
-397,12
+403,12
@@
bool yes(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. */
{
/* Print message X, wait for yes/no answer. If yes, print Y and return true;
* if no, print Z and return false. */
{
- bool outcome;
+ bool outcome
= false
;
for (;;) {
speak(question);
for (;;) {
speak(question);
- char*
reply = get_input();
+ char* reply = get_input();
if (reply == NULL) {
// LCOV_EXCL_START
// Should be unreachable. Reply should never be NULL
if (reply == NULL) {
// LCOV_EXCL_START
// Should be unreachable. Reply should never be NULL
@@
-411,6
+417,12
@@
bool yes(const char* question, const char* yes_response, const char* no_response
// LCOV_EXCL_STOP
}
// LCOV_EXCL_STOP
}
+ if (strlen(reply) == 0) {
+ free(reply);
+ rspeak(PLEASE_ANSWER);
+ continue;
+ }
+
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
char* firstword = (char*) xmalloc(strlen(reply) + 1);
sscanf(reply, "%s", firstword);
@@
-535,11
+547,11
@@
long get_vocab_id(const char* word)
return (WORD_NOT_FOUND);
}
return (WORD_NOT_FOUND);
}
-void juggle(
long
object)
+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. */
{
/* 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. */
{
- lo
ng
i, j;
+ lo
c_t
i, j;
i = game.place[object];
j = game.fixed[object];
i = game.place[object];
j = game.fixed[object];
@@
-547,7
+559,7
@@
void juggle(long object)
move(object + NOBJECTS, j);
}
move(object + NOBJECTS, j);
}
-void move(
long object, long
where)
+void move(
obj_t object, loc_t
where)
/* Place any object anywhere by picking it up and dropping it. May
* already be toting, in which case the carry is a no-op. Mustn't
* pick up objects which are not at any loc, since carry wants to
/* Place any object anywhere by picking it up and dropping it. May
* already be toting, in which case the carry is a no-op. Mustn't
* pick up objects which are not at any loc, since carry wants to
@@
-564,15
+576,15
@@
void move(long object, long where)
drop(object, where);
}
drop(object, where);
}
-long put(
long object, long
where, long pval)
-/*
PUT is the same as MOVE
, except it returns a value used to set up the
+long put(
obj_t object, loc_t
where, long 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. */
{
move(object, where);
* negated game.prop values for the repository objects. */
{
move(object, where);
- return
(-1) - pval;
;
+ return
STASHED(pval)
;
}
}
-void carry(
long object, long
where)
+void carry(
obj_t object, loc_t
where)
/* Start toting an object, removing it from the list of things at its former
* location. Incr holdng unless it was already being toted. If object>NOBJECTS
* (moving "fixed" second loc), don't change game.place or game.holdng. */
/* Start toting an object, removing it from the list of things at its former
* location. Incr holdng unless it was already being toted. If object>NOBJECTS
* (moving "fixed" second loc), don't change game.place or game.holdng. */
@@
-596,7
+608,7
@@
void carry(long object, long where)
game.link[temp] = game.link[object];
}
game.link[temp] = game.link[object];
}
-void drop(
long object, long
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. */
{
/* Place an object at a given loc, prefixing it onto the game.atloc list. Decr
* game.holdng if the object was being toted. */
{
@@
-607,13
+619,14
@@
void drop(long object, long where)
--game.holdng;
game.place[object] = where;
}
--game.holdng;
game.place[object] = where;
}
- if (where <= 0)
+ if (where == LOC_NOWHERE ||
+ where == CARRIED)
return;
game.link[object] = game.atloc[where];
game.atloc[where] = object;
}
return;
game.link[object] = game.atloc[where];
game.atloc[where] = object;
}
-long atdwrf(lo
ng
where)
+long atdwrf(lo
c_t
where)
/* Return the index of first dwarf at the given location, zero if no dwarf is
* there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore
* the pirate (6th dwarf). */
/* Return the index of first dwarf at the given location, zero if no dwarf is
* there (or if dwarves not active yet), -1 if all dwarves are dead. Ignore
* the pirate (6th dwarf). */
@@
-689,3
+702,12
@@
void bug(enum bugtype num, const char *error_string)
// LCOV_EXCL_STOP
/* end */
// LCOV_EXCL_STOP
/* end */
+
+void state_change(obj_t obj, long state)
+/* Object must have a change-message list for this to be useful; only some do */
+{
+ game.prop[obj] = state;
+ pspeak(obj, change, state, true);
+}
+
+/* end */