Пример #1
0
/**
 * Check if the given tile is a valid destination. In case of for example
 *  a carry-all it checks if the unit carrying can be placed on destination.
 * In case of structures, it checks if you can walk into it.
 *
 * Stack: 1 - An encoded tile, indicating the destination.
 *
 * @param script The script engine to operate on.
 * @return ??.
 */
uint16 Script_Unit_IsValidDestination(ScriptEngine *script)
{
	Unit *u;
	Unit *u2;
	uint16 encoded;
	uint16 index;

	u = g_scriptCurrentUnit;
	encoded = STACK_PEEK(1);
	index = Tools_Index_Decode(encoded);

	switch (Tools_Index_GetType(encoded)) {
		case IT_TILE:
			if (!Map_IsValidPosition(index)) return 1;
			if (u->o.linkedID == 0xFF) return 1;
			u2 = Unit_Get_ByIndex(u->o.linkedID);
			u2->o.position = Tools_Index_GetTile(encoded);
			if (!Unit_IsTileOccupied(u2)) return 0;
			u2->o.position.tile = 0xFFFFFFFF;
			return 1;

		case IT_STRUCTURE: {
			Structure *s;

			s = Structure_Get_ByIndex(index);
			if (s->o.houseID == Unit_GetHouseID(u)) return 0;
			if (u->o.linkedID == 0xFF) return 1;
			u2 = Unit_Get_ByIndex(u->o.linkedID);
			return Unit_IsValidMovementIntoStructure(u2, s) != 0 ? 1 : 0;
		}

		default: return 1;
	}
}
Пример #2
0
/**
 * @brief   f__167E_0005_0013_AF0C.
 * @details Removed guard for IT_UNIT.
 */
bool Tools_Index_IsValid(uint16 encoded)
{
	if (encoded == 0)
		return false;

	uint16 index = Tools_Index_Decode(encoded);
	switch (Tools_Index_GetType(encoded))
	{
	case IT_UNIT:
		{
			const Unit* u = Unit_Get_ByIndex(index);
			return u->o.flags.s.used && u->o.flags.s.allocated;
		}

	case IT_STRUCTURE:
		{
			const Structure* s = Structure_Get_ByIndex(index);
			return s->o.flags.s.used;
		}

	case IT_TILE:
	case IT_NONE:
	default:
		return true;
	}

	return false;
}