save and bone files now can be compressed with ZLib (wow!)
[k8-i-v-a-n.git] / src / game / cont.cpp
blob411ceb4e1ce3bfe91b84da36f51b1b150b6685e0
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)
62 if(!GTerrainAmount[Type])
63 ABORT("Shortage of terrain!");
65 v2* TypeContainer = new v2[Member.size()];
66 sLong Index = 0;
68 for(feuLong c = 0; c < Member.size(); ++c)
69 if(TypeBuffer[Member[c].X][Member[c].Y] == Type)
71 TypeContainer[Index++] = Member[c];
73 if(Index == GetGTerrainAmount(Type))
74 break;
77 v2 Return = TypeContainer[RAND() % Index];
78 delete [] TypeContainer;
79 return Return;
82 outputfile& operator<<(outputfile& SaveFile, const continent* Continent)
84 if(Continent)
86 SaveFile.Put(1);
87 Continent->Save(SaveFile);
89 else
90 SaveFile.Put(0);
92 return SaveFile;
95 inputfile& operator>>(inputfile& SaveFile, continent*& Continent)
97 if(SaveFile.Get())
99 Continent = new continent;
100 Continent->Load(SaveFile);
103 return SaveFile;
106 void continent::Add(v2 Pos)
108 Member.push_back(Pos);
109 ContinentBuffer[Pos.X][Pos.Y] = Index;