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

Function Script_Unit_Harvest

src/script/unit.c:1640–1670  ·  view source on GitHub ↗

* Make the current unit harvest spice. * * Stack: *none*. * * @param script The script engine to operate on. * @return ??. */

Source from the content-addressed store, hash-verified

1638 * @return ??.
1639 */
1640uint16 Script_Unit_Harvest(ScriptEngine *script)
1641{
1642 Unit *u;
1643 uint16 packed;
1644 uint16 type;
1645
1646 VARIABLE_NOT_USED(script);
1647
1648 u = g_scriptCurrentUnit;
1649
1650 if (u->o.type != UNIT_HARVESTER) return 0;
1651 if (u->amount >= 100) return 0;
1652
1653 packed = Tile_PackTile(u->o.position);
1654
1655 type = Map_GetLandscapeType(packed);
1656 if (type != LST_SPICE && type != LST_THICK_SPICE) return 0;
1657
1658 u->amount += Tools_Random_256() & 1;
1659 u->o.flags.s.inTransport = true;
1660
1661 Unit_UpdateMap(2, u);
1662
1663 if (u->amount > 100) u->amount = 100;
1664
1665 if ((Tools_Random_256() & 0x1F) != 0) return 1;
1666
1667 Map_ChangeSpiceAmount(packed, -1);
1668
1669 return 0;
1670}
1671
1672/**
1673 * Check if the given tile is a valid destination. In case of for example

Callers

nothing calls this directly

Calls 4

Map_GetLandscapeTypeFunction · 0.85
Tools_Random_256Function · 0.85
Unit_UpdateMapFunction · 0.85
Map_ChangeSpiceAmountFunction · 0.85

Tested by

no test coverage detected