//=============================================================================================== //stores the physical body void VehicleController::Store() { if(!body_) { DLOG(info) << "Vehicle::store() Error: Store was called for a nonexistant body object!"; return; } PlayerObject* owner = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(owner_)); if(!owner_ || owner->GetCreature()->isDead() || owner->GetCreature()->isIncapacitated()) { DLOG(info) << "Vehicle::store() couldnt find owner"; return; } // todo auto dismount if(owner->checkIfMounted()) { DLOG(info) << "Vehicle::store() dismounted"; DismountPlayer(); } if(!owner->checkIfMountCalled()) { DLOG(info) << "Vehicle::store() Mount wasnt called !!!"; return; } //the body is a creature_object!!! gSpatialIndexManager->RemoveObjectFromWorld(body_); owner->setMount(NULL); owner->setMounted(false); owner->setMountCalled(false); // finally unload & destroy the vehicle creature gWorldManager->destroyObject(body_); // null the reference body_ = NULL; }
void VehicleController::Call() { if(body_) { assert(false && "void Vehicle::call() body already exists"); return; } PlayerObject* owner = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(owner_)); if(owner->checkIfMountCalled()) { LOG(info) << "VehicleController::Call : body already in world " << this->getId(); return; } if(!owner->isConnected() || owner->GetCreature()->isDead() || owner->GetCreature()->isIncapacitated()) { LOG(info) << "VehicleController::Call : owner statecheck fail for " << this->getId(); return; } body_ = new MountObject(); BString cust; cust.initRawBSTR((int8*)Swoop_Customization, BSTRType_ANSI); body_->setCustomizationStr("");//cust.getAnsi()); body_->setCreoGroup(CreoGroup_Vehicle); body_->setTypeOptions(0x1080); body_->setMoodId(0); body_->setCL(0); body_->setId(mId + 1); // Vehicles are created by the VehicleControllerFactory with +2 step for IDs body_->set_controller(this->getId()); body_->set_owner(owner->getId()); body_->setParentId(0); body_->SetTemplate(mPhysicalModel); body_->setSpeciesGroup(mNameFile.getAnsi()); body_->setSpeciesString(mName.getAnsi()); body_->SetPosture(0); body_->setScale(1.0f); std::string con = this->getAttribute<std::string>("condition"); uint32 health_current = atoi(con.substr(0,con.find_first_of("/")).c_str()); uint32 health_max = atoi(con.substr(con.find_first_of("/")+1,con.find_first_of("/")).c_str()); for(int8 i = 0; i<9;i++) { body_->InitStatBase(0); body_->InitStatCurrent(0); body_->InitStatMax(0); body_->InitStatWound(0); } body_->InitStatCurrent(HamBar_Health, health_current); body_->InitStatMax(HamBar_Health, health_max); owner->setMount(body_); owner->setMounted(false); owner->setMountCalled(false); // Set default direction and position for the body. body_->mDirection = owner->GetCreature()->mDirection; body_->mPosition = owner->GetCreature()->mPosition; // Move it forward 2 meters body_->moveForward(2); auto terrain = gWorldManager->getKernel()->GetServiceManager()->GetService<swganh::terrain::TerrainService>("TerrainService"); gObjectManager->LoadSlotsForObject(body_); body_->mPosition.y = terrain->GetHeight(gWorldManager->getZoneId(), body_->mPosition.x,body_->mPosition.z) + 0.3; // Finally rotate it perpendicular to the player. body_->rotateRight(90.0f); // add to world if(!gWorldManager->addObject(body_)) { DLOG(info) << "void Vehicle::call() creating vehicle with id "<<body_->getId()<<" failed : couldnt add to world"; SAFE_DELETE(body_); return; } auto permissions_objects_ = gObjectManager->GetPermissionsMap(); body_->SetPermissions(permissions_objects_.find(swganh::object::RIDEABLE_PERMISSION)->second.get());//CREATURE_PERMISSION //currently done by gWorldManager->addObject(body_) //gSpatialIndexManager->createInWorld(body_); gMessageLib->sendUpdateTransformMessage(body_); owner->setMountCalled(true); return; }
bool ObjectController::_updateInRangeObjectsOutside() { PlayerObject* player = dynamic_cast<PlayerObject*>(mObject); // We may wan't to limit the amount of messages sent in one session. uint32 updatedObjects = 0; const uint32 objectSendLimit = 50; while ((mObjectSetIt != mInRangeObjects.end()) && (updatedObjects < objectSendLimit)) { //BEWARE Object is at this time possibly not valid anymore! //this actually causes a lot of crashes!!!! Object* object = dynamic_cast<Object*>(*mObjectSetIt); // Just simplified the code a little. Good find Schmunzel. // only add it if its also outside // see if its already observed, if yes, just send a position update out, if its a player if ((object) && (!player->checkKnownObjects(object))) { // send the according create for the type of object #if defined(_MSC_VER) if (object->getId() > 0x0000000100000000) #else if (object->getId() > 0x0000000100000000LLU) #endif { if (object->getPrivateOwner()) { if (object->isOwnedBy(player)) { gMessageLib->sendCreateObject(object,player); player->addKnownObjectSafe(object); object->addKnownObjectSafe(player); //If player has a mount make sure add to its known objects //but is the mount even near us ??? // does this even matter ? if(player->checkIfMountCalled() && player->getMount()) { if(player->getMount()->getId() != object->getId()) { player->getMount()->addKnownObjectSafe(object); object->addKnownObjectSafe(player->getMount()); } } updatedObjects++; } } else { //if(!player->checkKnownObjects(object)) //{ gMessageLib->sendCreateObject(object,player); player->addKnownObjectSafe(object); object->addKnownObjectSafe(player); //If player has a mount make sure add to its known objects if(player->checkIfMountCalled() && player->getMount()) { if(player->getMount()->getId() != object->getId()) { player->getMount()->addKnownObjectSafe(object); object->addKnownObjectSafe(player->getMount()); } } //} updatedObjects++; } } } ++mObjectSetIt; } return (mObjectSetIt == mInRangeObjects.end()); }