//--- // aoe: Physical entities tracking areas of effect of skills //--- #pragma once #include "geometry.h" #include "anim.h" #include "item.h" enum { /* Item */ AOE_ITEM, /* Bare-hand fist/close-contact attack */ AOE_HIT, /* Simple ranged attack */ AOE_PROJECTILE, AOE_PROJECTILE_FAST, /* Normal attack by a slashing weapon */ AOE_SLASH, /* Impaling attack using a slashing weapon */ AOE_IMPALE, /* Skills */ AOE_SHOCK, AOE_JUDGEMENT, AOE_BULLET, AOE_FIRE_CHARGE, AOE_WATER_CHARGE, AOE_CHEMICAL_CHARGE, /* Spawn effect */ EFFECT_SPAWN, }; /* Record of when an area hit an entity */ typedef struct { /* Entity hit */ entity_t *entity; /* Lifetime of the area at the time of the hit */ fixed_t lifetime; } aoe_record_t; /* Extra component for areas of effect */ typedef struct { /* Lifetime (s) */ fixed_t lifetime; /* Effect repeat delay (seconds; 0 for no repeat) */ fixed_t repeat_delay; /* List of entities that were hit */ aoe_record_t *hits; int hit_count; /* Entity that caused the area */ entity_t *origin; /* Type of effect */ uint16_t type; /* Effect data (type-dependent) */ union { /* Item: item info */ struct { int type; } item; /* Generic attacks: source and ATK strength */ struct { int strength; int dir; } generic; /* AOE_PROJECTILE, AOE_PROJECTILE_FAST: speed and direction */ struct { int strength; vec2 direction; fixed_t speed; } projectile; /* AOE_SHOCK: origin and ATK strength */ struct { int strength; vec2 origin; } shock; /* AOE_BULLET: magic strengh, speed parameters */ struct { int strength; int dir; fixed_t v; fixed_t final_v; } bullet; /* AOE_*_CHARGE: element type, origin and MAG power */ struct { int element; int power; vec2 origin; } charge; } data; } aoe_t; /* Create a new area of the specified type. The animation, repeat delay, origin and type-specific data should be set manually after creation. */ entity_t *aoe_make(uint16_t type, vec2 position, fixed_t lifetime); /* Free resources for an area. */ void aoe_destroy(entity_t *aoe); /* Create an area for a particular attack; all attributes are initialized. */ entity_t *aoe_make_attack(uint16_t type, entity_t *origin, vec2 dir); entity_t *aoe_make_attack_4(uint16_t type, entity_t *origin, int facing); /* Apply effect of area on entity */ struct game; void aoe_apply(struct game *g, entity_t *aoe, entity_t *e); /* Regular update, for moving areas (eg. bullet) */ void aoe_update(struct game *g, entity_t *aoe, fixed_t dt);