add non-functional c1 Hatchery
[openc2e.git] / SFCFile.h
blob05b4834ab325dd75c60f0acecd45bf666917833d
1 /*
2 * SFCFile.h
3 * openc2e
5 * Created by Alyssa Milburn on Sat 21 Oct 2006.
6 * Copyright (c) 2006-2008 Alyssa Milburn. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
20 #ifndef _SFCFILE_H
21 #define _SFCFILE_H
23 #include "endianlove.h"
24 #include <map>
25 #include <vector>
26 #include <string>
27 #include <istream>
30 * Note that we don't use shared_ptr here, everything is owned by the
31 * SFCFile. I couldn't find a way to cast downwards with shared_ptr,
32 * and since everything revolves around slurpMFC - which can only return
33 * the base SFCClass type - it seemed best to just use pointers, since
34 * ownership is clear. - fuzzie
37 class SFCClass;
38 class MapData;
39 class SFCObject;
40 class SFCScenery;
42 struct SFCScript {
43 uint8 genus, family;
44 uint16 species, eventno;
45 std::string data;
47 void read(class SFCFile *);
48 void install();
51 class SFCFile {
52 private:
53 bool reading_compound;
54 bool reading_scenery;
55 unsigned int ver;
57 std::vector<SFCClass *> storage;
58 std::map<unsigned int, unsigned int> types;
60 std::istream *ourStream;
62 public:
63 MapData *mapdata;
64 std::vector<SFCObject *> objects;
65 std::vector<SFCScenery *> scenery;
66 std::vector<SFCScript> scripts;
68 uint32 scrollx, scrolly;
69 // TODO: favourite places
71 SFCFile() : reading_compound(false), reading_scenery(false) { }
72 ~SFCFile();
73 void read(std::istream *i);
74 SFCClass *slurpMFC(unsigned int reqtype = 0);
76 uint8 read8();
77 uint16 read16();
78 uint32 read32();
79 signed int reads32() { return (signed int)read32(); }
80 std::string readBytes(unsigned int n);
81 std::string readstring();
83 bool readingScenery() { return reading_scenery; }
84 bool readingCompound() { return reading_compound; }
85 void setVersion(unsigned int v);
86 unsigned int version() { return ver; }
88 void copyToWorld();
91 class SFCClass {
92 protected:
93 friend class SFCFile;
95 SFCFile *parent;
96 SFCClass(SFCFile *p) : parent(p) { }
97 virtual ~SFCClass() { }
99 SFCClass *slurpMFC(unsigned int reqtype = 0) { return parent->slurpMFC(reqtype); }
100 uint8 read8() { return parent->read8(); }
101 uint16 read16() { return parent->read16(); }
102 uint32 read32() { return parent->read32(); }
103 signed int reads32() { return parent->reads32(); }
104 std::string readBytes(unsigned int n) { return parent->readBytes(n); }
105 std::string readstring() { return parent->readstring(); }
107 virtual void read() = 0;
109 public:
110 SFCFile *getParent() { return parent; }
113 class CGallery : public SFCClass {
114 public:
115 uint32 noframes;
116 uint32 firstimg;
117 std::string filename;
119 // no real need for sizes/offsets/etc..
121 CGallery(SFCFile *p) : SFCClass(p) { }
122 void read();
125 class CDoor : public SFCClass {
126 public:
127 uint8 openness;
128 uint16 otherroom;
130 CDoor(SFCFile *p) : SFCClass(p) { }
131 void read();
134 class CRoom : public SFCClass {
135 public:
136 uint32 id;
137 uint32 left, top, right, bottom;
138 std::vector<CDoor *> doors[4];
139 uint32 roomtype;
140 uint8 floorvalue;
141 uint8 inorganicnutrients, organicnutrients, temperature, pressure, lightlevel, radiation;
142 signed char heatsource, pressuresource, lightsource, radiationsource;
143 uint32 windx, windy;
144 std::vector<std::pair<uint32, uint32> > floorpoints;
145 std::string music;
146 uint32 dropstatus;
148 // TODO: misc data
150 CRoom(SFCFile *p) : SFCClass(p) { }
151 void read();
154 class MapData : public SFCClass {
155 public:
156 CGallery *background;
157 std::vector<CRoom *> rooms;
158 unsigned int groundlevels[261];
160 // TODO: misc data
162 MapData(SFCFile *p) : SFCClass(p) { }
163 void read();
164 void copyToWorld();
165 virtual ~MapData();
168 class SFCEntity : public SFCClass {
169 public:
170 CGallery *sprite;
172 uint8 currframe, imgoffset;
173 uint32 zorder;
174 uint32 x, y;
175 bool haveanim;
176 uint8 animframe;
177 std::string animstring;
179 uint32 relx, rely;
181 uint32 partzorder;
182 int bhvrclick[3];
183 uint8 bhvrtouch;
185 std::vector<std::pair<int, int> > pickup_handles;
186 std::vector<std::pair<int, int> > pickup_points;
188 // TODO: misc data/flags
189 SFCEntity(SFCFile *p) : SFCClass(p) { }
190 void read();
193 class SFCObject : public SFCClass {
194 protected:
195 SFCObject(SFCFile *p) : SFCClass(p) { }
197 public:
198 uint8 genus, family;
199 uint16 species;
201 uint32 unid; // needed?
202 uint16 attr;
203 uint32 left, top, right, bottom; // what is this?
204 uint8 actv;
206 std::string currentsound;
208 CGallery *sprite;
210 uint32 tickreset, tickstate;
212 uint32 variables[100];
214 uint8 size, threat;
215 uint32 range, accg, velx, vely, rest, aero;
216 uint32 gravdata;
218 bool frozen;
220 std::vector<SFCScript> scripts;
221 void read();
222 virtual void copyToWorld() = 0;
223 virtual class Agent *copiedAgent() = 0;
226 struct SFCHotspot {
227 int left, top, right, bottom;
228 int function;
229 uint16 message;
230 uint8 mask;
233 class SFCCompoundObject : public SFCObject {
234 protected:
235 class CompoundAgent *ourAgent;
237 public:
238 std::vector<SFCEntity *> parts;
240 SFCHotspot hotspots[6];
242 SFCCompoundObject(SFCFile *p) : SFCObject(p) { ourAgent = 0; }
243 void read();
244 void copyToWorld();
245 class Agent *copiedAgent() { return (Agent *)ourAgent; }
248 class SFCBlackboard : public SFCCompoundObject {
249 public:
250 uint32 textx, texty;
251 uint32 backgroundcolour, chalkcolour, aliascolour;
252 std::vector<std::pair<uint32, std::string> > strings;
254 SFCBlackboard(SFCFile *p) : SFCCompoundObject(p) { }
255 void read();
256 void copyToWorld();
259 class SFCVehicle : public SFCCompoundObject {
260 public:
261 uint32 cabinleft, cabintop, cabinright, cabinbottom;
262 int xvec, yvec;
263 uint8 bump;
265 // TODO: misc data
267 SFCVehicle(SFCFile *p) : SFCCompoundObject(p) { }
268 void read();
269 void copyToWorld();
272 class SFCLift : public SFCVehicle {
273 friend class SFCCallButton;
275 public:
276 uint32 nobuttons;
277 uint32 currentbutton;
278 uint32 callbuttony[8];
279 bool alignwithcabin;
280 // TODO: misc data
282 SFCLift(SFCFile *p) : SFCVehicle(p) { }
283 void read();
284 void copyToWorld();
287 class SFCSimpleObject : public SFCObject {
288 protected:
289 class SimpleAgent *ourAgent;
291 public:
292 SFCEntity *entity;
294 SFCSimpleObject(SFCFile *p) : SFCObject(p) { ourAgent = 0; }
295 void read();
296 void copyToWorld();
297 class Agent *copiedAgent() { return (Agent *)ourAgent; }
300 class SFCPointerTool : public SFCSimpleObject {
301 public:
302 // TODO: misc data
304 SFCPointerTool(SFCFile *p) : SFCSimpleObject(p) { }
305 void read();
306 void copyToWorld();
309 class SFCCallButton : public SFCSimpleObject {
310 public:
311 SFCLift *ourLift;
312 uint8 liftid;
314 SFCCallButton(SFCFile *p) : SFCSimpleObject(p) { }
315 void read();
316 void copyToWorld();
319 class SFCScenery : public SFCSimpleObject {
320 public:
321 SFCScenery(SFCFile *p) : SFCSimpleObject(p) { }
322 void copyToWorld();
325 #endif
327 /* vim: set noet: */