enemy_classes: only drop items when killed by player

This commit is contained in:
Andrei Alexeyev 2021-05-06 21:31:56 +03:00
parent b2b7645cab
commit 937aabacf2
No known key found for this signature in database
GPG key ID: 72D26128040B9690
3 changed files with 19 additions and 6 deletions

View file

@ -12,17 +12,19 @@
#include "random.h"
#include "util/glm.h"
DEFINE_EXTERN_TASK(common_drop_items) {
cmplx p = *ARGS.pos;
void common_drop_items(cmplx pos, const ItemCounts *items) {
for(int i = 0; i < ITEM_LAST - ITEM_FIRST; ++i) {
for(int j = ARGS.items.as_array[i]; j; --j) {
spawn_item(p, i + ITEM_FIRST);
for(int j = items->as_array[i]; j; --j) {
spawn_item(pos, i + ITEM_FIRST);
WAIT(2);
}
}
}
DEFINE_EXTERN_TASK(common_drop_items) {
common_drop_items(*ARGS.pos, &ARGS.items);
}
void common_move_loop(cmplx *restrict pos, MoveParams *restrict mp) {
for(;;) {
move_update(pos, mp);

View file

@ -63,6 +63,9 @@ DECLARE_EXTERN_TASK(
}
);
void common_drop_items(cmplx pos, const ItemCounts *items)
attr_nonnull(2);
int common_charge(int time, const cmplx *anchor, cmplx offset, const Color *color)
attr_nonnull(2, 4);

View file

@ -192,11 +192,19 @@ void Swirl(Enemy *e, int t, bool r) { visual_swirl(e, t, r); }
void Fairy(Enemy *e, int t, bool r) { visual_fairy_blue(e, t, r); }
void BigFairy(Enemy *e, int t, bool r) { visual_big_fairy(e, t, r); }
TASK(enemy_drop_items, { BoxedEnemy e; ItemCounts items; }) {
Enemy *e = TASK_BIND(ARGS.e);
if(e->damage_info && DAMAGETYPE_IS_PLAYER(e->damage_info->type)) {
common_drop_items(e->pos, &ARGS.items);
}
}
static Enemy *spawn(cmplx pos, const ItemCounts *item_drops, real hp, EnemyVisualRule visual) {
Enemy *e = create_enemy_p(&global.enemies, pos, hp, visual, NULL, 0, 0, 0, 0);
if(item_drops) {
INVOKE_TASK_WHEN(&e->events.killed, common_drop_items, &e->pos, *item_drops);
INVOKE_TASK_WHEN(&e->events.killed, enemy_drop_items, ENT_BOX(e), *item_drops);
}
return e;