Skip to content

Commit 21a5be6

Browse files
committed
unify(map): Merge GameLogic map headers and implementations
1 parent 9fee97a commit 21a5be6

11 files changed

Lines changed: 158 additions & 9 deletions

File tree

Generals/Code/GameEngine/Include/Common/MapReaderWriterInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#define K_TRIGGERS_VERSION_1 1
4949
#define K_TRIGGERS_VERSION_2 2 // Added m_isWaterArea
5050
#define K_TRIGGERS_VERSION_3 3 // Added m_isRiver & m_riverStart
51+
#define K_TRIGGERS_VERSION_4 4 // Added layer name.
5152
#define K_LIGHTING_VERSION_1 1
5253
#define K_LIGHTING_VERSION_2 2 // Added 2 additional global lights for objects.
5354
#define K_LIGHTING_VERSION_3 3 // Added 2 additional global lights for terrain.

Generals/Code/GameEngine/Include/GameLogic/PolygonTrigger.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class PolygonTrigger : public MemoryPoolObject,
8181
Bool m_exportWithScripts;
8282
Bool m_isWaterArea; ///< Used to specify water areas in the map.
8383
Bool m_isRiver; ///< Used to specify that a water area is a river.
84+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
85+
AsciiString m_layerName; ///< Used to specify the layer in the World Builder.
86+
Bool m_shouldRender;
87+
Bool m_selected;
88+
#endif
8489

8590
static PolygonTrigger* ThePolygonTriggerListPtr;
8691
static Int s_currentID; ///< Current id for new triggers.
@@ -116,6 +121,17 @@ class PolygonTrigger : public MemoryPoolObject,
116121
void deletePoint(Int ndx);
117122
void setTriggerName(AsciiString name) {m_triggerName = name;};
118123

124+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
125+
void setLayerName(AsciiString name) {m_layerName = name;};
126+
AsciiString getLayerName() const {return m_layerName;}
127+
128+
void setShouldRender(Bool toggle) {m_shouldRender = toggle;}
129+
Bool getShouldRender() {return m_shouldRender;}
130+
131+
void setSelected(Bool toggle) {m_selected = toggle;}
132+
Bool getSelected() {return m_selected;}
133+
#endif
134+
119135
void getCenterPoint(Coord3D* pOutCoord) const;
120136
Real getRadius() const;
121137

Generals/Code/GameEngine/Include/GameLogic/TerrainLogic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ class TerrainLogic : public Snapshot,
312312
void setActiveBoundary(Int newActiveBoundary);
313313

314314
void flattenTerrain(Object *obj); ///< Flatten the terrain under a building.
315+
#if RTS_ZEROHOUR
316+
void createCraterInTerrain(Object *obj); ///< Flatten the terrain under a building.
317+
#endif
315318

