3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
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
);
44 Continent
->Member
.insert(Continent
->Member
.end(), Member
.begin(), Member
.end());
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 ");
60 v2
continent::GetRandomMember(int Type
, truth
* success
)
62 if (success
) *success
= false;
63 if (!GTerrainAmount
[Type
]) {
64 //ABORT("Shortage of terrain!");
68 v2
* TypeContainer
= new v2
[Member
.size()];
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;
84 outputfile
& operator<<(outputfile
& SaveFile
, const continent
* Continent
)
89 Continent
->Save(SaveFile
);
97 inputfile
& operator>>(inputfile
& SaveFile
, continent
*& Continent
)
101 Continent
= new continent
;
102 Continent
->Load(SaveFile
);
108 void continent::Add(v2 Pos
)
110 Member
.push_back(Pos
);
111 ContinentBuffer
[Pos
.X
][Pos
.Y
] = Index
;