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

#include <C4Map.h>

Collaboration diagram for C4MapCreator:
[legend]

Public Member Functions

 C4MapCreator ()
 
void Create (CSurface8 *sfcMap, C4SLandscape &rLScape, C4TextureMap &rTexMap, int32_t iPlayerNum=1)
 

Protected Member Functions

void Reset ()
 
void SetPix (int32_t x, int32_t y, BYTE col)
 
void SetSpot (int32_t x, int32_t y, int32_t rad, BYTE col)
 
void DrawLayer (int32_t x, int32_t y, int32_t size, BYTE col)
 
void ValidateTextureIndices (C4TextureMap &rTexMap)
 
BYTE GetPix (int32_t x, int32_t y)
 

Protected Attributes

CSurface8MapBuf
 
CSurface8MapBkgBuf
 
int32_t MapWdt
 
int32_t MapHgt
 
int32_t Exclusive
 

Detailed Description

Definition at line 23 of file C4Map.h.

Constructor & Destructor Documentation

C4MapCreator::C4MapCreator ( )

Definition at line 27 of file C4Map.cpp.

References Reset().

28 {
29  Reset();
30 }
void Reset()
Definition: C4Map.cpp:32

Here is the call graph for this function:

Member Function Documentation

void C4MapCreator::Create ( CSurface8 sfcMap,
C4SLandscape rLScape,
C4TextureMap rTexMap,
int32_t  iPlayerNum = 1 
)

Definition at line 78 of file C4Map.cpp.

References C4SLandscape::Amplitude, C4MaxNameList, C4S_MaxMapPlayerExtend, C4S_MaxPlayer, Clamp(), C4NameList::Count, DrawLayer(), C4SVal::Evaluate(), Exclusive, C4TextureMap::GetIndexMatTex(), GetPix(), C4SLandscape::Layers, C4SLandscape::Liquid, C4SLandscape::LiquidLevel, MapBuf, MapHgt, C4SLandscape::MapPlayerExtend, MapWdt, C4SLandscape::Material, C4NameList::Name, C4SLandscape::Period, C4SLandscape::Phase, Random(), C4SLandscape::Random, and SetPix().

Referenced by C4Landscape::P::CreateMap().

