forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathINIWater.cpp
More file actions
144 lines (113 loc) · 5.33 KB
/
INIWater.cpp
File metadata and controls
144 lines (113 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: INIWater.cpp /////////////////////////////////////////////////////////////////////////////
// Author: Colin Day, December 2001
// Desc: Water settings
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#define DEFINE_TIME_OF_DAY_NAMES
#include "Common/INI.h"
#include "Common/GameType.h"
#include "GameClient/TerrainVisual.h"
#include "GameClient/Water.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
/** Water setting, note that this does not support override situations. As the water
* system becomes more complex we may want to change this */
//-------------------------------------------------------------------------------------------------
void INI::parseWaterSettingDefinition( INI* ini )
{
AsciiString name;
WaterSetting *waterSetting = nullptr;
// read the name
const char* token = ini->getNextToken();
name.set( token );
// get the water setting we want to load based on name
const char *const *timeOfDayName = TimeOfDayNames;
Int timeOfDayIndex = 0; // TIME_OF_DAY_INVALID
while( timeOfDayName && *timeOfDayName )
{
if( stricmp( *timeOfDayName, name.str() ) == 0 )
{
waterSetting = &WaterSettings[ timeOfDayIndex ];
break;
}
// next name
timeOfDayName++;
timeOfDayIndex++;
}
// check for no time of day match
if( waterSetting == nullptr )
throw INI_INVALID_DATA;
// parse the data
ini->initFromINI( waterSetting, waterSetting->getFieldParse() );
}
//-------------------------------------------------------------------------------------------------
void INI::parseWaterTransparencyDefinition( INI *ini )
{
if (TheWaterTransparency == nullptr) {
TheWaterTransparency = newInstance(WaterTransparencySetting);
} else if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
WaterTransparencySetting* wt = (WaterTransparencySetting*) (TheWaterTransparency.getNonOverloadedPointer());
WaterTransparencySetting* wtOverride = newInstance(WaterTransparencySetting);
*wtOverride = *wt;
// Mark that it is an override.
wtOverride->markAsOverride();
wt->friend_getFinalOverride()->setNextOverride(wtOverride);
} else {
throw INI_INVALID_DATA;
}
WaterTransparencySetting* waterTrans = (WaterTransparencySetting*) (TheWaterTransparency.getNonOverloadedPointer());
waterTrans = (WaterTransparencySetting*) (waterTrans->friend_getFinalOverride());
// parse the data
ini->initFromINI( waterTrans, TheWaterTransparency->getFieldParse() );
// If we overrode any skybox textures, then call the W3D Water stuff.
if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES) {
// Check to see if we overrode any skybox textures.
// If we did, then we need to replace them in the model.
// Copy/Paste monkeys PLEASE TAKE NOTE. This technique only works for the skybox because we
// know that there will never be more than one sky box. If you were to use this technique for
// technicals, for instance, it would make all technicals in the level have the same new
// texture.
const WaterTransparencySetting* wtOriginal = TheWaterTransparency.getNonOverloadedPointer();
OVERRIDE<WaterTransparencySetting> wtOverride = TheWaterTransparency;
if (wtOriginal == wtOverride)
return;
const AsciiString *oldTextures[5],*newTextures[5];
//Copy current texture names into arrays
oldTextures[0]=&wtOriginal->m_skyboxTextureN;
newTextures[0]=&wtOverride->m_skyboxTextureN;
oldTextures[1]=&wtOriginal->m_skyboxTextureE;
newTextures[1]=&wtOverride->m_skyboxTextureE;
oldTextures[2]=&wtOriginal->m_skyboxTextureS;
newTextures[2]=&wtOverride->m_skyboxTextureS;
oldTextures[3]=&wtOriginal->m_skyboxTextureW;
newTextures[3]=&wtOverride->m_skyboxTextureW;
oldTextures[4]=&wtOriginal->m_skyboxTextureT;
newTextures[4]=&wtOverride->m_skyboxTextureT;
TheTerrainVisual->replaceSkyboxTextures(oldTextures, newTextures);
}
}