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

Function Structure_IsValidBuildLocation

src/structure.c:734–815  ·  view source on GitHub ↗

* Checks if the given position is a valid location for the given structure type. * * @param position The (packed) tile to check. * @param type The structure type to check the position for. * @return 0 if the position is not valid, 1 if the position is valid and have enough slabs, <0 if the position is valid but miss some slabs. */

Source from the content-addressed store, hash-verified

732 * @return 0 if the position is not valid, 1 if the position is valid and have enough slabs, <0 if the position is valid but miss some slabs.
733 */
734int16 Structure_IsValidBuildLocation(uint16 position, StructureType type)
735{
736 const StructureInfo *si;
737 const uint16 *layoutTile;
738 uint8 i;
739 uint16 neededSlabs;
740 bool isValid;
741 uint16 curPos;
742
743 si = &g_table_structureInfo[type];
744 layoutTile = g_table_structure_layoutTiles[si->layout];
745
746 isValid = true;
747 neededSlabs = 0;
748 for (i = 0; i < g_table_structure_layoutTileCount[si->layout]; i++) {
749 uint16 lst;
750
751 curPos = position + layoutTile[i];
752
753 lst = Map_GetLandscapeType(curPos);
754
755 if (g_debugScenario) {
756 if (!g_table_landscapeInfo[lst].isValidForStructure2) {
757 isValid = false;
758 break;
759 }
760 } else {
761 if (!Map_IsValidPosition(curPos)) {
762 isValid = false;
763 break;
764 }
765
766 if (si->o.flags.notOnConcrete) {
767 if (!g_table_landscapeInfo[lst].isValidForStructure2 && g_validateStrictIfZero == 0) {
768 isValid = false;
769 break;
770 }
771 } else {
772 if (!g_table_landscapeInfo[lst].isValidForStructure && g_validateStrictIfZero == 0) {
773 isValid = false;
774 break;
775 }
776 if (lst != LST_CONCRETE_SLAB) neededSlabs++;
777 }
778 }
779
780 if (Object_GetByPackedTile(curPos) != NULL) {
781 isValid = false;
782 break;
783 }
784 }
785
786 if (g_validateStrictIfZero == 0 && isValid && type != STRUCTURE_CONSTRUCTION_YARD && !g_debugScenario) {
787 isValid = false;
788 for (i = 0; i < 16; i++) {
789 uint16 offset, lst;
790 Structure *s;
791

Callers 3

Structure_PlaceFunction · 0.85
Map_SetSelectionFunction · 0.85

Calls 4

Map_GetLandscapeTypeFunction · 0.85
Map_IsValidPositionFunction · 0.85
Object_GetByPackedTileFunction · 0.85

Tested by

no test coverage detected