bool WorldManager::_handleShuttleUpdate(uint64 callTime,void* ref) { ShuttleList::iterator shuttleIt = mShuttleList.begin(); while(shuttleIt != mShuttleList.end()) { Shuttle* shuttle = (*shuttleIt); // The Ticket Collector need a valid shuttle-object. if (!shuttle->ticketCollectorEnabled()) { TicketCollector* collector = dynamic_cast<TicketCollector*>(getObjectById(shuttle->getCollectorId())); if (collector) { if (!collector->getShuttle()) { // Enable the collector. collector->setShuttle(shuttle); } shuttle->ticketCollectorEnable(); } } switch(shuttle->getShuttleState()) { case ShuttleState_Away: { uint32 awayTime = shuttle->getAwayTime() + 1000; if(awayTime >= shuttle->getAwayInterval()) { uint32 awayTime = shuttle->getAwayTime() + 1000; if(awayTime >= shuttle->getAwayInterval()) { shuttle->states.setPosture(0); shuttle->setAwayTime(0); shuttle->setShuttleState(ShuttleState_AboutBoarding); gMessageLib->sendPostureUpdate(shuttle); gMessageLib->sendCombatAction(shuttle,NULL,opChange_Posture); } } else shuttle->setAwayTime(awayTime); } break; case ShuttleState_Landing: { uint32 landingTime = shuttle->getLandingTime() + 1000; if(landingTime >= SHUTTLE_LANDING_ANIMATION_TIME - 5000) { shuttle->setShuttleState(ShuttleState_AboutBoarding); } else shuttle->setLandingTime(landingTime); } break; case ShuttleState_AboutBoarding: { uint32 landingTime = shuttle->getLandingTime() + 1000; if(landingTime >= SHUTTLE_LANDING_ANIMATION_TIME) { shuttle->setLandingTime(0); shuttle->setShuttleState(ShuttleState_InPort); } else shuttle->setLandingTime(landingTime); } break; case ShuttleState_InPort: { uint32 inPortTime = shuttle->getInPortTime() + 1000; if(inPortTime >= shuttle->getInPortInterval()) { uint32 inPortTime = shuttle->getInPortTime() + 1000; if(inPortTime >= shuttle->getInPortInterval()) { shuttle->setInPortTime(0); shuttle->setShuttleState(ShuttleState_Away); shuttle->states.setPosture(2); gMessageLib->sendPostureUpdate(shuttle); gMessageLib->sendCombatAction(shuttle,NULL,opChange_Posture); } } else { shuttle->setInPortTime(inPortTime); } } break; default: break; } ++shuttleIt; } return(true); }
Shuttle* ShuttleFactory::_createShuttle(DatabaseResult* result) { Shuttle* shuttle = new Shuttle(); Inventory* shuttleInventory = new Inventory(); shuttleInventory->setParent(shuttle); uint64 count = result->getRowCount(); result->GetNextRow(mShuttleBinding,(void*)shuttle); shuttle->mHam.mBattleFatigue = 0; shuttle->mHam.mHealth.setCurrentHitPoints(500); shuttle->mHam.mAction.setCurrentHitPoints(500); shuttle->mHam.mMind.setCurrentHitPoints(500); shuttle->mHam.calcAllModifiedHitPoints(); // inventory shuttleInventory->setId(shuttle->mId + INVENTORY_OFFSET); shuttleInventory->setParentId(shuttle->mId); shuttleInventory->setModelString("object/tangible/inventory/shared_creature_inventory.iff"); shuttleInventory->setName("inventory"); shuttleInventory->setNameFile("item_n"); shuttleInventory->setTangibleGroup(TanGroup_Inventory); shuttleInventory->setTangibleType(TanType_CreatureInventory); shuttle->mEquipManager.addEquippedObject(CreatureEquipSlot_Inventory,shuttleInventory); shuttle->setLoadState(LoadState_Loaded); shuttle->mPosture = 0; shuttle->mScale = 1.0; shuttle->setFaction("neutral"); shuttle->mTypeOptions = 0x100; // Here we can handle the initializing of shuttle states // First, a dirty test for the shuttles in Theed Spaceport. // No need to randomize departure times, since we can always travel from there. // We wan't them to go in sync, so one of them always are in the spaceport. // if (shuttle->mParentId == 1692104) #if defined(_MSC_VER) if (shuttle->mId == 47781511212) #else if (shuttle->mId == 47781511212LLU) #endif { shuttle->setShuttleState(ShuttleState_InPort); shuttle->setInPortTime(0); } #if defined (_MSC_VER) else if (shuttle->mId == 47781511214) // This is the "extra" shuttle. #else else if (shuttle->mId == 47781511214LLU) // This is the "extra" shuttle. #endif { shuttle->setShuttleState(ShuttleState_Away); shuttle->setAwayTime(0); } else { // Get a randowm value in the range [0 <-> InPortInterval + AwayInterval] in ticks. // The rand value will land in either the InPort or in the Away part of the values. // Use that state as initial state and set the value as time that have already expired. uint32 maxInPortAndAwayIntervalTime = shuttle->getInPortInterval() + shuttle->getAwayInterval(); uint32 shuttleTimeExpired = static_cast<uint32>(gRandom->getRand() / RAND_MAX) * (maxInPortAndAwayIntervalTime); if (shuttleTimeExpired <= shuttle->getInPortInterval()) { // gLogger->log(LogManager::DEBUG,"Shuttle start InPort, time expired %u", shuttleTimeExpired); shuttle->setShuttleState(ShuttleState_InPort); shuttle->setInPortTime(shuttleTimeExpired); } else { // gLogger->log(LogManager::DEBUG,"Shuttle start Away, time expired %u", shuttleTimeExpired - shuttle->getInPortInterval()); shuttle->setShuttleState(ShuttleState_Away); shuttle->setAwayTime(shuttleTimeExpired - shuttle->getInPortInterval()); // Set the part corresponding to this state only. } } return shuttle; }