Ejemplo n.º 1
0
void Object::Destroy()
{
	for(auto it = playerObjectsOwned->begin(); it != playerObjectsOwned->end(); it++)
	{
		DestroyPlayerObject(it->first, it->second);
	}
}
Ejemplo n.º 2
0
void Object::RemovePlayerObject(int player)
{
	if(playerObjectsOwned->find(player) != playerObjectsOwned->end())
	{
		DestroyPlayerObject(player, playerObjectsOwned->find(player)->second);
		playerObjectsOwned->erase(player);
	}
}
Ejemplo n.º 3
0
void Object::RemoveAll()
{
	for(auto it = playerObjectsOwned->begin(); it != playerObjectsOwned->end(); it++)
	{
		DestroyPlayerObject(it->first, it->second);
		playerObjectsOwned->erase(it->first);
	}
}
cell AMX_NATIVE_CALL Natives::Streamer_DestroyAllVisibleItems(AMX *amx, cell *params)
{
	CHECK_PARAMS(3, "Streamer_DestroyAllVisibleItems");
	bool serverWide = static_cast<int>(params[3]) != 0;
	switch (static_cast<int>(params[2]))
	{
		case STREAMER_TYPE_PICKUP:
		{
			boost::unordered_map<int, int>::iterator p = core->getData()->internalPickups.begin();
			while (p != core->getData()->internalPickups.end())
			{
				boost::unordered_map<int, Item::SharedPickup>::iterator q = core->getData()->pickups.find(p->first);
				if (serverWide || (q != core->getData()->pickups.end() && q->second->amx == amx))
				{
					DestroyPickup(p->second);
					p = core->getData()->internalPickups.erase(p);
				}
				else
				{
					++p;
				}
			}
			return 1;
		}
		case STREAMER_TYPE_VEHICLE:
		{
			boost::unordered_map<int, int>::iterator p = core->getData()->internalVehicles.begin();
			while (p != core->getData()->internalPickups.end())
			{
				boost::unordered_map<int, Item::SharedVehicle>::iterator q = core->getData()->vehicles.find(p->first);
				if (serverWide || (q != core->getData()->vehicles.end() && q->second->amx == amx))
				{
					DestroyVehicle(p->second);
					p = core->getData()->internalVehicles.erase(p);
				}
				else
				{
					++p;
				}
			}
			return 1;
		}
	}
	boost::unordered_map<int, Player>::iterator p = core->getData()->players.find(static_cast<int>(params[1]));
	if (p != core->getData()->players.end())
	{
		switch (static_cast<int>(params[2]))
		{
			case STREAMER_TYPE_OBJECT:
			{
				boost::unordered_map<int, int>::iterator o = p->second.internalObjects.begin();
				while (o != p->second.internalObjects.end())
				{
					boost::unordered_map<int, Item::SharedObject>::iterator q = core->getData()->objects.find(o->first);
					if (serverWide || (q != core->getData()->objects.end() && q->second->amx == amx))
					{
						DestroyPlayerObject(p->first, o->second);
						o = p->second.internalObjects.erase(o);
					}
					else
					{
						++o;
					}
				}
				return 1;
			}
			case STREAMER_TYPE_CP:
			{
				if (p->second.visibleCheckpoint)
				{
					boost::unordered_map<int, Item::SharedCheckpoint>::iterator c = core->getData()->checkpoints.find(p->second.visibleCheckpoint);
					if (serverWide || (c != core->getData()->checkpoints.end() && c->second->amx == amx))
					{
						DisablePlayerCheckpoint(p->first);
						p->second.activeCheckpoint = 0;
						p->second.visibleCheckpoint = 0;
						return 1;
					}
				}
				return 0;
			}
			case STREAMER_TYPE_RACE_CP:
			{
				if (p->second.visibleRaceCheckpoint)
				{
					boost::unordered_map<int, Item::SharedRaceCheckpoint>::iterator r = core->getData()->raceCheckpoints.find(p->second.visibleRaceCheckpoint);
					if (serverWide || (r != core->getData()->raceCheckpoints.end() && r->second->amx == amx))
					{
						DisablePlayerRaceCheckpoint(p->first);
						p->second.activeRaceCheckpoint = 0;
						p->second.visibleRaceCheckpoint = 0;
						return 1;
					}
				}
				return 0;
			}
			case STREAMER_TYPE_MAP_ICON:
			{
				boost::unordered_map<int, int>::iterator m = p->second.internalMapIcons.begin();
				while (m != p->second.internalMapIcons.end())
				{
					boost::unordered_map<int, Item::SharedMapIcon>::iterator n = core->getData()->mapIcons.find(m->first);
					if (serverWide || (n != core->getData()->mapIcons.end() && n->second->amx == amx))
					{
						RemovePlayerMapIcon(p->first, m->second);
						m = p->second.internalMapIcons.erase(m);
					}
					else
					{
						++m;
					}
				}
				return 1;
			}
			case STREAMER_TYPE_3D_TEXT_LABEL:
			{
				boost::unordered_map<int, int>::iterator t = p->second.internalTextLabels.begin();
				while (t != p->second.internalMapIcons.end())
				{
					boost::unordered_map<int, Item::SharedTextLabel>::iterator u = core->getData()->textLabels.find(t->first);
					if (serverWide || (u != core->getData()->textLabels.end() && u->second->amx == amx))
					{
						DeletePlayer3DTextLabel(p->first, t->second);
						t = p->second.internalTextLabels.erase(t);
					}
					else
					{
						++t;
					}
				}
				return 1;
			}
			case STREAMER_TYPE_AREA:
			{
				boost::unordered_set<int>::iterator a = p->second.internalAreas.begin();
				while (a != p->second.internalAreas.end())
				{
					boost::unordered_map<int, Item::SharedArea>::iterator b = core->getData()->areas.find(*a);
					if (serverWide || (b != core->getData()->areas.end() && b->second->amx == amx))
					{
						a = p->second.internalAreas.erase(a);
					}
					else
					{
						++a;
					}
				}
				return 1;
			}
			default:
			{
				Utility::logError("Streamer_DestroyAllVisibleItems: Invalid type specified");
				return 0;
			}
		}
	}
	return 0;
}
void Streamer::processObjects(Player &player, const std::vector<SharedCell> &cells)
{
	std::multimap<float, Item::SharedObject> discoveredObjects, existingObjects;
	for (std::vector<SharedCell>::const_iterator c = cells.begin(); c != cells.end(); ++c)
	{
		for (boost::unordered_map<int, Item::SharedObject>::const_iterator o = (*c)->objects.begin(); o != (*c)->objects.end(); ++o)
		{
			float distance = std::numeric_limits<float>::infinity();
			if (checkPlayer(o->second->players, player.playerID, o->second->interiors, player.interiorID, o->second->worlds, player.worldID))
			{
				if (o->second->attach)
				{
					distance = static_cast<float>(boost::geometry::comparable_distance(player.position, o->second->attach->position));
				}
				else
				{
					distance = static_cast<float>(boost::geometry::comparable_distance(player.position, o->second->position));
				}
			}
			boost::unordered_map<int, int>::iterator i = player.internalObjects.find(o->first);
			if (distance <= o->second->streamDistance)
			{
				if (i == player.internalObjects.end())
				{
					discoveredObjects.insert(std::make_pair(distance, o->second));
				}
				else
				{
					if (o->second->cell)
					{
						player.visibleCell->objects.insert(*o);
					}
					existingObjects.insert(std::make_pair(distance, o->second));
				}
			}
			else
			{
				if (i != player.internalObjects.end())
				{
					DestroyPlayerObject(player.playerID, i->second);
					player.internalObjects.quick_erase(i);
				}
			}
		}
	}
	for (std::multimap<float, Item::SharedObject>::iterator d = discoveredObjects.begin(); d != discoveredObjects.end(); ++d)
	{
		if (player.internalObjects.size() == player.visibleObjects)
		{
			std::multimap<float, Item::SharedObject>::reverse_iterator e = existingObjects.rbegin();
			if (e != existingObjects.rend())
			{
				if (d->first < e->first)
				{
					boost::unordered_map<int, int>::iterator i = player.internalObjects.find(e->second->objectID);
					if (i != player.internalObjects.end())
					{
						DestroyPlayerObject(player.playerID, i->second);
						player.internalObjects.quick_erase(i);
					}
					if (e->second->cell)
					{
						player.visibleCell->objects.erase(e->second->objectID);
					}
					existingObjects.erase(--e.base());
				}
			}
		}
		if (player.internalObjects.size() == visibleObjects)
		{
			player.visibleObjects = player.internalObjects.size();
			break;
		}
		int internalID = CreatePlayerObject(player.playerID, d->second->modelID, d->second->position[0], d->second->position[1], d->second->position[2], d->second->rotation[0], d->second->rotation[1], d->second->rotation[2], d->second->drawDistance);
		if (internalID == INVALID_GENERIC_ID)
		{
			player.visibleObjects = player.internalObjects.size();
			break;
		}
		if (d->second->attach)
		{
			AttachPlayerObjectToVehicle(player.playerID, internalID, d->second->attach->vehicle, d->second->attach->offset[0], d->second->attach->offset[1], d->second->attach->offset[2], d->second->attach->rotation[0], d->second->attach->rotation[1], d->second->attach->rotation[2]);
		}
		else if (d->second->move)
		{
			MovePlayerObject(player.playerID, internalID, d->second->move->position.get<0>()[0], d->second->move->position.get<0>()[1], d->second->move->position.get<0>()[2], d->second->move->speed, d->second->move->rotation.get<0>()[0], d->second->move->rotation.get<0>()[1], d->second->move->rotation.get<0>()[2]);
		}
		for (boost::unordered_map<int, Item::Object::Material>::iterator m = d->second->materials.begin(); m != d->second->materials.end(); ++m)
		{
			if (m->second.main)
			{
				SetPlayerObjectMaterial(player.playerID, internalID, m->first, m->second.main->modelID, m->second.main->txdFileName.c_str(), m->second.main->textureName.c_str(), m->second.main->materialColor);
			}
			else if (m->second.text)
			{
				SetPlayerObjectMaterialText(player.playerID, internalID, m->second.text->materialText.c_str(), m->first, m->second.text->materialSize, m->second.text->fontFace.c_str(), m->second.text->fontSize, m->second.text->bold, m->second.text->fontColor, m->second.text->backColor, m->second.text->textAlignment);
			}
		}
		player.internalObjects.insert(std::make_pair(d->second->objectID, internalID));
		if (d->second->cell)
		{
			player.visibleCell->objects.insert(std::make_pair(d->second->objectID, d->second));
		}
	}
}