void take_damage( entity_t *e, weapon_t *w ) { int damage = rand() % ( w->max_damage - w->min_damage ) + w->min_damage; e->hp -= damage; if( e->hp <= 0 ) entity_die( e ); }
void entity_update(float secs) { ent_type_t *et; entity *ent, *next; msec_t now, time; int i; now = server.now; for( ent = root ; ent != NULL ; ent = ent->next ) { et = ent->type_info; if( ent->dripping ) { time = (ent->dripping==1)? et->drip_time : INVISIBLE_DRIP_TIME; if( now - ent->last_drip >= time ) { entity_drip(ent, ent->drip1, ent->drip2); ent->last_drip = now; } } if( ent->lookatdir > 0 ) { ent->speed = 0; /* make the entity slowly turn towards the lookatpoint */ if( ent->dir > ent->lookatdir ) ent->dir -= MAX( 1, (ent->dir - ent->lookatdir)/10); else if( ent->dir < ent->lookatdir ) ent->dir += MAX( 1, (ent->lookatdir - ent->dir)/10); else ent->lookatdir = -1; } else if( ent->mode == ALIVE ) ent->speed = et->speed; else if( ent->mode == LIMBO ) { /* Respawn items */ if( ent->respawn_time && (now >= ent->respawn_time) ) { ent->mode = ALIVE; ent->respawn_time = 0; entity_spawn_effect(ent); } } if( ent->powerup ) { /* Entity is wounded */ if( ent->powerup & (1<<PU_WOUND) ) if( now - ent->last_wound >= M_SEC ) { entity_drip(ent, COL_RED, COL_RED); /* Drip blood */ ent->health -= 2; ent->last_wound = now; } if( ent->powerup & (1<<PU_INVISIBILITY) ) { ent->visible = 0; if( ent->x_v || ent->y_v ) { /* Drip if moving */ ent->dripping = 2; ent->drip1 = ent->color1; ent->drip2 = ent->color2; } else { ent->dripping = et->dripping; ent->drip1 = et->drip1; ent->drip2 = et->drip2; } } for( i=0 ; i<NUM_POWERUPS ; i++ ) { if( ent->powerup & (1<<i) && now > ent->powerup_expire[i] ) { ent->powerup &= ~(1<<i); ent->powerup_expire[i] = 0; switch( i ) { case PU_INVISIBILITY: ent->dripping = et->dripping; ent->drip1 = et->drip1; ent->drip2 = et->drip2; ent->visible = 1; break; case PU_FROZEN: if( ent->mode == FROZEN ) ent->mode = ALIVE; break; case PU_E: /* Worn off, entity is now on a come down... */ if( ent->mode == ENLIGHTENED ) { ent->mode = COMEDOWN; ent->speed = et->speed * 0.50; ent->powerup |= (1<<PU_E); /* Restore bit */ ent->powerup_expire[PU_E] = now + M_SEC * 10; } else if( ent->mode == COMEDOWN ) { ent->mode = ALIVE; } break; } } } } } entity_update_movement(secs); entity_check_collisions(); entity_animate(); for( ent = root ; ent != NULL ; ent = next ) { next = ent->next; if( ent->mode >= FROZEN && ent->health <= 0 ) entity_die(ent); /* Set to either dead or dying */ if( ent->mode == DEAD ) { if( ent->controller == CTRL_CLIENT ) spawn(ent, 1); /* Respawn */ else entity_delete(ent); } } }