void step(void) { sampleExts(); fireTriggers(); updateObservers(); updateStates(); updateBuffers(); updatePtrs(); }
void doEnemies() { bool helpless; float fallSpeed; for (Unit *unit = (Unit*)entityManager->enemyList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next) { self = unit; //self->riding = NULL; bbManager->removeBox(unit); // final battle... if (unit->contentType & CONTENTS_PLAYERCLIP) { unit->health = 0; unit->flags |= EF_DEAD; } if (unit->health <= 0) { if (unit->flags & EF_DEAD) { if (!unit->referenced) { if (player->target == unit) { player->target = NULL; } unit = (Unit*)unit->previous; entityManager->enemyList.remove(unit->next); if (entityManager->enemyList.getSize() == 0) { fireTriggers("ANY_ENEMY", TRIGGER_TYPE_ALL_ENEMIES_KILLED); } continue; } else { unit->referenced = false; } continue; } else if (!(unit->flags & EF_DYING)) { unit->die(); if (!unit->dead) { fireTriggers(unit->getName(), TRIGGER_TYPE_ENTITY_KILLED); fireTriggers("ANY_ENEMY", TRIGGER_TYPE_ENTITY_KILLED); unit->dead = true; } unit->flags |= EF_DYING; if (!(unit->flags & EF_STATIC)) { unit->flags |= EF_BOUNCES; } addBloodParticle(unit->position.x, unit->position.y, unit->position.z); if (unit->contentType & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) { debug(("%s drowned...\n", unit->getName())); } } } if ((unit->spawnedIn) && (unit->lastPlayerSighting >= 6000) && (!unit->referenced)) { addTeleportParticles(unit->position); unit = (Unit*)unit->previous; entityManager->enemyList.remove(unit->next); continue; } if (unit->target != NULL) { unit->target->referenced = true; } if (unit->owner != NULL) { unit->owner->referenced = true; } unit->referenced = false; helpless = (unit->helpless > 0); if ((!game->allStatic) && (game->cutsceneType != CUTSCENE_INGAME)) { if ((!helpless) || (unit->health < 1)) { if (unit->performNextAction(engine->getTimeDifference(TD_LOGIC))) { if (unit->action != NULL) { unit->action(); } } } } if (game->cutsceneType != CUTSCENE_INGAME) { unit->think(engine->getTimeDifference(TD_LOGIC)); } if (unit->flags & (EF_TELEPORTING|EF_VANISHED)) { continue; } if (withinViewableRange(unit)) { entityManager->addEntityToDrawList(unit); if (unit->flags & EF_WEIGHTLESS) { addGravUnitParticles(unit, GLColor::purple, GLColor::blue); } } if ((unit->liquidLevel > 1) && (!(unit->flags & EF_SWIMS))) { if ((unit->definition->type == NME_DARK_BLOB) && (unit->health > 0)) { generalUnitVanish(player->position, Math::rrand(300, 400)); continue; } else if (unit->health > 0) { unit->applyDamage(RAND_MAX, DAMAGE_SPECIAL); } } // was helpless but now isn't - Stop sliding! if ((helpless) && (unit->helpless <= 0)) { if ((unit->flags & EF_ONGROUND) || (!(unit->contentType & CONTENTS_SOLID)) || (unit->flags & EF_WEIGHTLESS)) { unit->totalCurrentDamage = 0; unit->rotation.set(0, 0, 0); unit->flags &= ~EF_BOUNCES; } else { unit->helpless = 1; } } unit->applyGravity(engine->getTimeDifference(TD_LOGIC)); keepUnitAwayFromEdges(unit); fallSpeed = unit->realVelocity.z; if (fallSpeed <= FALL_DAMAGE_ACCEL) { unit->helpless = 5; unit->flags |= EF_BOUNCES; } // don't let swimming blobs move too quickly if ((unit->flags & EF_SWIMS) && (unit->liquidLevel == 2)) { Math::limit(&unit->velocity.x, -0.1, 0.1); Math::limit(&unit->velocity.y, -0.1, 0.1); Math::limit(&unit->velocity.z, -0.1, 0.1); } moveEntity(unit); if ((fallSpeed <= FALL_DAMAGE_ACCEL) && (unit->velocity.z > FALL_DAMAGE_ACCEL) && (unit->contentType & CONTENTS_SOLID)) { unit->velocity.z = 1.0; fallSpeed = fabs(fallSpeed * 1.5); if (!(unit->flags & EF_DYING)) { unit->applyDamage(fallSpeed, DAMAGE_SPECIAL); unit->shield = -2.5; audio->playSound(SND_HIT, CH_ANY, camera->getSoundDistance(unit->position)); debug(("%s took %.2f damage from fall [%s]\n", unit->getName(), fallSpeed, unit->position.toString())); } else { unit->health = -100; unit->flags |= EF_DYING; } } if ((unit->position.z < bsp->minCords.z) && (unit->health > 0)) { printf("WARNING: Enemy '%s' fell out of map at %s\n", unit->getName(), unit->position.toString()); printf("Map Mins: %s\n", bsp->minCords.toString()); printf("Map Maxs: %s\n", bsp->maxCords.toString()); printf("On Ground = %ld\n", (unit->flags & EF_ONGROUND)); printf("Velocity = %s\n", unit->velocity.toString()); unit->health = -100; unit->flags |= EF_DEAD; continue; #if DEV exit(1); #endif } if (unit->flags & EF_ONFIRE) { addOnFireParticles(); } bbManager->addBox(unit); if ((unit->definition->type == NME_DARK_BLOB) && (unit->health > 0)) { Math::limit(&unit->helpless, 0, 25); } if ((unit->flags & EF_ALWAYS_FACE) && (unit->health > 0)) { if ((!unit->helpless) && (unit->target != NULL)) { faceTarget(unit); } } } }