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

Function Unit_EnterStructure

src/unit.c:2177–2266  ·  view source on GitHub ↗

* Handles what happens when the given unit enters into the given structure. * * @param unit The Unit. * @param s The Structure. */

Source from the content-addressed store, hash-verified

2175 * @param s The Structure.
2176 */
2177void Unit_EnterStructure(Unit *unit, Structure *s)
2178{
2179 const StructureInfo *si;
2180 const UnitInfo *ui;
2181
2182 if (unit == NULL || s == NULL) return;
2183
2184 if (unit == g_unitSelected) {
2185 /* ENHANCEMENT -- When a Unit enters a Structure, the last tile the Unit was on becomes selected rather than the entire Structure. */
2186 if (g_dune2_enhanced) {
2187 Map_SetSelection(Tile_PackTile(s->o.position));
2188 } else {
2189 Unit_Select(NULL);
2190 }
2191 }
2192
2193 ui = &g_table_unitInfo[unit->o.type];
2194 si = &g_table_structureInfo[s->o.type];
2195
2196 if (!unit->o.flags.s.allocated || s->o.hitpoints == 0) {
2197 Unit_Remove(unit);
2198 return;
2199 }
2200
2201 unit->o.seenByHouses |= s->o.seenByHouses;
2202 Unit_Hide(unit);
2203
2204 if (House_AreAllied(s->o.houseID, Unit_GetHouseID(unit))) {
2205 Structure_SetState(s, si->o.flags.busyStateIsIncoming ? STRUCTURE_STATE_READY : STRUCTURE_STATE_BUSY);
2206
2207 if (s->o.type == STRUCTURE_REPAIR) {
2208 uint16 countDown;
2209
2210 countDown = ((ui->o.hitpoints - unit->o.hitpoints) * 256 / ui->o.hitpoints) * (ui->o.buildTime << 6) / 256;
2211
2212 if (countDown > 1) {
2213 s->countDown = countDown;
2214 } else {
2215 s->countDown = 1;
2216 }
2217 unit->o.hitpoints = ui->o.hitpoints;
2218 unit->o.flags.s.isSmoking = false;
2219 unit->spriteOffset = 0;
2220 }
2221 unit->o.linkedID = s->o.linkedID;
2222 s->o.linkedID = unit->o.index & 0xFF;
2223 return;
2224 }
2225
2226 if (unit->o.type == UNIT_SABOTEUR) {
2227 Structure_Damage(s, 500, 1);
2228 Unit_Remove(unit);
2229 return;
2230 }
2231
2232 /* Take over the building when low on hitpoints */
2233 if (s->o.hitpoints < si->o.hitpoints / 4) {
2234 House *h;

Callers 2

Unit_MoveFunction · 0.85

Calls 15

Map_SetSelectionFunction · 0.85
Unit_SelectFunction · 0.85
Unit_RemoveFunction · 0.85
Unit_HideFunction · 0.85
House_AreAlliedFunction · 0.85
Unit_GetHouseIDFunction · 0.85
Structure_SetStateFunction · 0.85
Structure_DamageFunction · 0.85
House_Get_ByIndexFunction · 0.85
Unit_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected