summaryrefslogtreecommitdiff
path: root/src/entity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity.c')
-rw-r--r--src/entity.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/entity.c b/src/entity.c
index 214c066..edb949e 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -24,6 +24,27 @@ entity_type(const char *typename)
return 0;
}
+unsigned int
+entity_type_parent(unsigned int type)
+{
+ if (type == 0)
+ return 0;
+ if (entitytags[type - 1].parent != NULL)
+ return entity_type(entitytags[type - 1].parent);
+ return 0;
+}
+
+bool
+entity_is_type(unsigned int type, unsigned int search)
+{
+ do {
+ if (type == search)
+ return true;
+ type = entity_type_parent(type);
+ } while (type != 0);
+ return false;
+}
+
bool
entity_collide(Entity *this, int ox, int oy)
{
@@ -47,7 +68,8 @@ Entity *
entity_place_meeting(Entity *this, struct Game *g, unsigned int type)
{
for (__auto_type i = MAX_ENTITIES - 1; i >= 0; i--)
- if (this != &g->entities[i] && g->entities[i].type == type &&
+ if (this != &g->entities[i] &&
+ entity_is_type(g->entities[i].type, type) &&
entity_meet(this, &g->entities[i]))
return &g->entities[i];
return NULL;