OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Weather Class Reference

#include <C4Weather.h>

Public Member Functions

 C4Weather ()
 
 ~C4Weather ()
 
void Default ()
 
void Clear ()
 
void Execute ()
 
void SetClimate (int32_t iClimate)
 
void SetSeason (int32_t iSeason)
 
void SetTemperature (int32_t iTemperature)
 
void Init (bool fScenario)
 
void SetWind (int32_t iWind)
 
int32_t GetWind (int32_t x, int32_t y)
 
int32_t GetTemperature ()
 
int32_t GetSeason ()
 
int32_t GetClimate ()
 
void SetSeasonGamma ()
 
void CompileFunc (StdCompiler *pComp)
 

Public Attributes

int32_t Season
 
int32_t YearSpeed
 
int32_t SeasonDelay
 
int32_t Wind
 
int32_t TargetWind
 
int32_t Temperature
 
int32_t TemperatureRange
 
int32_t Climate
 
int32_t NoGamma
 

Detailed Description

Definition at line 24 of file C4Weather.h.

Constructor & Destructor Documentation

C4Weather::C4Weather ( )

Definition at line 29 of file C4Weather.cpp.

References Default().

30 {
31  Default();
32 }
void Default()
Definition: C4Weather.cpp:105

Here is the call graph for this function:

C4Weather::~C4Weather ( )

Definition at line 34 of file C4Weather.cpp.

References Clear().

35 {
36  Clear();
37 }
void Clear()
Definition: C4Weather.cpp:89

Here is the call graph for this function:

Member Function Documentation

void C4Weather::Clear ( )

Definition at line 89 of file C4Weather.cpp.

Referenced by C4Game::Clear(), and ~C4Weather().

90 {
91 
92 }

Here is the caller graph for this function:

void C4Weather::CompileFunc ( StdCompiler pComp)

Definition at line 174 of file C4Weather.cpp.

References C4MaxGammaRamps, Climate, C4Draw::gamma, mkArrayAdaptM, mkNamingAdapt(), NoGamma, pDraw, Season, SeasonDelay, TargetWind, Temperature, TemperatureRange, StdCompiler::Value(), Wind, and YearSpeed.

175 {
176  pComp->Value(mkNamingAdapt(Season, "Season", 0));
177  pComp->Value(mkNamingAdapt(YearSpeed, "YearSpeed", 0));
178  pComp->Value(mkNamingAdapt(SeasonDelay, "SeasonDelay", 0));
179  pComp->Value(mkNamingAdapt(Wind, "Wind", 0));
180  pComp->Value(mkNamingAdapt(TargetWind, "TargetWind", 0));
181  pComp->Value(mkNamingAdapt(Temperature, "Temperature", 0));
182  pComp->Value(mkNamingAdapt(TemperatureRange, "TemperatureRange", 30));
183  pComp->Value(mkNamingAdapt(Climate, "Climate", 0));
184  pComp->Value(mkNamingAdapt(NoGamma, "NoGamma", 0));
185 
186  int32_t gamma[C4MaxGammaRamps*3],
187  gammaDefaults[C4MaxGammaRamps*3];
188  for (int32_t i=0; i<C4MaxGammaRamps; ++i)
189  {
190  gammaDefaults[i*3+0] = 100;
191  gammaDefaults[i*3+1] = 100;
192  gammaDefaults[i*3+2] = 100;
193  gamma[i*3+0] = int(pDraw->gamma[i][0] * 100.0f);
194  gamma[i*3+1] = int(pDraw->gamma[i][1] * 100.0f);
195  gamma[i*3+2] = int(pDraw->gamma[i][2] * 100.0f);
196  }
197  pComp->Value(mkNamingAdapt(mkArrayAdaptM(gamma), "Gamma", gammaDefaults));
198  for (int32_t i=0; i<C4MaxGammaRamps; ++i)
199  {
200  pDraw->gamma[i][0] = float(gamma[i*3+0]) / 100.0f;
201  pDraw->gamma[i][1] = float(gamma[i*3+1]) / 100.0f;
202  pDraw->gamma[i][2] = float(gamma[i*3+2]) / 100.0f;
203  }
204 }
int32_t NoGamma
Definition: C4Weather.h:33
const int C4MaxGammaRamps
Definition: C4Constants.h:35
int32_t Wind
Definition: C4Weather.h:31
int32_t TemperatureRange
Definition: C4Weather.h:32
#define mkArrayAdaptM(A)
Definition: StdAdaptors.h:311
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
int32_t Climate
Definition: C4Weather.h:32
int32_t TargetWind
Definition: C4Weather.h:31
C4Draw * pDraw
Definition: C4Draw.cpp:42
int32_t YearSpeed
Definition: C4Weather.h:30
void Value(const T &rStruct)
Definition: StdCompiler.h:161
int32_t Temperature
Definition: C4Weather.h:32
int32_t SeasonDelay
Definition: C4Weather.h:30
int32_t Season
Definition: C4Weather.h:30
float gamma[C4MaxGammaRamps][3]
Definition: C4Draw.h:97

