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

Function Structure_Place

src/structure.c:442–616  ·  view source on GitHub ↗

* Place a structure on the map. * * @param structure The structure to place on the map. * @param position The (packed) tile to place the struction on. * @return True if and only if the structure is placed on the map. */

Source from the content-addressed store, hash-verified

440 * @return True if and only if the structure is placed on the map.
441 */
442bool Structure_Place(Structure *s, uint16 position)
443{
444 const StructureInfo *si;
445 int16 validBuildLocation;
446
447 if (s == NULL) return false;
448 if (position == 0xFFFF) return false;
449
450 si = &g_table_structureInfo[s->o.type];
451
452 switch (s->o.type) {
453 case STRUCTURE_WALL: {
454 Tile *t;
455
456 if (Structure_IsValidBuildLocation(position, STRUCTURE_WALL) == 0) return false;
457
458 t = &g_map[position];
459 t->groundTileID = g_wallTileID + 1;
460 /* ENHANCEMENT -- Dune2 wrongfully only removes the lower 2 bits, where the lower 3 bits are the owner. This is no longer visible. */
461 t->houseID = s->o.houseID;
462
463 g_mapTileID[position] |= 0x8000;
464
465 if (s->o.houseID == g_playerHouseID) Tile_RemoveFogInRadius(Tile_UnpackTile(position), 1);
466
467 if (Map_IsPositionUnveiled(position)) t->overlayTileID = 0;
468
469 Structure_ConnectWall(position, true);
470 Structure_Free(s);
471
472 } return true;
473
474 case STRUCTURE_SLAB_1x1:
475 case STRUCTURE_SLAB_2x2: {
476 uint16 i, result;
477
478 result = 0;
479
480 for (i = 0; i < g_table_structure_layoutTileCount[si->layout]; i++) {
481 uint16 curPos = position + g_table_structure_layoutTiles[si->layout][i];
482 Tile *t = &g_map[curPos];
483
484 if (Structure_IsValidBuildLocation(curPos, STRUCTURE_SLAB_1x1) == 0) continue;
485
486 t->groundTileID = g_builtSlabTileID;
487 t->houseID = s->o.houseID;
488
489 g_mapTileID[curPos] |= 0x8000;
490
491 if (s->o.houseID == g_playerHouseID) Tile_RemoveFogInRadius(Tile_UnpackTile(curPos), 1);
492
493 if (Map_IsPositionUnveiled(curPos)) t->overlayTileID = 0;
494
495 Map_Update(curPos, 0, false);
496
497 result = 1;
498 }
499

Callers 3

GameLoop_StructureFunction · 0.85
Structure_CreateFunction · 0.85

Calls 15

Tile_RemoveFogInRadiusFunction · 0.85
Tile_UnpackTileFunction · 0.85
Map_IsPositionUnveiledFunction · 0.85
Structure_ConnectWallFunction · 0.85
Structure_FreeFunction · 0.85
Map_UpdateFunction · 0.85
Script_ResetFunction · 0.85
Script_LoadFunction · 0.85
Unit_Get_ByPackedTileFunction · 0.85
Unit_RemoveFunction · 0.85
House_Get_ByIndexFunction · 0.85

Tested by

no test coverage detected