81 {
82  double fullperiod= 20.0 * M_PI;
83  BYTE ccol;
84  int32_t cx,cy;
85 
86  // Safeties
87  if (!sfcMap) return;
88  iPlayerNum=Clamp<int32_t>(iPlayerNum,1,C4S_MaxPlayer);
89 
90  // Set creator variables
91  MapBuf = sfcMap;
92  MapWdt = MapBuf->Wdt; MapHgt = MapBuf->Hgt;
93 
94  // Reset map (0 is sky)
95  MapBuf->ClearBox8Only(0,0,MapBuf->Wdt, MapBuf->Hgt);
96 
97  // Surface
98  ccol=rTexMap.GetIndexMatTex(rLScape.Material.c_str());
99  float amplitude= (float) rLScape.Amplitude.Evaluate();
100  float phase= (float) rLScape.Phase.Evaluate();
101  float period= (float) rLScape.Period.Evaluate();
102  if (rLScape.MapPlayerExtend) period *= std::min(iPlayerNum, C4S_MaxMapPlayerExtend);
103  float natural= (float) rLScape.Random.Evaluate();
104  int32_t level0= std::min(MapWdt,MapHgt)/2;
105  int32_t maxrange= level0*3/4;
106  double cy_curve,cy_natural; // -1.0 - +1.0 !
107 
108  double rnd_cy,rnd_tend; // -1.0 - +1.0 !
109  rnd_cy= (double) (Random(2000+1)-1000)/1000.0;
110  rnd_tend= (double) (Random(200+1)-100)/20000.0;
111 
112  for (cx=0; cx<MapWdt; cx++)
113  {
114 
115  rnd_cy+=rnd_tend;
116  rnd_tend+= (double) (Random(100+1)-50)/10000;
117  if (rnd_tend>+0.05) rnd_tend=+0.05;
118  if (rnd_tend<-0.05) rnd_tend=-0.05;
119  if (rnd_cy<-0.5) rnd_tend+=0.01;
120  if (rnd_cy>+0.5) rnd_tend-=0.01;
121 
122  cy_natural=rnd_cy*natural/100.0;
123  cy_curve=sin(fullperiod*period/100.0*(float)cx/(float)MapWdt
124  +2.0*M_PI*phase/100.0) * amplitude/100.0;
125 
126  cy=level0+Clamp((int32_t)((float)maxrange*(cy_curve+cy_natural)),
127  -maxrange,+maxrange);
128 
129 
130  SetPix(cx,cy,ccol);
131  }
132 
133  // Raise bottom to surface
134  for (cx=0; cx<MapWdt; cx++)
135  for (cy=MapHgt-1; (cy>=0) && !GetPix(cx,cy); cy--)
136  SetPix(cx,cy,ccol);
137  // Raise liquid level
138  Exclusive=0;
139  ccol=rTexMap.GetIndexMatTex(rLScape.Liquid.c_str());
140  int32_t wtr_level=rLScape.LiquidLevel.Evaluate();
141  for (cx=0; cx<MapWdt; cx++)
142  for (cy=MapHgt*(100-wtr_level)/100; cy<MapHgt; cy++)
143  SetPix(cx,cy,ccol);
144  Exclusive=-1;
145 
146  // Layers
147  // Base material
148  Exclusive=rTexMap.GetIndexMatTex(rLScape.Material.c_str());
149 
150  int32_t cnt,clayer,layer_num,sptx,spty;
151 
152  // Process layer name list
153  for (clayer=0; clayer<C4MaxNameList; clayer++)
154  if (rLScape.Layers.Name[clayer][0])
155  {
156  // Draw layers
157  ccol=rTexMap.GetIndexMatTex(rLScape.Layers.Name[clayer]);
158  layer_num=rLScape.Layers.Count[clayer];
159  layer_num=layer_num*MapWdt*MapHgt/15000;
160  for (cnt=0; cnt<layer_num; cnt++)
161  {
162  // Place layer
163  sptx=Random(MapWdt);
164  for (spty=0; (spty<MapHgt) && (GetPix(sptx,spty)!=Exclusive); spty++) {}
165  spty+=5+Random((MapHgt-spty)-10);
166  DrawLayer(sptx,spty,Random(15),ccol);
167 
168  }
169  }
170 
171  Exclusive=-1;
172 }
std::string Liquid
Definition: C4Scenario.h:182
std::string Material
Definition: C4Scenario.h:181
BYTE GetPix(int32_t x, int32_t y)
Definition: C4Map.cpp:70
uint32_t Random()
Definition: C4Random.cpp:43
int32_t MapPlayerExtend
Definition: C4Scenario.h:179
const int C4MaxNameList
Definition: C4NameList.h:23
uint8_t BYTE
const int C4S_MaxPlayer
Definition: C4Constants.h:53
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
C4SVal Period
Definition: C4Scenario.h:177
void DrawLayer(int32_t x, int32_t y, int32_t size, BYTE col)
Definition: C4Map.cpp:59
int32_t Exclusive
Definition: C4Map.h:31
int32_t MapHgt
Definition: C4Map.h:30
C4SVal Phase
Definition: C4Scenario.h:177
CSurface8 * MapBuf
Definition: C4Map.h:28
C4SVal Random
Definition: C4Scenario.h:177
void SetPix(int32_t x, int32_t y, BYTE col)
Definition: C4Map.cpp:38
int32_t Count[C4MaxNameList]
Definition: C4NameList.h:33
C4SVal Amplitude
Definition: C4Scenario.h:177
C4NameList Layers
Definition: C4Scenario.h:180
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:450
int32_t Evaluate()
Definition: C4Scenario.cpp:50
C4SVal LiquidLevel
Definition: C4Scenario.h:178
char Name[C4MaxNameList][C4MaxName+1]
Definition: C4NameList.h:32
const int32_t C4S_MaxMapPlayerExtend
Definition: C4Scenario.h:137
int32_t MapWdt
Definition: C4Map.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MapCreator::DrawLayer ( int32_t  x,
int32_t  y,
int32_t  size,
BYTE  col 
)
protected

Definition at line 59 of file C4Map.cpp.

References Random(), and SetPix().

Referenced by Create().

60 {
61  int32_t cnt,cnt2;
62  for (cnt=0; cnt<size; cnt++)
63  {
64  x+=Random(9)-4; y+=Random(3)-1;
65  for (cnt2=Random(3); cnt2<5; cnt2++)
66  { SetPix(x+cnt2,y,col); SetPix(x+cnt2+1,y+1,col); }
67  }
68 }
uint32_t Random()
Definition: C4Random.cpp:43
void SetPix(int32_t x, int32_t y, BYTE col)
Definition: C4Map.cpp:38

Here is the call graph for this function:

Here is the caller graph for this function:

BYTE C4MapCreator::GetPix ( int32_t  x,
int32_t  y 
)
protected

Definition at line 70 of file C4Map.cpp.

