MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Script_Unit_IsValidDestination

Function Script_Unit_IsValidDestination

src/script/unit.c:1682–1716  ·  view source on GitHub ↗

* 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 ??. */

Source from the content-addressed store, hash-verified

1680 * @return ??.
1681 */
1682uint16 Script_Unit_IsValidDestination(ScriptEngine *script)
1683{
1684 Unit *u;
1685 Unit *u2;
1686 uint16 encoded;
1687 uint16 index;
1688
1689 u = g_scriptCurrentUnit;
1690 encoded = STACK_PEEK(1);
1691 index = Tools_Index_Decode(encoded);
1692
1693 switch (Tools_Index_GetType(encoded)) {
1694 case IT_TILE:
1695 if (!Map_IsValidPosition(index)) return 1;
1696 if (u->o.linkedID == 0xFF) return 1;
1697 u2 = Unit_Get_ByIndex(u->o.linkedID);
1698 u2->o.position = Tools_Index_GetTile(encoded);
1699 if (!Unit_IsTileOccupied(u2)) return 0;
1700 u2->o.position.x = 0xFFFF;
1701 u2->o.position.y = 0xFFFF;
1702 return 1;
1703
1704 case IT_STRUCTURE: {
1705 Structure *s;
1706
1707 s = Structure_Get_ByIndex(index);
1708 if (s->o.houseID == Unit_GetHouseID(u)) return 0;
1709 if (u->o.linkedID == 0xFF) return 1;
1710 u2 = Unit_Get_ByIndex(u->o.linkedID);
1711 return Unit_IsValidMovementIntoStructure(u2, s) != 0 ? 1 : 0;
1712 }
1713
1714 default: return 1;
1715 }
1716}
1717
1718/**
1719 * Get a random tile around the Unit.

Callers

nothing calls this directly

Calls 9

Tools_Index_DecodeFunction · 0.85
Tools_Index_GetTypeFunction · 0.85
Map_IsValidPositionFunction · 0.85
Unit_Get_ByIndexFunction · 0.85
Tools_Index_GetTileFunction · 0.85
Unit_IsTileOccupiedFunction · 0.85
Structure_Get_ByIndexFunction · 0.85
Unit_GetHouseIDFunction · 0.85

Tested by

no test coverage detected