Here is the call graph for this function:

void C4Weather::Default ( )

Definition at line 105 of file C4Weather.cpp.

References Climate, NoGamma, Season, SeasonDelay, TargetWind, Temperature, TemperatureRange, Wind, and YearSpeed.

Referenced by C4Weather(), and C4Game::Default().

106 {
107  Season=0; YearSpeed=0; SeasonDelay=0;
108  Wind=TargetWind=0;
110  TemperatureRange=30;
111  NoGamma=true;
112 }
int32_t NoGamma
Definition: C4Weather.h:33
int32_t Wind
Definition: C4Weather.h:31
int32_t TemperatureRange
Definition: C4Weather.h:32
int32_t Climate
Definition: C4Weather.h:32
int32_t TargetWind
Definition: C4Weather.h:31
int32_t YearSpeed
Definition: C4Weather.h:30
int32_t Temperature
Definition: C4Weather.h:32
int32_t SeasonDelay
Definition: C4Weather.h:30
int32_t Season
Definition: C4Weather.h:30

Here is the caller graph for this function:

void C4Weather::Execute ( )

Definition at line 58 of file C4Weather.cpp.

References C4Game::C4S, Climate, Cos(), C4SVal::Evaluate(), fixtoi(), Game, C4Game::iTick10, C4Game::iTick1000, C4Game::iTick35, itofix(), C4SVal::Max, C4SVal::Min, Season, SeasonDelay, SetSeasonGamma(), Sign(), C4SWeather::StartSeason, TargetWind, Temperature, TemperatureRange, C4Scenario::Weather, Wind, C4SWeather::Wind, and YearSpeed.

Referenced by C4Game::Execute().

