moved almost all hardcoded constants to "define.dat"
[k8-i-v-a-n.git] / src / game / area.cpp
blobd78759964c1adb719184e28f4748536b4c680819
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
12 /* Compiled through areaset.cpp */
15 area::area () {
19 area::area (int InitXSize, int InitYSize) {
20 Initialize(InitXSize, InitYSize);
24 void area::Initialize (int InitXSize, int InitYSize) {
25 XSize = InitXSize;
26 YSize = InitYSize;
27 XSizeTimesYSize = XSize * YSize;
28 Border = rect(0, 0, XSize - 1, YSize - 1);
29 Alloc2D(Map, XSize, YSize);
30 Alloc2D(FlagMap, XSize, YSize);
31 memset(FlagMap[0], 0, XSizeTimesYSize * sizeof(uChar));
35 area::~area () {
36 for (feuLong c = 0; c < XSizeTimesYSize; ++c) delete Map[0][c];
37 delete [] Map;
38 delete [] FlagMap;
42 void area::Save (outputfile &SaveFile) const {
43 SaveFile << XSize << YSize << EntryMap;
44 SaveFile.Write(reinterpret_cast<cchar *>(FlagMap[0]), XSizeTimesYSize*sizeof(uChar));
48 void area::Load (inputfile &SaveFile) {
49 game::SetAreaInLoad(this);
50 SaveFile >> XSize >> YSize;
51 if (SaveFile.Eof()) ABORT("Area file %s corrupted!", SaveFile.GetFileName().CStr());
52 SaveFile >> EntryMap;
53 XSizeTimesYSize = XSize*YSize;
54 Border = rect(0, 0, XSize-1, YSize-1);
55 Alloc2D(Map, XSize, YSize);
56 Alloc2D(FlagMap, XSize, YSize);
57 SaveFile.Read(reinterpret_cast<char *>(FlagMap[0]), XSizeTimesYSize*sizeof(uChar));
61 void area::SendNewDrawRequest () {
62 cint XMin = Max(game::GetCamera().X, 0);
63 cint YMin = Max(game::GetCamera().Y, 0);
64 cint XMax = Min(XSize, game::GetCamera().X + game::GetScreenXSize());
65 cint YMax = Min(YSize, game::GetCamera().Y + game::GetScreenYSize());
66 for (int x = XMin; x < XSize && x < XMax; ++x)
67 for (int y = YMin; y < YMax; ++y)
68 Map[x][y]->SendStrongNewDrawRequest();
69 igraph::GetBackGround()->FastBlit(DOUBLE_BUFFER);
70 DOUBLE_BUFFER->DrawRectangle(14, 30, 17 + (game::GetScreenXSize() << 4), 33 + (game::GetScreenYSize() << 4), DARK_GRAY, true);
71 DOUBLE_BUFFER->Fill(16, 32, game::GetScreenXSize() << 4, game::GetScreenYSize() << 4, BLACK);
75 square *area::GetNeighbourSquare (v2 Pos, int I) const {
76 Pos += game::GetMoveVector(I);
77 if (Pos.X >= 0 && Pos.Y >= 0 && Pos.X < XSize && Pos.Y < YSize) return Map[Pos.X][Pos.Y];
78 return 0;
82 void area::SetEntryPos (int I, v2 Pos) {
83 EntryMap.insert(std::make_pair(I, Pos));