Пример #1
0
static bool TryAddMapObject(
	Mission *m, const MapObject *mo, const Vec2i pos, CArray *objs)
{
	CASSERT(m->Type == MAPTYPE_STATIC, "invalid map type");
	const unsigned short tile = MissionGetTile(m, pos);

	// Remove any items already there
	TryRemoveMapObjectAt(pos, objs);

	if (MapObjectIsTileOK(
		mo, tile, 1, MissionGetTile(m, Vec2iNew(pos.x, pos.y - 1))))
	{
		// Check if the item already has an entry, and add to its list
		// of positions
		bool hasAdded = false;
		for (int i = 0; i < (int)objs->size; i++)
		{
			MapObjectPositions *mop = CArrayGet(objs, i);
			if (mop->M == mo)
			{
				CArrayPushBack(&mop->Positions, &pos);
				hasAdded = true;
				break;
			}
		}
		// If not, create a new entry
		if (!hasAdded)
		{
			MapObjectPositions mop;
			mop.M = mo;
			CArrayInit(&mop.Positions, sizeof(Vec2i));
			CArrayPushBack(&mop.Positions, &pos);
			CArrayPushBack(objs, &mop);
		}
		return true;
	}
	return false;
}
Пример #2
0
bool MissionStaticTryRemoveItemAt(Mission *m, const Vec2i pos)
{
	return TryRemoveMapObjectAt(pos, &m->u.Static.Items);
}
Пример #3
0
bool MissionStaticTryRemoveWreckAt(Mission *m, const Vec2i pos)
{
	return TryRemoveMapObjectAt(pos, &m->u.Static.Wrecks);
}