X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=src%2Fserver%2Frun.c;h=83bb724cb67cabbabdb1dfbff2615fc592a22dae;hb=e03020342a74aef143b1ec38c18966dac64181b5;hp=1df4b63b6668dbd5076ae3d9fa7ea26b529f00be;hpb=0255432b4e8d3a7b3aec71c4e43e7fb063c45833;p=plomrogue diff --git a/src/server/run.c b/src/server/run.c index 1df4b63..83bb724 100644 --- a/src/server/run.c +++ b/src/server/run.c @@ -26,6 +26,17 @@ */ static void turn_over(); +/* Helper to turn_over() to determine whether a map object's action effort has + * reached its end. The simplicity of just comparing map_object->progress to + * moa->effort is suspended for actor movement, for in this case the effort + * depends on the diagonal movement penalty expressed in the ratio of + * world.map.dist_diagonal / world.map.dist_orthogonal. (Movement being diagonal + * or orthogonal is determined by the ->arg char encoding an even or un-even + * number digit). + */ +static uint8_t is_effort_finished(struct MapObjAct * moa, + struct MapObj * map_object); + /* If "msg"'s first part matches "command_name", set player's MapObj's .command * to the command's id and its .arg to a numerical value following in the latter * part of "msg" (if no digits are found, use 0); then finish player's turn and @@ -64,7 +75,7 @@ static void turn_over() { moa = moa->next; } - if (map_object->progress == moa->effort) + if (is_effort_finished(moa, map_object)) { moa->func(map_object); map_object->command = 0; @@ -77,6 +88,37 @@ static void turn_over() +static uint8_t is_effort_finished(struct MapObjAct * moa, + struct MapObj * map_object) +{ + if (moa->func != actor_move) + { + if (map_object->progress == moa->effort) + { + return 1; + } + } + else if (strchr("8624", map_object->arg)) + { + if (map_object->progress == moa->effort) + { + return 1; + } + } + else if (strchr("1379", map_object->arg)) + { + uint16_t diagonal_effort = (moa->effort * world.map.dist_diagonal) + / world.map.dist_orthogonal; + if (map_object->progress == diagonal_effort) + { + return 1; + } + } + return 0; +} + + + static uint8_t apply_player_command(char * msg, char * command_name) { if (!strncmp(msg, command_name, strlen(command_name)))