X-Git-Url: https://plomlompom.com/repos/test.html?a=blobdiff_plain;f=src%2Fmap_object_actions.c;h=4217145843fc2d1bf80b22df7dd0cbe65f5be159;hb=657d5dbc6d362d7b20693c63b38d8d99f3d2dbbd;hp=3e9ead2e2846e09dcc2a74ab63818ad41806c519;hpb=aafa0cb49e7ec8600dad902411de6e76e111c939;p=plomrogue
diff --git a/src/map_object_actions.c b/src/map_object_actions.c
index 3e9ead2..4217145 100644
--- a/src/map_object_actions.c
+++ b/src/map_object_actions.c
@@ -2,8 +2,12 @@
#include "map_object_actions.h"
#include /* for strlen() */
-#include "yx_uint16.h" /* for yx_uint16 struct, mv_yx_in_dir(), yx_uint16_cmp */
-#include "map_objects.h" /* for MapObj, MapObjDef structs, get_player() */
+#include "yx_uint16.h" /* for yx_uint16 struct, mv_yx_in_dir(),
+ * yx_uint16_cmp()
+ */
+#include "map_objects.h" /* for MapObj, MapObjDef structs, get_player(),
+ * set_object_position(), own_map_object()
+ */
#include "misc.h" /* for update_log(), turn_over() */
#include "map.h" /* for Map struct */
#include "main.h" /* for World struct */
@@ -15,7 +19,7 @@
* reach zero in the process, killing it. Generates appropriate log message.
*/
static void actor_hits_actor(struct World * world, struct MapObj * hitter,
- struct MapObj * hitted)
+ struct MapObj * hitted);
@@ -83,7 +87,7 @@ extern uint8_t move_actor(struct World * world, struct MapObj * actor,
}
if (is_passable(world->map, target))
{
- actor->pos = target;
+ set_object_position(actor, target);
return 0;
}
return 1;
@@ -156,3 +160,53 @@ extern char is_passable(struct Map * map, struct yx_uint16 pos)
}
return passable;
}
+
+
+
+extern void player_drop(struct World * world)
+{
+ struct MapObj * player = get_player(world);
+ if (NULL == player->owns)
+ {
+ update_log(world, "\nYou try to drop an object, but you own none.");
+ }
+ else
+ {
+ struct MapObj * owned = player->owns;
+ uint8_t i = 0;
+ for (; i != world->inventory_select; i++, owned = owned->next);
+ if (0 < world->inventory_select)
+ {
+ world->inventory_select--;
+ }
+ own_map_object(&world->map_objs, &player->owns, owned->id);
+ update_log(world, "\nYou drop an object.");
+ }
+ turn_over(world, get_command_id(world, "drop"));
+}
+
+
+
+extern void player_pick(struct World * world)
+{
+ struct MapObj * player = get_player(world);
+ struct MapObj * picked;
+ for (picked = world->map_objs; NULL != picked; picked = picked->next)
+ {
+ if (picked != player && yx_uint16_cmp(&picked->pos, &player->pos))
+ {
+ break;
+ }
+ }
+ if (NULL == picked)
+ {
+ update_log(world, "\nYou try to pick up an object, but there is none.");
+ }
+ else
+ {
+ own_map_object(&player->owns, &world->map_objs, picked->id);
+ set_object_position(picked, player->pos);
+ update_log(world, "\nYou pick up an object.");
+ }
+ turn_over(world, get_command_id(world, "pick"));
+}