316319
protected:
317320

Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ m_numPoints(0),
4848
m_sizePoints(0),
4949
m_exportWithScripts(false),
5050
m_isWaterArea(false),
51+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
52+
m_shouldRender(true),
53+
m_selected(false),
54+
#endif
5155
m_isRiver(FALSE),
5256
m_riverStart(0)
5357
{
@@ -140,6 +144,9 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
140144
Bool isRiver;
141145
Int riverStart;
142146
AsciiString triggerName;
147+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
148+
AsciiString layerName;
149+
#endif
143150
// Remove any existing polygon triggers, if any.
144151
PolygonTrigger::deleteTriggers(); // just in case.
145152
PolygonTrigger *pPrevTrig = nullptr;
@@ -148,6 +155,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
148155
while (count>0) {
149156
count--;
150157
triggerName = file.readAsciiString();
158+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
159+
if (info->version >= K_TRIGGERS_VERSION_4) {
160+
layerName = file.readAsciiString();
161+
}
162+
#endif
151163
triggerID = file.readInt();
152164
isWater = false;
153165
if (info->version >= K_TRIGGERS_VERSION_2) {
@@ -163,6 +175,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
163175
numPoints = file.readInt();
164176
PolygonTrigger *pTrig = newInstance(PolygonTrigger)(numPoints+1);
165177
pTrig->setTriggerName(triggerName);
178+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
179+
if (info->version >= K_TRIGGERS_VERSION_4) {
180+
pTrig->setLayerName(layerName);
181+
}
182+
#endif
166183
pTrig->setWaterArea(isWater);
167184
pTrig->setRiver(isRiver);
168185
pTrig->setRiverStart(riverStart);
@@ -177,6 +194,14 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
177194
loc.z = file.readInt();
178195
pTrig->addPoint(loc);
179196
}
197+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
198+
if (numPoints<2) {
199+
DEBUG_LOG(("Deleting polygon trigger '%s' with %d points.",
200+
pTrig->getTriggerName().str(), numPoints));
201+
deleteInstance(pTrig);
202+
continue;
203+
}
204+
#endif
180205
if (pPrevTrig) {
181206
pPrevTrig->setNextPoly(pTrig);
182207
} else {
@@ -224,7 +249,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
224249
*/
225250
void PolygonTrigger::WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter)
226251
{
252+
#if RTS_GENERALS && RETAIL_COMPATIBLE_CRC
227253
chunkWriter.openDataChunk("PolygonTriggers", K_TRIGGERS_VERSION_3);
254+
#else
255+
chunkWriter.openDataChunk("PolygonTriggers", K_TRIGGERS_VERSION_4);
256+
#endif
228257

229258
PolygonTrigger *pTrig;
230259
Int count = 0;
@@ -234,6 +263,9 @@ void PolygonTrigger::WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter)
234263
chunkWriter.writeInt(count);
235264
for (pTrig=PolygonTrigger::getFirstPolygonTrigger(); pTrig; pTrig = pTrig->getNext()) {
236265
chunkWriter.writeAsciiString(pTrig->getTriggerName());
266+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
267+
chunkWriter.writeAsciiString(pTrig->getLayerName());
268+
#endif
237269
chunkWriter.writeInt(pTrig->getID());
238270
chunkWriter.writeByte(pTrig->isWaterArea());
239271
chunkWriter.writeByte(pTrig->isRiver());

Generals/Code/GameEngine/Source/GameLogic/Map/SidesList.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,29 @@ static AsciiString static_readPlayerNames[MAX_PLAYER_COUNT];
429429
* Input: DataChunkInput
430430
*
431431
*/
432+
#if RTS_ZEROHOUR
433+
#define K_PLAYERS_NAMES_FOR_SCRIPTS_VERSION_1 1
434+
#define K_PLAYERS_NAMES_FOR_SCRIPTS_VERSION_2 2
435+
#endif
436+
432437
static Bool ParsePlayersDataChunk(DataChunkInput &file, DataChunkInfo *info, void *userData)
433438
{
439+
#if RTS_ZEROHOUR
440+
Int readDicts = 0;
441+
if (info->version >= K_PLAYERS_NAMES_FOR_SCRIPTS_VERSION_2) {
442+
readDicts = file.readInt();
443+
}
444+
#endif
434445
Int numNames = file.readInt();
435446
Int i;
436447
for (i=0; i<numNames; i++) {
437448
if (i>=MAX_PLAYER_COUNT) break;
438449
static_readPlayerNames[i] = file.readAsciiString();
450+
#if RTS_ZEROHOUR
451+
if (readDicts) {
452+
Dict sideDict = file.readDict();
453+
}
454+
#endif
439455
}
440456
DEBUG_ASSERTCRASH(file.atEndOfChunk(), ("Unexpected data left over."));
441457
return true;
@@ -1121,7 +1137,11 @@ void TeamsInfoRec::addTeam(const Dict* d)
11211137
TEAM_ALLOC_CHUNK = 8 ///< how many teams to alloc at a time
11221138
};
11231139

1140+
#if RTS_GENERALS
11241141
DEBUG_ASSERTCRASH(m_numTeams < 1024, ("hmm, seems like an awful lot of teams..."));
1142+
#else
1143+
DEBUG_ASSERTCRASH(m_numTeams < 2048, ("%d teams have been allocated (so far). This seems excessive.", m_numTeams ));
1144+
#endif
11251145
if (m_numTeams >= m_numTeamsAllocated)
11261146
{
11271147
// pool[]ify

Generals/Code/GameEngine/Source/GameLogic/Map/TerrainLogic.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ void TerrainLogic::setWaterHeight( const WaterHandle *water, Real height, Real d
23842384
Coord3D center;
23852385
center.x = affectedRegion.lo.x + affectedRegion.width() / 2.0f;
23862386
center.y = affectedRegion.lo.y + affectedRegion.height() / 2.0f;
2387-
center.z = 0.0f; // irrelavant
2387+
center.z = 0.0f; // irrelevant
23882388

23892389
// the max radius to scan around us is the diagonal of the bounding region
23902390
Real maxDist = sqrt( affectedRegion.width() * affectedRegion.width() +
@@ -2866,6 +2866,57 @@ void TerrainLogic::flattenTerrain(Object *obj)
28662866

28672867
}
28682868

2869+
#if RTS_ZEROHOUR
2870+
// ------------------------------------------------------------------------------------------------
2871+
/** Dig a deep circular gorge into the terrain beneath an object. */
2872+
// ------------------------------------------------------------------------------------------------
2873+
void TerrainLogic::createCraterInTerrain(Object *obj)
2874+
{
2875+
if (obj->getGeometryInfo().getIsSmall())
2876+
return;
2877+
2878+
const Coord3D *pos = obj->getPosition();
2879+
Real radius = obj->getGeometryInfo().getMajorRadius();
2880+
2881+
if ( radius <= 0.0f )
2882+
return; // sanity
2883+
2884+
ICoord2D iMin, iMax;
2885+
iMin.x = REAL_TO_INT_FLOOR( ( pos->x - radius ) / MAP_XY_FACTOR );
2886+
iMin.y = REAL_TO_INT_FLOOR( ( pos->y - radius ) / MAP_XY_FACTOR );
2887+
iMax.x = REAL_TO_INT_FLOOR( ( pos->x + radius ) / MAP_XY_FACTOR );
2888+
iMax.y = REAL_TO_INT_FLOOR( ( pos->y + radius ) / MAP_XY_FACTOR );
2889+
2890+
Real deltaX, deltaY;
2891+
2892+
for (Int i = iMin.x; i <= iMax.x; i++ )
2893+
{
2894+
for ( Int j=0; j <= iMax.y; j++ )
2895+
{
2896+
deltaX = ( i * MAP_XY_FACTOR ) - pos->x;
2897+
deltaY = ( j * MAP_XY_FACTOR ) - pos->y;
2898+
2899+
Real distance = sqrt( sqr( deltaX ) + sqr( deltaY ) );
2900+
2901+
if ( distance < radius ) //inside circle
2902+
{
2903+
ICoord2D gridPos;
2904+
gridPos.x = i;
2905+
gridPos.y = j;
2906+
2907+
2908+
Real displacementAmount = radius * (1.0f - distance / radius );
2909+
2910+
Int targetHeight = MAX( 1, TheTerrainVisual->getRawMapHeight( &gridPos ) - displacementAmount );
2911+
2912+
TheTerrainVisual->setRawMapHeight( &gridPos, targetHeight );
2913+
}
2914+
}
2915+
}
2916+
2917+
}
2918+
#endif
2919+
28692920
// ------------------------------------------------------------------------------------------------
28702921
/** CRC */
28712922
// ------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ class PolygonTrigger : public MemoryPoolObject,
8181
Bool m_exportWithScripts;
8282
Bool m_isWaterArea; ///< Used to specify water areas in the map.
8383
Bool m_isRiver; ///< Used to specify that a water area is a river.
84+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
8485
AsciiString m_layerName; ///< Used to specify the layer in the World Builder.
8586
Bool m_shouldRender;
8687
Bool m_selected;
88+
#endif
8789

8890
static PolygonTrigger* ThePolygonTriggerListPtr;
8991
static Int s_currentID; ///< Current id for new triggers.
@@ -119,6 +121,7 @@ class PolygonTrigger : public MemoryPoolObject,
119121
void deletePoint(Int ndx);
120122
void setTriggerName(AsciiString name) {m_triggerName = name;};
121123

124+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
122125
void setLayerName(AsciiString name) {m_layerName = name;};
123126
AsciiString getLayerName() const {return m_layerName;}
124127

@@ -127,6 +130,7 @@ class PolygonTrigger : public MemoryPoolObject,
127130

128131
void setSelected(Bool toggle) {m_selected = toggle;}
129132
Bool getSelected() {return m_selected;}
133+
#endif
130134

131135
void getCenterPoint(Coord3D* pOutCoord) const;
132136
Real getRadius() const;

GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ class TerrainLogic : public Snapshot,
312312
void setActiveBoundary(Int newActiveBoundary);
313313

314314
void flattenTerrain(Object *obj); ///< Flatten the terrain under a building.
315+
#if RTS_ZEROHOUR
315316
void createCraterInTerrain(Object *obj); ///< Flatten the terrain under a building.
317+
#endif
316318

317319
protected:
318320

GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ m_numPoints(0),
4848
m_sizePoints(0),
4949
m_exportWithScripts(false),
5050
m_isWaterArea(false),
51+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
5152
m_shouldRender(true),
5253
m_selected(false),
54+
#endif
5355
m_isRiver(FALSE),
5456
m_riverStart(0)
5557
{
@@ -142,7 +144,9 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
142144
Bool isRiver;
143145
Int riverStart;
144146
AsciiString triggerName;
147+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
145148
AsciiString layerName;
149+
#endif
146150
// Remove any existing polygon triggers, if any.
147151
PolygonTrigger::deleteTriggers(); // just in case.
148152
PolygonTrigger *pPrevTrig = nullptr;
@@ -151,9 +155,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
151155
while (count>0) {
152156
count--;
153157
triggerName = file.readAsciiString();
158+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
154159
if (info->version >= K_TRIGGERS_VERSION_4) {
155160
layerName = file.readAsciiString();
156161
}
162+
#endif
157163
triggerID = file.readInt();
158164
isWater = false;
159165
if (info->version >= K_TRIGGERS_VERSION_2) {
@@ -169,9 +175,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
169175
numPoints = file.readInt();
170176
PolygonTrigger *pTrig = newInstance(PolygonTrigger)(numPoints+1);
171177
pTrig->setTriggerName(triggerName);
178+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
172179
if (info->version >= K_TRIGGERS_VERSION_4) {
173180
pTrig->setLayerName(layerName);
174181
}
182+
#endif
175183
pTrig->setWaterArea(isWater);
176184
pTrig->setRiver(isRiver);
177185
pTrig->setRiverStart(riverStart);
@@ -186,12 +194,14 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
186194
loc.z = file.readInt();
187195
pTrig->addPoint(loc);
188196
}
197+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
189198
if (numPoints<2) {
190199
DEBUG_LOG(("Deleting polygon trigger '%s' with %d points.",
191200
pTrig->getTriggerName().str(), numPoints));
192201
deleteInstance(pTrig);
193202
continue;
194203
}
204+
#endif
195205
if (pPrevTrig) {
196206
pPrevTrig->setNextPoly(pTrig);
197207
} else {
@@ -239,7 +249,11 @@ Bool PolygonTrigger::ParsePolygonTriggersDataChunk(DataChunkInput &file, DataChu
239249
*/
240250
void PolygonTrigger::WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter)
241251
{
252+
#if RTS_GENERALS && RETAIL_COMPATIBLE_CRC
253+
chunkWriter.openDataChunk("PolygonTriggers", K_TRIGGERS_VERSION_3);
254+
#else
242255
chunkWriter.openDataChunk("PolygonTriggers", K_TRIGGERS_VERSION_4);
256+
#endif
243257

244258
PolygonTrigger *pTrig;
245259
Int count = 0;
@@ -249,7 +263,9 @@ void PolygonTrigger::WritePolygonTriggersDataChunk(DataChunkOutput &chunkWriter)
249263
chunkWriter.writeInt(count);
250264
for (pTrig=PolygonTrigger::getFirstPolygonTrigger(); pTrig; pTrig = pTrig->getNext()) {
251265
chunkWriter.writeAsciiString(pTrig->getTriggerName());
266+
#if !(RTS_GENERALS && RETAIL_COMPATIBLE_CRC)
252267
chunkWriter.writeAsciiString(pTrig->getLayerName());
268+
#endif
253269
chunkWriter.writeInt(pTrig->getID());
254270
chunkWriter.writeByte(pTrig->isWaterArea());
255271
chunkWriter.writeByte(pTrig->isRiver());

0 commit comments

Comments
 (0)