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

Function Unit_UpdateMap

src/unit.c:2466–2525  ·  view source on GitHub ↗

* Update the map around the Unit depending on the type (entering tile, leaving, staying). * @param type The type of action on the map. * @param unit The Unit doing the action. */

Source from the content-addressed store, hash-verified

2464 * @param unit The Unit doing the action.
2465 */
2466void Unit_UpdateMap(uint16 type, Unit *unit)
2467{
2468 const UnitInfo *ui;
2469 tile32 position;
2470 uint16 packed;
2471 Tile *t;
2472 uint16 radius;
2473
2474 if (unit == NULL || unit->o.flags.s.isNotOnMap || !unit->o.flags.s.used) return;
2475
2476 ui = &g_table_unitInfo[unit->o.type];
2477
2478 if (ui->movementType == MOVEMENT_WINGER) {
2479 if (type != 0) {
2480 unit->o.flags.s.isDirty = true;
2481 g_dirtyAirUnitCount++;
2482 }
2483
2484 Map_UpdateAround(g_table_unitInfo[unit->o.type].dimension, unit->o.position, unit, g_functions[0][type]);
2485 return;
2486 }
2487
2488 position = unit->o.position;
2489 packed = Tile_PackTile(position);
2490 t = &g_map[packed];
2491
2492 if (t->isUnveiled || unit->o.houseID == g_playerHouseID) {
2493 Unit_HouseUnitCount_Add(unit, g_playerHouseID);
2494 } else {
2495 Unit_HouseUnitCount_Remove(unit);
2496 }
2497
2498 if (type == 1) {
2499 if (House_AreAllied(Unit_GetHouseID(unit), g_playerHouseID) && !Map_IsPositionUnveiled(packed) && unit->o.type != UNIT_SANDWORM) {
2500 Tile_RemoveFogInRadius(position, 1);
2501 }
2502
2503 if (Object_GetByPackedTile(packed) == NULL) {
2504 t->index = unit->o.index + 1;
2505 t->hasUnit = true;
2506 }
2507 }
2508
2509 if (type != 0) {
2510 unit->o.flags.s.isDirty = true;
2511 g_dirtyUnitCount++;
2512 }
2513
2514 radius = ui->dimension + 3;
2515
2516 if (unit->o.flags.s.bulletIsBig || unit->o.flags.s.isSmoking || (unit->o.type == UNIT_HARVESTER && unit->actionID == ACTION_HARVEST)) radius = 33;
2517
2518 Map_UpdateAround(radius, position, unit, g_functions[1][type]);
2519
2520 if (unit->o.type != UNIT_HARVESTER) return;
2521
2522 /* The harvester is the only 2x1 unit, so also update tiles in behind us. */
2523 Map_UpdateAround(radius, unit->targetPreLast, unit, g_functions[1][type]);

Callers 15

Unit_RotateFunction · 0.85
GameLoop_UnitFunction · 0.85
Unit_CreateFunction · 0.85
Unit_SetPositionFunction · 0.85
Unit_RemoveFunction · 0.85
Unit_StartMovementFunction · 0.85
Unit_Deviation_DecreaseFunction · 0.85
Unit_DeviateFunction · 0.85
Unit_MoveFunction · 0.85
Unit_DamageFunction · 0.85
Unit_SelectFunction · 0.85
Unit_HideFunction · 0.85

Calls 8

Map_UpdateAroundFunction · 0.85
Unit_HouseUnitCount_AddFunction · 0.85
House_AreAlliedFunction · 0.85
Unit_GetHouseIDFunction · 0.85
Map_IsPositionUnveiledFunction · 0.85
Tile_RemoveFogInRadiusFunction · 0.85
Object_GetByPackedTileFunction · 0.85

Tested by

no test coverage detected