References CSurface8::GetPix(), MapBuf, MapHgt, and MapWdt.

Referenced by Create(), SetPix(), and ValidateTextureIndices().

71 {
72  // Safety
73  if (!Inside<int32_t>(x,0,MapWdt-1) || !Inside<int32_t>(y,0,MapHgt-1)) return 0;
74  // Get pix
75  return MapBuf->GetPix(x,y);
76 }
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
int32_t MapHgt
Definition: C4Map.h:30
CSurface8 * MapBuf
Definition: C4Map.h:28
int32_t MapWdt
Definition: C4Map.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MapCreator::Reset ( )
protected

Definition at line 32 of file C4Map.cpp.

References Exclusive, and MapBuf.

Referenced by C4MapCreator().

33 {
34  MapBuf=nullptr;
35  Exclusive=-1;
36 }
int32_t Exclusive
Definition: C4Map.h:31
CSurface8 * MapBuf
Definition: C4Map.h:28

Here is the caller graph for this function:

void C4MapCreator::SetPix ( int32_t  x,
int32_t  y,
BYTE  col 
)
protected

Definition at line 38 of file C4Map.cpp.

References Exclusive, GetPix(), MapBuf, MapHgt, MapWdt, and CSurface8::SetPix().

Referenced by Create(), DrawLayer(), SetSpot(), and ValidateTextureIndices().

39 {
40  // Safety
41  if (!Inside<int32_t>(x,0,MapWdt-1) || !Inside<int32_t>(y,0,MapHgt-1)) return;
42  // Exclusive
43  if (Exclusive>-1) if (GetPix(x,y)!=Exclusive) return;
44  // Set pix
45  MapBuf->SetPix(x,y,col);
46 }
BYTE GetPix(int32_t x, int32_t y)
Definition: C4Map.cpp:70
int32_t Exclusive
Definition: C4Map.h:31
int32_t MapHgt
Definition: C4Map.h:30
CSurface8 * MapBuf
Definition: C4Map.h:28
void SetPix(int iX, int iY, BYTE byCol)
Definition: CSurface8.h:37
int32_t MapWdt
Definition: C4Map.h:30

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MapCreator::SetSpot ( int32_t  x,
int32_t  y,
int32_t  rad,
BYTE  col 
)
protected

Definition at line 48 of file C4Map.cpp.

References SetPix().

49 {
50  int32_t ycnt,xcnt,lwdt,dpy;
51  for (ycnt=-rad; ycnt<=rad; ycnt++)
52  {
53  lwdt= (int32_t) sqrt(double(rad*rad-ycnt*ycnt)); dpy=y+ycnt;
54  for (xcnt=-lwdt; xcnt<lwdt+(lwdt==0); xcnt++)
55  SetPix(x+xcnt,dpy,col);
56  }
57 }
void SetPix(int32_t x, int32_t y, BYTE col)
Definition: C4Map.cpp:38

Here is the call graph for this function:

void C4MapCreator::ValidateTextureIndices ( C4TextureMap rTexMap)
protected

Definition at line 174 of file C4Map.cpp.

References C4TextureMap::GetEntry(), GetPix(), MapHgt, MapWdt, and SetPix().

175 {
176  int32_t iX,iY;
177  for (iY=0; iY<MapHgt; iY++)
178  for (iX=0; iX<MapWdt; iX++)
179  if (!rTextureMap.GetEntry(GetPix(iX,iY)))
180  SetPix(iX,iY,0);
181 }
BYTE GetPix(int32_t x, int32_t y)
Definition: C4Map.cpp:70
int32_t MapHgt
Definition: C4Map.h:30
void SetPix(int32_t x, int32_t y, BYTE col)
Definition: C4Map.cpp:38
int32_t MapWdt
Definition: C4Map.h:30

Here is the call graph for this function:

Member Data Documentation

int32_t C4MapCreator::Exclusive
protected

Definition at line 31 of file C4Map.h.

Referenced by Create(), Reset(), and SetPix().

CSurface8* C4MapCreator::MapBkgBuf
protected

Definition at line 29 of file C4Map.h.

CSurface8* C4MapCreator::MapBuf
protected

Definition at line 28 of file C4Map.h.

Referenced by Create(), GetPix(), Reset(), and SetPix().

int32_t C4MapCreator::MapHgt
protected

Definition at line 30 of file C4Map.h.

Referenced by Create(), GetPix(), SetPix(), and ValidateTextureIndices().

int32_t C4MapCreator::MapWdt
protected

Definition at line 30 of file C4Map.h.

Referenced by Create(), GetPix(), SetPix(), and ValidateTextureIndices().


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