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

Function Script_Structure_RefineSpice

src/script/structure.c:105–153  ·  view source on GitHub ↗

* Refine spice in the current structure. * * Stack: *none* * * @param script The script engine to operate on. * @return 0 if there is no spice to refine, otherwise 1. */

Source from the content-addressed store, hash-verified

103 * @return 0 if there is no spice to refine, otherwise 1.
104 */
105uint16 Script_Structure_RefineSpice(ScriptEngine *script)
106{
107 const StructureInfo *si;
108 Structure *s;
109 Unit *u;
110 House *h;
111 uint16 harvesterStep, creditsStep;
112
113 VARIABLE_NOT_USED(script);
114
115 s = g_scriptCurrentStructure;
116
117 if (s->o.linkedID == 0xFF) {
118 Structure_SetState(s, STRUCTURE_STATE_IDLE);
119 return 0;
120 }
121
122 u = Unit_Get_ByIndex(s->o.linkedID);
123 si = &g_table_structureInfo[s->o.type];
124
125 harvesterStep = (s->o.hitpoints * 256 / si->o.hitpoints) * 3 / 256;
126
127 if (u->amount < harvesterStep) harvesterStep = u->amount;
128 if (u->amount != 0 && harvesterStep < 1) harvesterStep = 1;
129 if (harvesterStep == 0) return 0;
130
131 creditsStep = 7;
132 if (u->o.houseID != g_playerHouseID) {
133 creditsStep += (Tools_Random_256() % 4) - 1;
134 }
135
136 creditsStep *= harvesterStep;
137
138 if (House_AreAllied(g_playerHouseID, s->o.houseID)) {
139 g_scenario.harvestedAllied += creditsStep;
140 if (g_scenario.harvestedAllied > 65000) g_scenario.harvestedAllied = 65000;
141 } else {
142 g_scenario.harvestedEnemy += creditsStep;
143 if (g_scenario.harvestedEnemy > 65000) g_scenario.harvestedEnemy = 65000;
144 }
145
146 h = House_Get_ByIndex(s->o.houseID);
147 h->credits += creditsStep;
148 u->amount -= harvesterStep;
149
150 if (u->amount == 0) u->o.flags.s.inTransport = false;
151 s->o.script.delay = 6;
152 return 1;
153}
154
155/**
156 * Unknown function 0A81.

Callers

nothing calls this directly

Calls 5

Structure_SetStateFunction · 0.85
Unit_Get_ByIndexFunction · 0.85
Tools_Random_256Function · 0.85
House_AreAlliedFunction · 0.85
House_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected