int main(){ std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ASCIIWriter("example.txt", &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& strings = store.create<ExampleWithStringCollection>("strings"); writer.registerForWrite<EventInfoCollection>("info"); writer.registerForWrite<ExampleMCCollection>("mcparticles"); writer.registerForWrite<ExampleHitCollection>("hits"); writer.registerForWrite<ExampleClusterCollection>("clusters"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs2"); writer.registerForWrite<ExampleWithComponentCollection>("Component"); writer.registerForWrite<ExampleWithOneRelationCollection>("OneRelation"); writer.registerForWrite<ExampleWithVectorMemberCollection>("WithVectorMember"); writer.registerForWrite<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); writer.registerForWrite<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); writer.registerForWrite<ExampleWithStringCollection>("strings"); unsigned nevents=1;//2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(23); vec.addcount(24); vecs.push_back(vec); auto namesp = ex::ExampleWithNamespace(); namesp.data().x = 1; namesp.data().y = i; namesps.push_back(namesp); auto rel = ex::ExampleWithARelation(); rel.ref(namesp); namesprels.push_back(rel); auto string = ExampleWithString("SomeString"); strings.push_back(string); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
void UnitBase::navigate() { if(isAFlyingUnit() || (((currentGame->getGameCycleCount() + getObjectID()*1337) % 5) == 0)) { // navigation is only performed every 5th frame if(!moving && !justStoppedMoving) { if(location != destination) { if(nextSpotFound == false) { if(pathList.empty() && (recalculatePathTimer == 0)) { recalculatePathTimer = 100; if(!SearchPathWithAStar() && (++noCloserPointCount >= 3) && (location != oldLocation)) { //try searching for a path a number of times then give up if (target.getObjPointer() != NULL && targetFriendly && (target.getObjPointer()->getItemID() != Structure_RepairYard) && ((target.getObjPointer()->getItemID() != Structure_Refinery) || (getItemID() != Unit_Harvester))) { setTarget(NULL); } setDestination(location); //can't get any closer, give up forced = false; } } if(!pathList.empty()) { nextSpot = pathList.front(); pathList.pop_front(); nextSpotFound = true; recalculatePathTimer = 0; noCloserPointCount = 0; } } else { int tempAngle = currentGameMap->getPosAngle(location, nextSpot); if(tempAngle != INVALID) { nextSpotAngle = tempAngle; } if(!canPass(nextSpot.x, nextSpot.y)) { clearPath(); } else { if (drawnAngle == nextSpotAngle) { moving = true; nextSpotFound = false; assignToMap(nextSpot); angle = drawnAngle; setSpeeds(); } } } } else if(!target) { if(((currentGame->getGameCycleCount() + getObjectID()*1337) % MILLI2CYCLES(UNITIDLETIMER)) == 0) { idleAction(); } } } } }
int GeneratorObjectImplementation::handleObjectMenuSelect(CreatureObject* player, byte selectedID) { if (!isOnAdminList(player)) return 1; switch (selectedID) { case 78: { ResourceHarvesterActivatePageMessage* rhapm = new ResourceHarvesterActivatePageMessage(getObjectID()); player->sendMessage(rhapm); break; } default: return InstallationObjectImplementation::handleObjectMenuSelect(player, selectedID); } return 0; }
void SceneObjectImplementation::broadcastMessagePrivate(BasePacket* message, SceneObject* selfObject, bool lockZone) { ZoneServer* zoneServer = getZoneServer(); if (zoneServer != NULL && zoneServer->isServerLoading()) return; if (parent.get() != NULL) { ManagedReference<SceneObject*> grandParent = cast<SceneObject*>(getRootParent().get().get()); if (grandParent != NULL) { grandParent->broadcastMessagePrivate(message, selfObject, lockZone); return; } else { delete message; return; } } if (zone == NULL) { delete message; return; } //Locker zoneLocker(zone); //getZone()->rlock(lockZone); // bool readlock = lockZone && !zone->isLockedByCurrentThread(); SortedVector<ManagedReference<QuadTreeEntry*> >* closeSceneObjects = NULL; SortedVector<ManagedReference<QuadTreeEntry*> >* closeNoneReference = NULL; int maxInRangeObjectCount = 0; bool deleteVector = true; try { // zone->rlock(readlock); if (closeobjects == NULL) { info(String::valueOf(getObjectID()) + " Null closeobjects vector in SceneObjectImplementation::broadcastMessagePrivate", true); closeSceneObjects = new SortedVector<ManagedReference<QuadTreeEntry*> >(); zone->getInRangeObjects(getPositionX(), getPositionY(), 192, closeSceneObjects, true); maxInRangeObjectCount = closeSceneObjects->size(); deleteVector = true; } else { // maxInRangeObjectCount = closeobjects->size(); //closeSceneObjects = closeobjects; closeNoneReference = new SortedVector<ManagedReference<QuadTreeEntry*> >(maxInRangeObjectCount, 50); /* for (int i = 0; i < closeobjects->size(); ++i) { closeNoneReference->add(closeobjects->get(i).get()); } */ closeobjects->safeCopyTo(*closeNoneReference); maxInRangeObjectCount = closeNoneReference->size(); //closeSceneObjects.removeAll(maxInRangeObjectCount, 10); //closeSceneObjects.addAll(*closeobjects); } /* for (int i = 0; i < maxInRangeObjectCount; ++i) { SceneObject* scno = cast<SceneObject*>(closeSceneObjects->get(i).get()); if (selfObject == scno) continue; ManagedReference<ZoneClientSession*> client = scno->getClient(); if (client != NULL || scno->isVehicleObject()) { scno->sendMessage(message->clone()); } } */ //zone->runlock(readlock); } catch (...) { // zone->runlock(readlock); delete message; throw; } for (int i = 0; i < maxInRangeObjectCount; ++i) { SceneObject* scno; if (closeSceneObjects != NULL) scno = cast<SceneObject*>(closeSceneObjects->get(i).get()); else scno = cast<SceneObject*>(closeNoneReference->get(i).get()); if (selfObject == scno) continue; ManagedReference<ZoneClientSession*> client = scno->getClient(); if ((dynamic_cast<VehicleObject*>(scno) != NULL) || client != NULL || scno->isMount()) scno->sendMessage(message->clone()); } delete message; if (closeSceneObjects != NULL) delete closeSceneObjects; else delete closeNoneReference; }
void SceneObjectImplementation::broadcastMessagesPrivate(Vector<BasePacket*>* messages, SceneObject* selfObject) { ZoneServer* zoneServer = getZoneServer(); if (zoneServer != NULL && zoneServer->isServerLoading()) return; if (parent.get() != NULL) { ManagedReference<SceneObject*> grandParent = cast<SceneObject*>(getRootParent().get().get()); if (grandParent != NULL) { grandParent->broadcastMessagesPrivate(messages, selfObject); return; } else { while (!messages->isEmpty()) { delete messages->remove(0); } return; } } if (zone == NULL) { while (!messages->isEmpty()) { delete messages->remove(0); } return; } //getZone()->rlock(); //Locker zoneLocker(zone); bool readlock = !zone->isLockedByCurrentThread(); SortedVector<ManagedReference<QuadTreeEntry*> > closeSceneObjects; int maxInRangeObjectCount = 0; // zone->rlock(readlock); try { if (closeobjects == NULL) { info(String::valueOf(getObjectID()) + " Null closeobjects vector in SceneObjectImplementation::broadcastMessagesPrivate", true); zone->getInRangeObjects(getPositionX(), getPositionY(), 192, &closeSceneObjects, true); maxInRangeObjectCount = closeSceneObjects.size(); } else { maxInRangeObjectCount = closeobjects->size(); closeSceneObjects.removeAll(maxInRangeObjectCount, 10); //closeSceneObjects.addAll(*closeobjects); closeobjects->safeCopyTo(closeSceneObjects); maxInRangeObjectCount = closeSceneObjects.size(); } } catch (Exception& e) { } //getZone()->runlock(); //zoneLocker.release(); // zone->runlock(readlock); for (int i = 0; i < maxInRangeObjectCount; ++i) { SceneObject* scno = cast<SceneObject*>(closeSceneObjects.get(i).get()); if (selfObject == scno) continue; ManagedReference<ZoneClientSession*> client = scno->getClient(); if (scno->isVehicleObject() || client != NULL || scno->isMount()) { for (int j = 0; j < messages->size(); ++j) { BasePacket* msg = messages->get(j); scno->sendMessage(msg->clone()); } } } while (!messages->isEmpty()) { delete messages->remove(0); } }
void write(std::string outfilename) { std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ROOTWriter(outfilename, &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& cpytest = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelationCopy"); auto& strings = store.create<ExampleWithStringCollection>("strings"); auto& arrays = store.create<ExampleWithArrayCollection>("arrays"); writer.registerForWrite("info"); writer.registerForWrite("mcparticles"); writer.registerForWrite("hits"); writer.registerForWrite("clusters"); writer.registerForWrite("refs"); writer.registerForWrite("refs2"); writer.registerForWrite("Component"); writer.registerForWrite("OneRelation"); writer.registerForWrite("WithVectorMember"); writer.registerForWrite("WithNamespaceMember"); writer.registerForWrite("WithNamespaceRelation"); writer.registerForWrite("WithNamespaceRelationCopy"); writer.registerForWrite("strings"); writer.registerForWrite("arrays"); unsigned nevents = 2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(i); vec.addcount(i+10); vecs.push_back(vec); auto vec1 = ExampleWithVectorMember(); vec1.addcount(i+1); vec1.addcount(i+11); vecs.push_back(vec1); for (int j = 0; j < 5; j++) { auto rel = ex::ExampleWithARelation(); rel.number(0.5*j); auto exWithNamesp = ex::ExampleWithNamespace(); exWithNamesp.data().x = i; exWithNamesp.data().y = 1000*i; namesps.push_back(exWithNamesp); if (j != 3) { // also check for empty relations rel.ref(exWithNamesp); for (int k = 0; k < 5; k++) { auto namesp = ex::ExampleWithNamespace(); namesp.x(3*k); namesp.data().y = k; namesps.push_back(namesp); rel.addrefs(namesp); } } namesprels.push_back(rel); } for (int j = 0; j < namesprels.size(); ++j) { cpytest.push_back(namesprels.at(j).clone()); } auto string = ExampleWithString("SomeString"); strings.push_back(string); std::array<int, 4> arrayTest = {0, 0, 2, 3}; std::array<int, 4> arrayTest2 = {4, 4, 2 * static_cast<int>(i)}; NotSoSimpleStruct a; a.data.p = arrayTest2; ex2::NamespaceStruct nstruct; nstruct.x = static_cast<int>(i); std::array<ex2::NamespaceStruct, 4> structArrayTest = {nstruct, nstruct, nstruct, nstruct}; auto array = ExampleWithArray(a, arrayTest, arrayTest, arrayTest, arrayTest, structArrayTest); array.myArray(1, i); array.arrayStruct(a); arrays.push_back(array); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
BaseMessage* SceneObjectImplementation::link(uint64 objectID, uint32 containmentType) { return new UpdateContainmentMessage(getObjectID(), objectID, containmentType); }
void SceneObjectImplementation::broadcastMessagePrivate(BasePacket* message, SceneObject* selfObject, bool lockZone) { ZoneServer* zoneServer = getZoneServer(); if (zoneServer != NULL && zoneServer->isServerLoading()) return; if (parent.get() != NULL) { ManagedReference<SceneObject*> grandParent = getRootParent().get(); if (grandParent != NULL) { grandParent->broadcastMessagePrivate(message, selfObject, lockZone); return; } else { delete message; return; } } if (zone == NULL) { delete message; return; } SortedVector<ManagedReference<QuadTreeEntry*> >* closeSceneObjects = NULL; SortedVector<ManagedReference<QuadTreeEntry*> >* closeNoneReference = NULL; int maxInRangeObjectCount = 0; bool deleteVector = true; try { if (closeobjects == NULL) { info(String::valueOf(getObjectID()) + " Null closeobjects vector in SceneObjectImplementation::broadcastMessagePrivate", true); closeSceneObjects = new SortedVector<ManagedReference<QuadTreeEntry*> >(); zone->getInRangeObjects(getPositionX(), getPositionY(), 192, closeSceneObjects, true); maxInRangeObjectCount = closeSceneObjects->size(); deleteVector = true; } else { closeNoneReference = new SortedVector<ManagedReference<QuadTreeEntry*> >(maxInRangeObjectCount, 50); closeobjects->safeCopyTo(*closeNoneReference); maxInRangeObjectCount = closeNoneReference->size(); } } catch (Exception& e) { error(e.getMessage()); e.printStackTrace(); delete message; throw; } catch (...) { delete message; throw; } for (int i = 0; i < maxInRangeObjectCount; ++i) { SceneObject* scno; if (closeSceneObjects != NULL) scno = static_cast<SceneObject*>(closeSceneObjects->get(i).get()); else scno = static_cast<SceneObject*>(closeNoneReference->get(i).get()); ManagedReference<ZoneClientSession*> client = scno->getClient(); if (scno->isVehicleObject() || client != NULL || scno->isMount()) scno->sendMessage(message->clone()); } delete message; if (closeSceneObjects != NULL) delete closeSceneObjects; else delete closeNoneReference; }
void GroupObjectImplementation::startChatRoom() { Reference<CreatureObject*> leader = groupMembers.get(0).get().castTo<CreatureObject*>(); ChatManager* chatManager = server->getZoneServer()->getChatManager(); chatRoom = chatManager->createGroupRoom(getObjectID(), leader); }
void SceneObjectImplementation::createChildObjects() { if (getZone() == NULL) return; ZoneServer* zoneServer = getZone()->getZoneServer(); bool client = isStaticObject(); for (int i = 0; i < templateObject->getChildObjectsSize(); ++i) { ChildObject* child = templateObject->getChildObject(i); if (child == NULL) continue; ManagedReference<SceneObject*> obj = NULL; if (client) obj = zoneServer->createObject(child->getTemplateFile().hashCode(), "clientobjects", getPersistenceLevel()); else obj = zoneServer->createObject(child->getTemplateFile().hashCode(), getPersistenceLevel()); if (obj == NULL) continue; Locker objLocker(obj, asSceneObject()); Vector3 childPosition = child->getPosition(); childObjects.put(obj); obj->initializePosition(childPosition.getX(), childPosition.getZ(), childPosition.getY()); obj->setDirection(child->getDirection()); if (isBuildingObject() && child->getCellId() >= 0) { BuildingObject* buildingObject = asBuildingObject(); int totalCells = buildingObject->getTotalCellNumber(); try { if (totalCells >= child->getCellId()) { ManagedReference<CellObject*> cellObject = buildingObject->getCell(child->getCellId()); if (cellObject != NULL) { if (!cellObject->transferObject(obj, child->getContainmentType(), true)) { obj->destroyObjectFromDatabase(true); continue; } //cellObject->broadcastObject(obj, false); } else { error("NULL CELL OBJECT"); obj->destroyObjectFromDatabase(true); continue; } } } catch (Exception& e) { error("unreported exception caught in void SceneObjectImplementation::createChildObjects()!"); e.printStackTrace(); } } else { //Create the object outdoors in relation to its parent. Vector3 position; if (obj->isActiveArea()) position = getWorldPosition(); else position = getPosition(); float angle = direction.getRadians(); float x = (Math::cos(angle) * childPosition.getX()) + (childPosition.getY() * Math::sin(angle)); float y = (Math::cos(angle) * childPosition.getY()) - (childPosition.getX() * Math::sin(angle)); x += position.getX(); y += position.getY(); float z = position.getZ() + childPosition.getZ(); float degrees = direction.getDegrees(); Quaternion dir = child->getDirection(); obj->initializePosition(x, z, y); obj->setDirection(dir.rotate(Vector3(0, 1, 0), degrees)); if (obj->isBuildingObject()) { BuildingObject* building = obj->asBuildingObject(); if (building != NULL) { building->createCellObjects(); } } if (!getZone()->transferObject(obj, -1, false)) { obj->destroyObjectFromDatabase(true); continue; } } //childObjects.put(obj); ContainerPermissions* permissions = obj->getContainerPermissions(); permissions->setOwner(getObjectID()); permissions->setInheritPermissionsFromParent(false); permissions->setDefaultDenyPermission(ContainerPermissions::MOVECONTAINER); permissions->setDenyPermission("owner", ContainerPermissions::MOVECONTAINER); obj->initializeChildObject(asSceneObject()); } }
void processEvent(podio::EventStore& store, bool verboser, unsigned eventNum) { auto& failing = store.get<ExampleClusterCollection>("notthere"); if(failing.isValid() == true) { throw std::runtime_error("Collection 'notthere' should not be valid"); }; auto& strings = store.get<ExampleWithStringCollection>("strings"); if(strings.isValid()){ auto string = strings[0]; if (string.theString() != "SomeString") { throw std::runtime_error("Couldn't read string properly"); } } else { throw std::runtime_error("Collection 'strings' should be present."); } auto& clusters = store.get<ExampleClusterCollection>("clusters"); if(clusters.isValid()){ auto cluster = clusters[0]; for (auto i = cluster.Hits_begin(), end = cluster.Hits_end(); i!=end; ++i){ std::cout << " Referenced hit has an energy of " << i->energy() << std::endl; glob++; } } else { throw std::runtime_error("Collection 'clusters' should be present"); } auto& mcps = store.get<ExampleMCCollection>("mcparticles"); if( mcps.isValid() ){ // check that we can retrieve the correct parent daughter relation // set in write.cpp : // particle 0 has particles 2,3,4 and 5 as daughters: auto p = mcps[0] ; //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } auto d0 = p.daughters(0) ; auto d1 = p.daughters(1) ; auto d2 = p.daughters(2) ; auto d3 = p.daughters(3) ; if( ! ( d0 == mcps[2] ) ) throw std::runtime_error(" error: 1. daughter of particle 0 is not particle 2 "); if( ! ( d1 == mcps[3] ) ) throw std::runtime_error(" error: 2. daughter of particle 0 is not particle 3 "); if( ! ( d2 == mcps[4] ) ) throw std::runtime_error(" error: 3. daughter of particle 0 is not particle 4 "); if( ! ( d3 == mcps[5] ) ) throw std::runtime_error(" error: 4. daughter of particle 0 is not particle 5 "); // particle 3 has particles 6,7,8 and 9 as daughters: p = mcps[3] ; d0 = p.daughters(0) ; d1 = p.daughters(1) ; d2 = p.daughters(2) ; d3 = p.daughters(3) ; if( ! ( d0 == mcps[6] ) ) throw std::runtime_error(" error: 1. daughter of particle 3 is not particle 6 "); if( ! ( d1 == mcps[7] ) ) throw std::runtime_error(" error: 2. daughter of particle 3 is not particle 7 "); if( ! ( d2 == mcps[8] ) ) throw std::runtime_error(" error: 3. daughter of particle 3 is not particle 8 "); if( ! ( d3 == mcps[9] ) ) throw std::runtime_error(" error: 4. daughter of particle 3 is not particle 9 "); } else { throw std::runtime_error("Collection 'mcparticles' should be present"); } //std::cout << "Fetching collection 'refs'" << std::endl; auto& refs = store.get<ExampleReferencingTypeCollection>("refs"); if(refs.isValid()){ auto ref = refs[0]; for (auto j = ref.Clusters_begin(), end = ref.Clusters_end(); j!=end; ++j){ for (auto i = j->Hits_begin(), end = j->Hits_end(); i!=end; ++i){ //std::cout << " Referenced object has an energy of " << i->energy() << std::endl; glob++; } } } else { throw std::runtime_error("Collection 'refs' should be present"); } //std::cout << "Fetching collection 'OneRelation'" << std::endl; auto& rels = store.get<ExampleWithOneRelationCollection>("OneRelation"); if(rels.isValid()) { //std::cout << "Referenced object has an energy of " << (*rels)[0].cluster().energy() << std::endl; glob++; } else { throw std::runtime_error("Collection 'OneRelation' should be present"); } // std::cout << "Fetching collection 'WithVectorMember'" << std::endl; auto& vecs = store.get<ExampleWithVectorMemberCollection>("WithVectorMember"); if(vecs.isValid()) { std::cout << vecs.size() << std::endl; for( auto item : vecs ) for (auto c = item.count_begin(), end = item.count_end(); c!=end; ++c){ std::cout << " Counter value " << (*c) << std::endl; glob++; } } else { throw std::runtime_error("Collection 'WithVectorMember' should be present"); } auto& comps = store.get<ExampleWithComponentCollection>("Component"); if (comps.isValid()) { auto comp = comps[0]; int a = comp.component().data.x + comp.component().data.z; } auto& arrays = store.get<ExampleWithArrayCollection>("arrays"); if (arrays.isValid() && arrays.size() != 0) { auto array = arrays[0]; if (array.myArray(1) != eventNum) { throw std::runtime_error("Array not properly set."); } if (array.arrayStruct().data.p.at(2) != 2*eventNum) { throw std::runtime_error("Array not properly set."); } if (array.structArray(0).x != eventNum) { throw std::runtime_error("Array of struct not properly set."); } } else { throw std::runtime_error("Collection 'arrays' should be present"); } auto& nmspaces = store.get<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& copies = store.get<ex::ExampleWithARelationCollection>("WithNamespaceRelationCopy"); auto& cpytest = store.create<ex::ExampleWithARelationCollection>("TestConstCopy"); if (nmspaces.isValid() && copies.isValid()) { for (int j = 0; j < nmspaces.size(); j++) { auto nmsp = nmspaces[j]; auto cpy = copies[j]; cpytest.push_back(nmsp.clone()); if (nmsp.ref().isAvailable()) { if (nmsp.ref().data().x != cpy.ref().data().x || nmsp.ref().data().y != cpy.ref().data().y) { throw std::runtime_error("Copied item has differing data in OneToOne referenced item."); } // check direct accessors of POD sub members if (nmsp.ref().x() != cpy.ref().x()) { throw std::runtime_error("Getting wrong values when using direct accessors for sub members."); } if (nmsp.number() != cpy.number()) { throw std::runtime_error("Copied item has differing member."); } if (!(nmsp.ref().getObjectID() == cpy.ref().getObjectID())) { throw std::runtime_error("Copied item has wrong OneToOne references."); } } auto cpy_it = cpy.refs_begin(); for (auto it = nmsp.refs_begin(); it != nmsp.refs_end(); ++it, ++cpy_it) { if (it->data().x != cpy_it->data().x || it->data().y != cpy_it->data().y) { throw std::runtime_error("Copied item has differing data in OneToMany referenced item."); } if (!(it->getObjectID() == cpy_it->getObjectID())) { throw std::runtime_error("Copied item has wrong OneToMany references."); } } } } else { throw std::runtime_error("Collection 'WithNamespaceRelation' and 'WithNamespaceRelationCopy' should be present"); } }
std::string toString() const { return getObjectID(); }
bool DisplayElement::validToDraw(DisplayOrder backLayer, DisplayOrder frontLayer) { return isDisplaying() && _elementIsVisible && (getObjectID() <= kHighestReservedElementID || (getDisplayOrder() >= backLayer && getDisplayOrder() <= frontLayer)); }
void GroupObjectImplementation::startChatRoom(CreatureObject* leader) { ChatManager* chatManager = server->getZoneServer()->getChatManager(); chatRoom = chatManager->createGroupRoom(getObjectID(), leader); }
int ConsumableImplementation::handleObjectMenuSelect(CreatureObject* player, byte selectedID) { if (!isASubChildOf(player)) return 0; if (selectedID != 20) { return TangibleObjectImplementation::handleObjectMenuSelect(player, selectedID); } if (speciesRestriction == "pets") { player->sendSystemMessage("@error_message:pets_only"); //That food is only suitable for pets. return 0; } PlayerObject* ghost = player->getPlayerObject(); String raceName = player->getSpeciesName(); if ((speciesRestriction == "2" && raceName != "trandoshan") || (speciesRestriction == "4" && raceName != "wookiee")) { player->sendSystemMessage("@error_message:race_restriction"); //That food isn't edible by your species. return 0; } if (isSpice() && player->hasSpice()) { player->sendSystemMessage("@spice/spice:sys_already_spiced"); //You are already under the influence of spices. return 0; } if (player->hasBuff(buffCRC) && (!isAttributeEffect() || isForagedFood())) { player->sendSystemMessage("@combat_effects:already_affected"); //You are already under the influence of that food. Eating more won't enhance the effect. return 0; } if (player->isDead() || player->isIncapacitated()) return 0; int availfill = 0; if (ghost == NULL) return 1; if (isFood()) availfill = ghost->getFoodFillingMax() - ghost->getFoodFilling(); if (isDrink()) availfill = ghost->getDrinkFillingMax() - ghost->getDrinkFilling(); if (filling > availfill) { if (isFood()) player->sendSystemMessage("@error_message:full_food"); //You are too full to eat that. if (isDrink()) player->sendSystemMessage("@error_message:full_drink"); //You are too full to drink that. return 1; } ManagedReference<Buff*> buff = NULL; switch (effectType) { case EFFECT_ATTRIBUTE: { buff = new Buff(player, buffName.hashCode(), duration, BuffType::FOOD); setModifiers(buff, false); break; } case EFFECT_SKILL: { buff = new Buff(player, buffName.hashCode(), duration, BuffType::FOOD); setModifiers(buff, true); break; } case EFFECT_SPICE: { buff = new SpiceBuff(player, buffName, String("spice." + buffName + ".up").hashCode(), duration); setModifiers(buff, false); //buff->parseAttributeModifierString(modifierString); player->addBuff(buff); //useCharge(player); decreaseUseCount(); return 1; } case EFFECT_HEALING: { int dmghealed = player->healDamage(player, 6, nutrition); if (dmghealed <= 0) { player->sendSystemMessage("@healing:no_mind_to_heal_self"); //You have no mind to heal. return 0; } StringIdChatParameter stringId("combat_effects", "food_mind_heal"); stringId.setDI(dmghealed); player->sendSystemMessage(stringId); break; } case EFFECT_DURATION: { buff = new DurationBuff(player, buffName.hashCode(), duration); setModifiers(buff, true); //buff->parseSkillModifierString(generateModifierString()); break; } case EFFECT_DELAYED: { buff = new DelayedBuff(player, buffName.hashCode(), duration); setModifiers(buff, true); DelayedBuff* delayedBuff = cast<DelayedBuff*>(buff.get()); delayedBuff->init(&eventTypes); break; } case EFFECT_INSTANT: { if (modifiers.isEmpty()) return 0; //TODO: Handle each instant effect on its own... String effect = modifiers.elementAt(0).getKey(); if (effect == "burst_run") { //We need to reduce the cooldown and efficiency. player->executeObjectControllerAction(String("burstrun").hashCode()); if (player->hasBuff(String("burstrun").hashCode())) { float reduction = 1.f - ((float)nutrition / 100.f); player->updateCooldownTimer("burstrun", ((300 * reduction) + duration) * 1000); player->sendSystemMessage("@combat_effects:instant_burst_run"); //You instantly burst run at increased efficiency! Reference<Task*> task = player->getPendingTask("burst_run_notify"); if (task != NULL) task->reschedule(((300 * reduction) + duration) * 1000); else { task = new BurstRunNotifyAvailableEvent(player); player->addPendingTask("burst_run_notify", task, ((300 * reduction) + duration) * 1000); } } else { //Couldnt burst run yet. return 0; } } else if (effect == "food_reduce") { //Tilla till reduces food stomach filling by a percentage int currentfilling = ghost->getFoodFilling(); ghost->setFoodFilling(round(currentfilling * (100 - nutrition) / 100.0f), true); } } } if (buff != NULL) player->addBuff(buff); if (isFood()) ghost->setFoodFilling(ghost->getFoodFilling() + filling, true); if (isDrink()) ghost->setDrinkFilling(ghost->getDrinkFilling() + filling, true); StringIdChatParameter stringId("base_player", "prose_consume_item"); stringId.setTT(getObjectID()); player->sendSystemMessage(stringId);//player->sendSystemMessage("base_player", "prose_consume_item", objectID);; // Play the client effect sound depending on species/gender. // Get the species. int species = player->getSpecies(); switch (species) { case 0: // Human if (player->getGender() == 0) player->playEffect("clienteffect/human_male_eat.cef"); else if (player->getGender() == 1) player->playEffect("clienteffect/human_female_eat.cef"); break; case 2: // Trandoshan if (player->getGender() == 0) player->playEffect("clienteffect/reptile_male_eat.cef"); else if (player->getGender() == 1) player->playEffect("clienteffect/reptile_female_eat.cef"); break; case 4: // Wookiee if (player->getGender() == 0) player->playEffect("clienteffect/wookiee_male_eat.cef"); else if (player->getGender() == 1) player->playEffect("clienteffect/wookiee_female_eat.cef"); break; default: break; } //Consume a charge from the item, destroy it if it reaches 0 charges remaining. //useCharge(player); decreaseUseCount(); return 0; }
/// \param name Specifies the name of the object. /// \return A pointer to the object. /// \warning Do not call \c delete on this function's return value. GameObject *GameObjectManager::getObjectPointer(const std::string &name) { return getObjectPointer(getObjectID(name)); }