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
12 /* Compiled through areaset.cpp */
19 area::area (int InitXSize
, int InitYSize
) {
20 Initialize(InitXSize
, InitYSize
);
24 void area::Initialize (int InitXSize
, int 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
));
36 for (feuLong c
= 0; c
< XSizeTimesYSize
; ++c
) delete Map
[0][c
];
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());
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
];
82 void area::SetEntryPos (int I
, v2 Pos
) {
83 EntryMap
.insert(std::make_pair(I
, Pos
));