59 {
60  // Season
61  if (!::Game.iTick35)
62  {
64  if (SeasonDelay>=200)
65  {
66  SeasonDelay=0;
67  Season++;
71  }
72  }
73  // Temperature
74  if (!::Game.iTick35)
75  {
76  int32_t iTemperature = Climate - fixtoi(Cos(itofix(36 * Season, 10)), TemperatureRange);
77  if (Temperature<iTemperature) Temperature++;
78  else if (Temperature>iTemperature) Temperature--;
79  }
80  // Wind
81  if (!::Game.iTick1000)
83  if (!::Game.iTick10)
84  Wind=Clamp<int32_t>(Wind+Sign(TargetWind-Wind),
87 }
int32_t Max
Definition: C4Scenario.h:31
C4SVal StartSeason
Definition: C4Scenario.h:198
C4Game Game
Definition: C4Globals.cpp:52
int32_t iTick35
Definition: C4Game.h:129
C4Scenario C4S
Definition: C4Game.h:74
int Sign(T val)
Definition: Standard.h:45
void SetSeasonGamma()
Definition: C4Weather.cpp:156
C4SVal Wind
Definition: C4Scenario.h:199
int32_t Wind
Definition: C4Weather.h:31
int32_t TemperatureRange
Definition: C4Weather.h:32
int32_t iTick1000
Definition: C4Game.h:129
int32_t Climate
Definition: C4Weather.h:32
int32_t TargetWind
Definition: C4Weather.h:31
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int32_t YearSpeed
Definition: C4Weather.h:30
int32_t iTick10
Definition: C4Game.h:129
int32_t Temperature
Definition: C4Weather.h:32
int32_t SeasonDelay
Definition: C4Weather.h:30
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4SWeather Weather
Definition: C4Scenario.h:236
int32_t Evaluate()
Definition: C4Scenario.cpp:50
C4Real Cos(const C4Real &fAngle)
Definition: C4Real.h:266
int32_t Season
Definition: C4Weather.h:30
int32_t Min
Definition: C4Scenario.h:31

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4Weather::GetClimate ( )

Definition at line 143 of file C4Weather.cpp.

References Climate.

144 {
145  return Climate;
146 }
int32_t Climate
Definition: C4Weather.h:32
int32_t C4Weather::GetSeason ( )

Definition at line 132 of file C4Weather.cpp.

References Season.

133 {
134  return Season;
135 }
int32_t Season
Definition: C4Weather.h:30
int32_t C4Weather::GetTemperature ( )

Definition at line 100 of file C4Weather.cpp.

References Temperature.

Referenced by C4Landscape::P::DoScan(), and C4Landscape::P::ExecuteScan().

101 {
102  return Temperature;
103 }
int32_t Temperature
Definition: C4Weather.h:32

Here is the caller graph for this function:

int32_t C4Weather::GetWind ( int32_t  x,
int32_t  y 
)

Definition at line 94 of file C4Weather.cpp.

References C4Landscape::GetBackPix(), Landscape, and Wind.

Referenced by C4PXS::Execute().

95 {
96  if (Landscape.GetBackPix(x,y) != 0) return 0;
97  return Wind;
98 }
int32_t Wind
Definition: C4Weather.h:31
C4Landscape Landscape
BYTE GetBackPix(int32_t x, int32_t y) const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Weather::Init ( bool  fScenario)

Definition at line 39 of file C4Weather.cpp.

References C4Game::C4S, Climate, C4SWeather::Climate, C4SVal::Evaluate(), Game, NoGamma, C4SWeather::NoGamma, Season, SetSeasonGamma(), C4SWeather::StartSeason, TargetWind, Temperature, C4Scenario::Weather, Wind, C4SWeather::Wind, YearSpeed, and C4SWeather::YearSpeed.

Referenced by C4Game::InitGame().

40 {
41  if (fScenario)
42  {
43  // Season
46  // Temperature
49  // Wind
51  // gamma?
53  }
54  // set gamma
56 }
C4SVal Climate
Definition: C4Scenario.h:197
C4SVal StartSeason
Definition: C4Scenario.h:198
int32_t NoGamma
Definition: C4Weather.h:33
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
C4SVal YearSpeed
Definition: C4Scenario.h:198
void SetSeasonGamma()
Definition: C4Weather.cpp:156
C4SVal Wind
Definition: C4Scenario.h:199
int32_t Wind
Definition: C4Weather.h:31
bool NoGamma
Definition: C4Scenario.h:200
int32_t Climate
Definition: C4Weather.h:32
int32_t TargetWind
Definition: C4Weather.h:31
int32_t YearSpeed
Definition: C4Weather.h:30
int32_t Temperature
Definition: C4Weather.h:32
C4SWeather Weather
Definition: C4Scenario.h:236
int32_t Evaluate()
Definition: C4Scenario.cpp:50
int32_t Season
Definition: C4Weather.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Weather::SetClimate ( int32_t  iClimate)

Definition at line 137 of file C4Weather.cpp.

References Climate, and SetSeasonGamma().

138 {
139  Climate = Clamp<int32_t>(iClimate,-50,+50);
140  SetSeasonGamma();
141 }
void SetSeasonGamma()
Definition: C4Weather.cpp:156
int32_t Climate
Definition: C4Weather.h:32

Here is the call graph for this function:

void C4Weather::SetSeason ( int32_t  iSeason)

Definition at line 126 of file C4Weather.cpp.

References Season, and SetSeasonGamma().

127 {
128  Season = Clamp<int32_t>(iSeason,0,100);
129  SetSeasonGamma();
130 }
void SetSeasonGamma()
Definition: C4Weather.cpp:156
int32_t Season
Definition: C4Weather.h:30

Here is the call graph for this function:

void C4Weather::SetSeasonGamma ( )

Definition at line 156 of file C4Weather.cpp.

References C4GRI_SEASON, Clamp(), NoGamma, pDraw, Season, and C4Draw::SetGamma().

Referenced by Execute(), Init(), SetClimate(), SetSeason(), and SetTemperature().

157 {
158  if (NoGamma) return;
159  // get season num and offset
160  int32_t iSeason1=(Season/25)%4; int32_t iSeason2=(iSeason1+1)%4;
161  int32_t iSeasonOff1=Clamp(Season%25, 5, 19)-5; int32_t iSeasonOff2=15-iSeasonOff1;
162  float gamma[3] = { 0.0f, 0.0f, 0.0f };
163  // interpolate between season colors
164  for (int32_t iChan=0; iChan<3; iChan+=8)
165  {
166  float c1 = SeasonColors[iSeason1][iChan],
167  c2 = SeasonColors[iSeason2][iChan];
168  gamma[iChan] = (c1*iSeasonOff2 + c2*iSeasonOff1) / 15;
169  }
170  // apply gamma ramp
171  pDraw->SetGamma(gamma[0], gamma[1], gamma[2], C4GRI_SEASON);
172 }
int32_t NoGamma
Definition: C4Weather.h:33
#define C4GRI_SEASON
Definition: C4Constants.h:39
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
C4Draw * pDraw
Definition: C4Draw.cpp:42
void SetGamma(float r, float g, float b, int32_t iRampIndex)
Definition: C4Draw.cpp:744
int32_t Season
Definition: C4Weather.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Weather::SetTemperature ( int32_t  iTemperature)

Definition at line 120 of file C4Weather.cpp.

References SetSeasonGamma(), and Temperature.

121 {
122  Temperature = Clamp<int32_t>(iTemperature,-100,100);
123  SetSeasonGamma();
124 }
void SetSeasonGamma()
Definition: C4Weather.cpp:156
int32_t Temperature
Definition: C4Weather.h:32

Here is the call graph for this function:

void C4Weather::SetWind ( int32_t  iWind)

Definition at line 114 of file C4Weather.cpp.

References TargetWind, and Wind.

115 {
116  Wind=Clamp<int32_t>(iWind,-100,+100);
117  TargetWind=Clamp<int32_t>(iWind,-100,+100);
118 }
int32_t Wind
Definition: C4Weather.h:31
int32_t TargetWind
Definition: C4Weather.h:31

Member Data Documentation

int32_t C4Weather::Climate

Definition at line 32 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), GetClimate(), Init(), and SetClimate().

int32_t C4Weather::NoGamma

Definition at line 33 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Init(), and SetSeasonGamma().

int32_t C4Weather::Season

Definition at line 30 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), GetSeason(), Init(), SetSeason(), and SetSeasonGamma().

int32_t C4Weather::SeasonDelay

Definition at line 30 of file C4Weather.h.

Referenced by CompileFunc(), Default(), and Execute().

int32_t C4Weather::TargetWind

Definition at line 31 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), Init(), and SetWind().

int32_t C4Weather::Temperature

Definition at line 32 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), GetTemperature(), Init(), and SetTemperature().

int32_t C4Weather::TemperatureRange

Definition at line 32 of file C4Weather.h.

Referenced by CompileFunc(), Default(), and Execute().

int32_t C4Weather::Wind

Definition at line 31 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), C4Sky::Execute(), GetWind(), Init(), and SetWind().

int32_t C4Weather::YearSpeed

Definition at line 30 of file C4Weather.h.

Referenced by CompileFunc(), Default(), Execute(), and Init().


The documentation for this class was generated from the following files: