moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / game / cont.cpp
blob35a0ca8339d556f5bdda4aff8e0b9c44f0f5a744
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
13 /* Compiled through wmapset.cpp */
15 uChar** continent::TypeBuffer;
16 short** continent::AltitudeBuffer;
17 uChar** continent::ContinentBuffer;
19 continent::continent() { }
20 continent::continent(int Index) : Index(Index) { }
21 sLong continent::GetSize() const { return Member.size(); }
22 int continent::GetGTerrainAmount(int Type) const { return GTerrainAmount[Type]; }
23 v2 continent::GetMember(int I) const { return Member[I]; }
25 void continent::Save(outputfile& SaveFile) const
27 SaveFile << Name << Member << Index;
30 void continent::Load(inputfile& SaveFile)
32 SaveFile >> Name >> Member >> Index;
35 void continent::AttachTo(continent* Continent)
37 for(feuLong c = 0; c < Member.size(); ++c)
38 ContinentBuffer[Member[c].X][Member[c].Y] = Continent->Index;
40 if(!Continent->Member.size())
41 Continent->Member.swap(Member);
42 else
44 Continent->Member.insert(Continent->Member.end(), Member.begin(), Member.end());
45 Member.clear();
49 void continent::GenerateInfo()
51 GTerrainAmount.resize(protocontainer<gwterrain>::GetSize() + 1);
53 for(feuLong c = 0; c < Member.size(); ++c)
54 ++GTerrainAmount[TypeBuffer[Member[c].X][Member[c].Y]];
56 Name = CONST_S("number ");
57 Name << Index;
60 v2 continent::GetRandomMember(int Type, truth* success)
62 if (success) *success = false;
63 if (!GTerrainAmount[Type]) {
64 //ABORT("Shortage of terrain!");
65 return v2(0, 0);
68 v2* TypeContainer = new v2[Member.size()];
69 sLong Index = 0;
71 for (feuLong c = 0; c < Member.size(); ++c) {
72 if (TypeBuffer[Member[c].X][Member[c].Y] == Type) {
73 TypeContainer[Index++] = Member[c];
74 if (Index == GetGTerrainAmount(Type)) break;
78 v2 Return = TypeContainer[RAND() % Index];
79 delete [] TypeContainer;
80 if (success) *success = true;
81 return Return;
84 outputfile& operator<<(outputfile& SaveFile, const continent* Continent)
86 if(Continent)
88 SaveFile.Put(1);
89 Continent->Save(SaveFile);
91 else
92 SaveFile.Put(0);
94 return SaveFile;
97 inputfile& operator>>(inputfile& SaveFile, continent*& Continent)
99 if(SaveFile.Get())
101 Continent = new continent;
102 Continent->Load(SaveFile);
105 return SaveFile;
108 void continent::Add(v2 Pos)
110 Member.push_back(Pos);
111 ContinentBuffer[Pos.X][Pos.Y] = Index;