void InstallationObjectImplementation::updateInstallationWork() { Time timeToWorkTill; bool shutdownAfterWork = updateMaintenance(timeToWorkTill); updateHopper(timeToWorkTill, shutdownAfterWork); }
void AiEntity::update() { Physics& physics = *mGameModel->physics; // this has to be non-NULL since AiManager::update() checks before calling this. // all the same... mPhysicsEntity = physics.getEntityByHandle(mPhysicsHandle); if (mPhysicsEntity == NULL) { // this is bad! printf("AiEntity::update(): error: NULL physics entity\n"); mActive = false; return; } mWorldPosition = physics.getCenter(mPhysicsHandle); // won't know this until we read the mail mWasAttacked = false; readMail(); // handle death // FIXME: the other half of this exists in AiManager... // ever get the urge to merge? if (mCurrentHealth <= 0.0) { // turn inventory items into phys entities for (int i = 0; i < AI_INVENTORY_SIZE; i++) { if (mInventory[i] > 0) { item_t item = mGameModel->itemManager->getItem(mInventory[i]); if (item.type == ITEMTYPE_GUN_ONE_HANDED && r_numi(0, 10) < 3) { mGameModel->itemManager->destroyItem(mInventory[i]); } else { v3d_t itemForce = v3d_random(20.0); itemForce.y = 10.0; PhysicsEntity* itemPhysicsEntity = physics.createEntity(OBJTYPE_ITEM, mWorldPosition, itemForce, true); if (itemPhysicsEntity != NULL) { physics.setItemHandleAndType(itemPhysicsEntity->handle, mInventory[i], mGameModel->itemManager->getItemType(mInventory[i])); } } mInventory[i] = 0; } } return; } double time = mGameModel->physics->getLastUpdateTime(); // is it time to think yet? if (mNextUpdateTime < time) { updateTarget(); // updateState(time, worldMap, physics, aiEntities, itemManager); mNextUpdateTime = time + 0.3; } if (mTargetPhysicsHandle > 0) { mTargetPhysicsEntity = physics.getEntityByHandle(mTargetPhysicsHandle); } bool couldHaveFiredGun = false; bool didFireGun = false; if (mTargetPhysicsEntity == NULL) { mTargetPhysicsHandle = 0; } else { // now shoot'm if you got'm! v3d_t targetPosition = mTargetPhysicsEntity->boundingBox.getCenterPosition(); bool hasLineOfSight = mGameModel->location->getWorldMap()->lineOfSight(mWorldPosition, targetPosition); if (mTargetPhysicsEntity->type != OBJTYPE_TIGER_BAIT && hasLineOfSight) { if (mInventory[0] > 0 && mGameModel->itemManager->getItem(mInventory[0]).type == ITEMTYPE_GUN_ONE_HANDED) { couldHaveFiredGun = true; } didFireGun = useWeapon(); } } // now for movement switch (mType) { case AITYPE_BALLOON: updateBalloon(); break; case AITYPE_SHOOTER: if (!couldHaveFiredGun || (couldHaveFiredGun && !didFireGun && mNextShotTime <= time)) { updateHopper(); } break; case AITYPE_HOPPER: updateHopper(); break; case AITYPE_HUMAN: if (!couldHaveFiredGun || (couldHaveFiredGun && !didFireGun && mNextShotTime <= time)) { updateHopper(); } break; case AITYPE_DUMMY: updateDummy(); break; default: break; } }