Skip to content

Commit 0b2cbfb

Browse files
committed
Add toggle to allow building on overlays
- Also add doc section for OverlayTypes and move existing changes there from the misc. list
1 parent abb4cc5 commit 0b2cbfb

File tree

7 files changed

+130
-11
lines changed

7 files changed

+130
-11
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ This page lists all the individual contributions to the project by their author.
287287
- Deploy priority filtering
288288
- Customizable paradrop missions
289289
- Guard range customizations
290+
- Buildable-upon OverlayTypes
290291
- **Morton (MortonPL)**:
291292
- `XDrawOffset` for animations
292293
- Shield passthrough & absorption

docs/Fixed-or-Improved-Logics.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
118118
- Fixed `DeployToFire` not considering building placement rules for `DeploysInto` buildings and as a result not working properly with `WaterBound` buildings.
119119
- Fixed `DeployToFire` not recalculating firer's position on land if it cannot currently deploy.
120120
- `Arcing=true` projectile elevation inaccuracy can now be fixed by setting `Arcing.AllowElevationInaccuracy=false`.
121-
- Wall overlays are now drawn with the custom palette defined in `Palette` in `artmd.ini` if possible.
122121
- Setting `ReloadInTransport` to true on units with `Ammo` will allow the ammo to be reloaded according to `Reload` or `EmptyReload` timers even while the unit is inside a transport.
123122
- It is now possible to enable `Verses` and `PercentAtMax` to be applied on negative damage by setting `ApplyModifiersOnNegativeDamage` to true on the Warhead.
124123
- Attached animations on flying units now have their layer updated immediately after the parent unit, if on same layer they always draw above the parent.
@@ -146,7 +145,6 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
146145
- Units & buildings with `DecloakToFire=false` weapons now cloak while targeting & reloading.
147146
- Units with `Sensors=true` will no longer reveal ally buildings.
148147
- Air units are now reliably included by target scan with large range and Warhead detonation by large `CellSpread`.
149-
- OverlayTypes now read and use `ZAdjust` if specified in their `artmd.ini` entry.
150148
- Weapons with `AA=true` Projectile can now correctly fire at air units when both firer and target are over a bridge.
151149
- Fixed disguised units not using the correct palette if target has custom palette.
152150
- Building upgrades now consistently use building's `PowerUpN` animation settings corresponding to the upgrade's `PowersUpToLevel` where possible.
@@ -221,7 +219,6 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
221219
- Fixed the bug that infantry ignored `Passengers` and `SizeLimit` when entering buildings.
222220
- Fixed `VoiceDeploy` not played, when deployed through hot-key/command bar.
223221
- Fixed the bug that ships can travel on elevated bridges.
224-
- Dehardcoded 255 limit of `OverlayType`.
225222
- Fixed an issue where airstrike flare line drawn to target at lower elevation would clip.
226223
- Elite technos no longer scatter by default, behaviour is controlled by `SCATTER` veterancy ability now.
227224
- Second weapon with `ElectricAssault=yes` will not unconditionally attack your building with `Overpowerable=yes`.
@@ -1176,9 +1173,43 @@ ProneSpeed.NoCrawls=1.5 ; floating point value, multiplier
11761173
ProneSpeed= ; floating point value, multiplier, by default, use the corresponding global value according to Crawls
11771174
```
11781175

1179-
<!--
11801176
## Overlays
1181-
-->
1177+
1178+
### Buildable-upon OverlayTypes
1179+
1180+
- It is now possible to make OverlayTypes allow buildings to be placed on them by setting `CanBeBuiltOn` to true. This still requires the tile's landtype (which is changed to overlay's land type unless OverlayType has `NoUseTileLandType=false`) to allow buildings to be placed.
1181+
- If `CanBeBuiltOn.Remove=true`, the overlay will be removed upon the building being placed. If this is not set to true, buildings with `Wall=true` cannot be placed on the overlay and neither does overlay with `Wall=true` allow buildings to be placed on itself regardless of other settings.
1182+
1183+
In `rulesmd.ini`:
1184+
```ini
1185+
[SOMEOVERLAY] ; OverlayType
1186+
CanBeBuiltOn=false ; boolean
1187+
CanBeBuiltOn.Remove=true ; boolean
1188+
```
1189+
1190+
### More than 255 OverlayTypes
1191+
1192+
- Game now supports more than 255 distinct OverlayTypes, up to 65535. For map file/editor support, see [Increased Overlay Limit](AI-Scripting-and-Mapping.md#increased-overlay-limit).
1193+
1194+
### Custom palette
1195+
1196+
- You can now specify custom palette for OverlayTypes in similar manner as TechnoTypes can.
1197+
1198+
In `artmd.ini`:
1199+
```ini
1200+
[SOMETERRAINTYPE] ; TerrainType
1201+
Palette= ; filename - excluding .pal extension and three-character theater-specific suffix
1202+
```
1203+
1204+
### ZAdjust
1205+
1206+
- OverlayTypes now read and use `ZAdjust`.
1207+
1208+
In `artmd.ini`:
1209+
```ini
1210+
[SOMEOVERLAY] ; OverlayType image
1211+
ZAdjust=0
1212+
```
11821213

11831214
## Particle systems
11841215

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ New:
543543
- Allow jumpjet climbing ignore building height (by TaranDahl)
544544
- Allow draw SuperWeapon timer as percentage (by NetsuNegi)
545545
- Customize particle system of parasite logic (by NetsuNegi)
546+
- [Buildable-upon OverlayTypes](Fixed-or-Improved-Logics.md#buildable-upon-overlaytypes) (by Starkku)
546547
547548
Vanilla fixes:
548549
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

src/Ext/OverlayType/Body.cpp

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,43 @@
22

33
OverlayTypeExt::ExtContainer OverlayTypeExt::ExtMap;
44

5+
bool OverlayTypeExt::CanBeBuiltOn(int overlayTypeIndex, BuildingTypeClass* pBuildingType, bool requireToBeRemovable)
6+
{
7+
auto const pOverlayType = OverlayTypeClass::Array[overlayTypeIndex];
8+
auto const pTypeExt = OverlayTypeExt::ExtMap.Find(pOverlayType);
9+
10+
if (!pTypeExt->CanBeBuiltOn)
11+
return false;
12+
13+
if (((pBuildingType && pBuildingType->Wall) || pOverlayType->Wall) && !pTypeExt->CanBeBuiltOn_Remove)
14+
return false;
15+
16+
return requireToBeRemovable ? pTypeExt->CanBeBuiltOn_Remove : true;
17+
}
18+
19+
void OverlayTypeExt::RemoveOverlayFromCell(int overlayTypeIndex, CellClass* pCell)
20+
{
21+
if (overlayTypeIndex != -1 && OverlayTypeClass::Array[overlayTypeIndex]->Wall)
22+
{
23+
pCell->DamageWall(-1);
24+
}
25+
else
26+
{
27+
pCell->OverlayTypeIndex = -1;
28+
pCell->OverlayData = 0;
29+
pCell->RecalcAttributes(-1);
30+
}
31+
}
32+
533
// =============================
634
// load / save
735

836
template <typename T>
937
void OverlayTypeExt::ExtData::Serialize(T& Stm)
1038
{
1139
Stm
40+
.Process(this->CanBeBuiltOn)
41+
.Process(this->CanBeBuiltOn_Remove)
1242
.Process(this->ZAdjust)
1343
.Process(this->PaletteFile)
1444
;
@@ -18,12 +48,15 @@ void OverlayTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
1848
{
1949
auto pThis = this->OwnerObject();
2050

21-
//const char* pSection = pThis->ID;
22-
//
23-
//if (!pINI->GetSection(pSection))
24-
// return;
25-
//
26-
//INI_EX exINI(pINI);
51+
const char* pSection = pThis->ID;
52+
53+
if (!pINI->GetSection(pSection))
54+
return;
55+
56+
INI_EX exINI(pINI);
57+
58+
this->CanBeBuiltOn.Read(exINI, pSection, "CanBeBuiltOn");
59+
this->CanBeBuiltOn_Remove.Read(exINI, pSection, "CanBeBuiltOn.Remove");
2760

2861
auto pArtSection = pThis->ImageFile;
2962
INI_EX exArtINI(&CCINIClass::INI_Art);

src/Ext/OverlayType/Body.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ class OverlayTypeExt
1515
class ExtData final : public Extension<OverlayTypeClass>
1616
{
1717
public:
18+
Valueable<bool> CanBeBuiltOn;
19+
Valueable<bool> CanBeBuiltOn_Remove;
1820
Valueable<int> ZAdjust;
1921
PhobosFixedString<32u> PaletteFile;
2022
DynamicVectorClass<ColorScheme*>* Palette; // Intentionally not serialized - rebuilt from the palette file on load.
2123

2224
ExtData(OverlayTypeClass* OwnerObject) : Extension<OverlayTypeClass>(OwnerObject)
25+
, CanBeBuiltOn { false }
26+
, CanBeBuiltOn_Remove { true }
2327
, ZAdjust { 0 }
2428
, PaletteFile {}
2529
, Palette {}
@@ -50,4 +54,7 @@ class OverlayTypeExt
5054

5155
static bool LoadGlobals(PhobosStreamReader& Stm);
5256
static bool SaveGlobals(PhobosStreamWriter& Stm);
57+
58+
static bool CanBeBuiltOn(int overlayTypeIndex, BuildingTypeClass* pBuildingType, bool requireToBeRemovable);
59+
static void RemoveOverlayFromCell(int overlayTypeIndex, CellClass* pCell);
5360
};

src/Ext/OverlayType/Hooks.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,38 @@ DEFINE_HOOK(0x47F974, CellClass_DrawOverlay_Walls, 0x5)
4444

4545
return SkipGameCode;
4646
}
47+
48+
#pragma region CanBeBuiltOn
49+
50+
DEFINE_HOOK(0x47C9A7, CellClass_IsClearToBuild_Overlays, 0x5)
51+
{
52+
enum { ReturnFromFunction = 0x47C6D1, CheckTileLandType = 0x47C9CD };
53+
54+
GET(CellClass*, pThis, EDI);
55+
GET_STACK(BuildingTypeClass*, pBuildingType, STACK_OFFSET(0x18, 0x8));
56+
57+
int overlayTypeIndex = pThis->OverlayTypeIndex;
58+
59+
if (overlayTypeIndex != -1)
60+
{
61+
if (OverlayTypeExt::CanBeBuiltOn(overlayTypeIndex, pBuildingType, false))
62+
return CheckTileLandType;
63+
}
64+
65+
return ReturnFromFunction;
66+
}
67+
68+
DEFINE_HOOK(0x45EF11, BuildingTypeClass_FlushForPlacement_Overlays, 0x6)
69+
{
70+
enum { Continue = 0x45EF2C };
71+
72+
GET(BuildingTypeClass*, pThis, EBX);
73+
GET(int, overlayTypeIndex, ECX);
74+
75+
if (OverlayTypeExt::CanBeBuiltOn(overlayTypeIndex, pThis, false))
76+
return Continue;
77+
78+
return 0;
79+
}
80+
81+
#pragma endregion

src/Ext/TerrainType/Hooks.Passable.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Body.h"
2+
#include <Ext/OverlayType/Body.h>
23

34
constexpr bool IS_CELL_OCCUPIED(CellClass* pCell)
45
{
@@ -113,6 +114,16 @@ DEFINE_HOOK(0x5684B1, MapClass_PlaceDown_BuildableTerrain, 0x6)
113114
TerrainTypeExt::Remove(pTerrain);
114115
}
115116
}
117+
118+
int overlayTypeIndex = pCell->OverlayTypeIndex;
119+
120+
if (overlayTypeIndex != -1)
121+
{
122+
auto const pBuildingType = static_cast<BuildingTypeClass*>(pObject->GetType());
123+
124+
if (OverlayTypeExt::CanBeBuiltOn(overlayTypeIndex, pBuildingType, true))
125+
OverlayTypeExt::RemoveOverlayFromCell(overlayTypeIndex, pCell);
126+
}
116127
}
117128

118129
return 0;

0 commit comments

Comments
 (0)