/* map_object_actions.c */
#include "map_object_actions.h"
-#include <stdint.h> /* for uint8_t */
+#include <stdint.h> /* for uint8_t, uint16_t */
#include <string.h> /* for strlen(), strcmp() */
#include "yx_uint16.h" /* for yx_uint16 struct, mv_yx_in_dir(),
* yx_uint16_cmp()
if (player == hitted)
{
update_log(" You die.");
+ return;
}
- else
+ update_log(" It dies.");
+ if (player == hitter)
{
- update_log(" It dies.");
- if (player == hitter)
- {
- world.score = world.score + mod_hitted->lifepoints;
- }
+ world.score = world.score + mod_hitted->lifepoints;
}
}
}
if (0 != owns_none)
{
update_log("\nYou try to drop an object, but you own none.");
+ return;
}
- else
- {
- update_log("\nYou drop an object.");
- if (0 < world.inventory_sel)
- {
- world.inventory_sel--;
- }
- }
+ update_log("\nYou drop an object.");
+ world.inventory_sel = world.inventory_sel - (0 < world.inventory_sel);
}
if (picked)
{
update_log("\nYou pick up an object.");
+ return;
}
- else
- {
- update_log("\nYou try to pick up an object, but there is none.");
- }
+ update_log("\nYou try to pick up an object, but there is none.");
}
if (no_object)
{
update_log("\nYou try to use an object, but you own none.");
+ return;
}
else if (wrong_object)
{
update_log("\nYou try to use this object, but fail.");
+ return;
}
- else
- {
- update_log("\nYou consume MAGIC MEAT.");
- if (0 < world.inventory_sel)
- {
- world.inventory_sel--;
- }
- }
+ update_log("\nYou consume MAGIC MEAT.");
+ world.inventory_sel = world.inventory_sel - (0 < world.inventory_sel);
}
extern void init_map_object_actions()
{
char * f_name = "init_map_object_actions()";
-
char * path = "config/map_object_actions";
FILE * file = try_fopen(path, "r", f_name);
uint16_t linemax = textfile_sizes(file, NULL);
char line[linemax + 1];
-
struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts;
char * delim = " ";
while (fgets(line, linemax + 1, file))
if (0 < select)
{
select--;
- for (i = 0, selected = mo->owns;
- i != select;
- i++, selected = selected->next);
+ selected = mo->owns;
+ for (i = 0; i != select; i++, selected = selected->next);
selected->next = next;
}
else
struct MapObjAct * next;
uint8_t id; /* unique id of map object action */
char * name; /* human-readable identifier */
- uint8_t effort; /* how many turn the action takes */
+ uint8_t effort; /* how many turns the action takes */
void (* func) (struct MapObj *); /* function called after .effort turns */
};
extern void actor_pick(struct MapObj * mo);
/* Actor "mo" tries to use inventory object indexed by number mo->args.
- * (Currently the only valid use is consuming "MAGIC MEAT".
+ * (Currently the only valid use is consuming "MAGIC MEAT".)
*/
extern void actor_use(struct MapObj * mo);