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.
23 #include "endianlove.h"
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
45 uint16 species
, eventno
;
48 void read(class SFCFile
*);
54 bool reading_compound
;
58 std::vector
<SFCClass
*> storage
;
59 std::map
<unsigned int, unsigned int> types
;
61 std::istream
*ourStream
;
65 std::vector
<SFCObject
*> objects
;
66 std::vector
<SFCScenery
*> scenery
;
67 std::vector
<SFCScript
> scripts
;
68 std::vector
<SFCMacro
*> macros
;
70 uint32 scrollx
, scrolly
;
71 std::string favplacename
;
72 uint32 favplacex
, favplacey
;
73 std::vector
<std::string
> speech_history
;
75 SFCFile() : reading_compound(false), reading_scenery(false) { }
77 void read(std::istream
*i
);
78 SFCClass
*slurpMFC(unsigned int reqtype
= 0);
83 signed int reads32() { return (signed int)read32(); }
84 std::string
readBytes(unsigned int n
);
85 std::string
readstring();
87 bool readingScenery() { return reading_scenery
; }
88 bool readingCompound() { return reading_compound
; }
89 void setVersion(unsigned int v
);
90 unsigned int version() { return ver
; }
100 SFCClass(SFCFile
*p
) : parent(p
) { }
101 virtual ~SFCClass() { }
103 SFCClass
*slurpMFC(unsigned int reqtype
= 0) { return parent
->slurpMFC(reqtype
); }
104 uint8
read8() { return parent
->read8(); }
105 uint16
read16() { return parent
->read16(); }
106 uint32
read32() { return parent
->read32(); }
107 signed int reads32() { return parent
->reads32(); }
108 std::string
readBytes(unsigned int n
) { return parent
->readBytes(n
); }
109 std::string
readstring() { return parent
->readstring(); }
111 virtual void read() = 0;
114 SFCFile
*getParent() { return parent
; }
117 class CGallery
: public SFCClass
{
121 std::string filename
;
123 // no real need for sizes/offsets/etc..
125 CGallery(SFCFile
*p
) : SFCClass(p
) { }
129 class CDoor
: public SFCClass
{
134 CDoor(SFCFile
*p
) : SFCClass(p
) { }
138 class CRoom
: public SFCClass
{
141 uint32 left
, top
, right
, bottom
;
142 std::vector
<CDoor
*> doors
[4];
145 uint8 inorganicnutrients
, organicnutrients
, temperature
, pressure
, lightlevel
, radiation
;
146 signed char heatsource
, pressuresource
, lightsource
, radiationsource
;
148 std::vector
<std::pair
<uint32
, uint32
> > floorpoints
;
154 CRoom(SFCFile
*p
) : SFCClass(p
) { }
158 class MapData
: public SFCClass
{
160 CGallery
*background
;
161 std::vector
<CRoom
*> rooms
;
162 unsigned int groundlevels
[261];
166 MapData(SFCFile
*p
) : SFCClass(p
) { }
172 class SFCEntity
: public SFCClass
{
176 uint8 currframe
, imgoffset
;
181 std::string animstring
;
189 std::vector
<std::pair
<int, int> > pickup_handles
;
190 std::vector
<std::pair
<int, int> > pickup_points
;
192 // TODO: misc data/flags
193 SFCEntity(SFCFile
*p
) : SFCClass(p
) { }
197 class SFCObject
: public SFCClass
{
199 SFCObject(SFCFile
*p
) : SFCClass(p
) { }
205 uint32 unid
; // needed?
207 uint32 left
, top
, right
, bottom
; // what is this?
210 std::string currentsound
;
214 uint32 tickreset
, tickstate
;
216 uint32 variables
[100];
219 uint32 range
, accg
, velx
, vely
, rest
, aero
;
224 std::vector
<SFCScript
> scripts
;
226 virtual void copyToWorld() = 0;
227 virtual class Agent
*copiedAgent() = 0;
231 int left
, top
, right
, bottom
;
237 class SFCCompoundObject
: public SFCObject
{
239 class CompoundAgent
*ourAgent
;
242 std::vector
<SFCEntity
*> parts
;
244 SFCHotspot hotspots
[6];
246 SFCCompoundObject(SFCFile
*p
) : SFCObject(p
) { ourAgent
= 0; }
249 class Agent
*copiedAgent() { return (Agent
*)ourAgent
; }
252 class SFCBlackboard
: public SFCCompoundObject
{
255 uint32 backgroundcolour
, chalkcolour
, aliascolour
;
256 std::vector
<std::pair
<uint32
, std::string
> > strings
;
258 SFCBlackboard(SFCFile
*p
) : SFCCompoundObject(p
) { }
263 class SFCVehicle
: public SFCCompoundObject
{
265 uint32 cabinleft
, cabintop
, cabinright
, cabinbottom
;
271 SFCVehicle(SFCFile
*p
) : SFCCompoundObject(p
) { }
276 class SFCLift
: public SFCVehicle
{
277 friend class SFCCallButton
;
281 uint32 currentbutton
;
282 uint32 callbuttony
[8];
286 SFCLift(SFCFile
*p
) : SFCVehicle(p
) { }
291 class SFCSimpleObject
: public SFCObject
{
293 class SimpleAgent
*ourAgent
;
298 SFCSimpleObject(SFCFile
*p
) : SFCObject(p
) { ourAgent
= 0; }
301 class Agent
*copiedAgent() { return (Agent
*)ourAgent
; }
304 class SFCPointerTool
: public SFCSimpleObject
{
308 SFCPointerTool(SFCFile
*p
) : SFCSimpleObject(p
) { }
313 class SFCCallButton
: public SFCSimpleObject
{
318 SFCCallButton(SFCFile
*p
) : SFCSimpleObject(p
) { }
323 class SFCScenery
: public SFCSimpleObject
{
325 SFCScenery(SFCFile
*p
) : SFCSimpleObject(p
) { }
329 class SFCMacro
: public SFCClass
{
331 SFCObject
*owner
, *from
, *targ
;
335 SFCMacro(SFCFile
*p
) : SFCClass(p
) { }