2 *This file includes the basic classes for map/savegame loading
4 * Copyright (C) 2008 Mathias Gottschlag
6 * This file is part of OpenStranded
8 * OpenStranded is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * OpenStranded is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
27 #include "eal/engine.hh"
33 environment
= eal::Engine::get()->addEnvironment();
40 Map::load (std::string path
)
46 std::cerr
<< "Map file couldn't be opened: " << path
<< std::endl
;
51 std::string format
= mapfile
.readLine();
52 std::string version
= mapfile
.readLine();
53 std::string date
= mapfile
.readLine();
54 std::string time
= mapfile
.readLine();
55 format
= mapfile
.readLine();
56 std::string mode
= mapfile
.readLine();
58 std::string typeformat
= mapfile
.readLine();
62 if (typeformat
.size() >= 3)
64 objectformat
= typeformat
[0] - '0';
65 unitformat
= typeformat
[1] - '0';
66 infoformat
= typeformat
[2] - '0';
76 uint8_t mapimage
[96 * 72 * 3];
77 mapfile
.readData(mapimage
, 96 * 72 * 3);
84 // Environment settings
85 int day
= mapfile
.readInt();
86 int hour
= mapfile
.readByte();
87 int minute
= mapfile
.readByte();
88 int freezetime
= mapfile
.readByte();
89 std::string skybox
= mapfile
.readString();
90 int multiplayer
= mapfile
.readByte();
91 int climate
= mapfile
.readByte();
92 std::string music
= mapfile
.readString();
93 std::string briefing
= mapfile
.readString();
94 int fogr
= mapfile
.readByte();
95 int fogg
= mapfile
.readByte();
96 int fogb
= mapfile
.readByte();
97 int fogmode
= mapfile
.readByte();
102 for (int i
= 0; i
< 10; i
++)
103 mapfile
.readString();
106 int colormapsize
= mapfile
.readInt();
107 printf("Color map size: %d\n", colormapsize
);
108 uint8_t *colormap
= new uint8_t[colormapsize
* colormapsize
* 3];
109 mapfile
.readData(colormap
, colormapsize
* colormapsize
* 3);
111 int heightmapsize
= mapfile
.readInt();
112 printf("Height map size: %d\n", heightmapsize
);
113 float *heightmap
= new float[(heightmapsize
+ 1) * (heightmapsize
+ 1)];
114 mapfile
.readData(heightmap
, (heightmapsize
+ 1) * (heightmapsize
+ 1) * sizeof(float));
116 uint8_t *grassmap
= new uint8_t[(colormapsize
+ 1) * (colormapsize
+ 1)];
117 mapfile
.readData(grassmap
, (colormapsize
+ 1) * (colormapsize
+ 1));
120 environment
->setSize(heightmapsize
);
121 environment
->setHeightData(heightmap
);
122 environment
->setColorMap(colormap
, colormapsize
);
123 environment
->setSkyCube(skybox
);
124 environment
->setFog(eal::Color(fogr
, fogg
, fogb
));
129 int objectcount
= mapfile
.readInt();
130 for (int i
= 0; i
< objectcount
; i
++)
132 ID id
= mapfile
.readInt();
136 type
= mapfile
.readShort();
140 type
= mapfile
.readByte();
142 float x
= mapfile
.readFloat();
143 float z
= mapfile
.readFloat();
144 float yaw
= mapfile
.readFloat();
145 float health
= mapfile
.readFloat();
146 float maxhealth
= mapfile
.readFloat();
147 int daytimer
= mapfile
.readInt();
150 Entity
*newobject
= Kingdom::kingdomList
[S2_OBJECT
]->insertEntity(type
, id
);
151 newobject
->setPosition(eal::Vector3(x
, environment
->getHeight(eal::Vector2(x
, z
)), z
));
153 printf("%d objects.\n", objectcount
);
154 // TODO: Load other entity types