5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004 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.
25 #include "CompoundPart.h"
30 #include <boost/enable_shared_from_this.hpp>
37 bool operator()(const class Agent
*s1
, const class Agent
*s2
) const;
40 class Agent
: public boost::enable_shared_from_this
<Agent
> {
42 friend struct agentzorder
;
44 friend class AgentRef
;
48 friend class LifeAssert
;
50 friend class SFCSimpleObject
;
51 friend class SFCCompoundObject
;
52 friend class QtOpenc2e
; // i despise c++ - fuzzie
54 FRIEND_SERIALIZE(Agent
);
58 virtual void finishInit();
62 Agent() { core_init(); } // for boost only
66 caosVar var
[100]; // OVxx
67 std::map
<caosVar
, caosVar
, caosVarCompare
> name_variables
;
68 std::map
<unsigned int, shared_ptr
<class genomeFile
> > slots
;
75 unsigned int tickssincelasttimer
, timerrate
;
79 int emitca_index
; float emitca_amount
;
80 int lastcollidedirection
;
82 std::multiset
<Agent
*, agentzorder
>::iterator zorder_iter
;
83 std::list
<boost::shared_ptr
<Agent
> >::iterator agents_iter
;
84 std::list
<caosVM
*> vmstack
; // for CALL etc
85 std::vector
<AgentRef
> floated
;
87 void updateAudio(boost::shared_ptr
<class AudioSource
>);
91 virtual bool fireScript(unsigned short event
, Agent
*from
, caosVar one
, caosVar two
);
93 virtual void physicsTick();
96 std::map
<unsigned int, std::pair
<int, int> > carry_points
, carried_points
;
98 virtual void carry(AgentRef
);
99 virtual void drop(AgentRef
);
101 virtual std::pair
<int, int> getCarryPoint();
102 virtual std::pair
<int, int> getCarriedPoint();
103 virtual void adjustCarried(float xoffset
, float yoffset
);
106 boost::shared_ptr
<class AudioSource
> sound
;
108 // these are maps rather than vectors because ports can be destroyed
109 std::map
<unsigned int, boost::shared_ptr
<InputPort
> > inports
; // XXX: do these need to be shared_ptr?
110 std::map
<unsigned int, boost::shared_ptr
<OutputPort
> > outports
;
112 void join(unsigned int outid
, AgentRef dest
, unsigned int inid
);
118 inline bool isDying() const {
124 // values which are always the same
125 bool carryable() { return attr
.getInt() & 1; }
126 bool mouseable() { return attr
.getInt() & 2; }
127 bool activateable() { return attr
.getInt() & 4; }
128 bool greedycabin() { return attr
.getInt() & 8; }
129 bool invisible() { return attr
.getInt() & 16; }
130 bool floatable() { return attr
.getInt() & 32; }
131 // version-specific values
133 bool groundbound() { return attr
.getInt() & 64; }
134 bool roombound() { return attr
.getInt() & 128; }
136 bool suffercollisions() { return attr
.getInt() & 64; }
137 bool sufferphysics() { return attr
.getInt() & 128; }
139 bool camerashy() { return attr
.getInt() & 256; }
140 bool openaircabin() { return attr
.getInt() & 512; }
141 bool rotatable() { return attr
.getInt() & 1024; }
142 bool presence() { return attr
.getInt() & 2048; }
145 bool cr_can_push
: 1;
146 bool cr_can_pull
: 1;
147 bool cr_can_stop
: 1;
150 bool cr_can_pickup
: 1;
152 bool imsk_key_down
: 1;
153 bool imsk_key_up
: 1;
154 bool imsk_mouse_move
: 1;
155 bool imsk_mouse_down
: 1;
156 bool imsk_mouse_up
: 1;
157 bool imsk_mouse_wheel
: 1;
158 bool imsk_translated_char
: 1;
163 bool displaycore
: 1;
165 int clac
[3]; int clik
;
167 void setClassifier(unsigned char f
, unsigned char g
, unsigned short s
);
168 unsigned char family
, genus
;
169 unsigned short species
;
175 unsigned int friction
;
179 bool falling
: 1; // TODO: icky hack, possibly
183 AgentRef floatingagent
;
185 // Creatures 1/2 bits
186 caosVar objp
, babymoniker
;
189 // TODO: size/grav likely duplicates of perm/falling
190 caosVar actv
, thrt
, size
, grav
;
192 Agent(unsigned char f
, unsigned char g
, unsigned short s
, unsigned int p
);
197 void addFloated(AgentRef
);
198 void delFloated(AgentRef
);
199 void floatTo(AgentRef
);
200 void floatTo(float x
, float y
);
204 void addCarried(AgentRef
);
205 void dropCarried(AgentRef
);
207 bool queueScript(unsigned short event
, AgentRef from
= AgentRef(), caosVar p0
= caosVar(), caosVar p1
= caosVar());
209 void pushVM(caosVM
*newvm
);
212 void moveTo(float, float, bool force
= false);
213 bool tryMoveToPlaceAround(float x
, float y
);
215 void setTimerRate(unsigned int r
) { tickssincelasttimer
= 0; timerrate
= r
; }
217 virtual int handleClick(float, float);
219 virtual CompoundPart
*part(unsigned int id
) = 0;
221 unsigned int getWidth() { return part(0)->getWidth(); }
222 unsigned int getHeight() { return part(0)->getHeight(); }
223 Point
const boundingBoxPoint(unsigned int n
);
224 Point
const boundingBoxPoint(unsigned int n
, Point p
, unsigned int w
, unsigned int h
);
225 shared_ptr
<class Room
> const bestRoomAt(unsigned int x
, unsigned int y
, unsigned int direction
, shared_ptr
<Room
> exclude
);
226 void const findCollisionInDirection(unsigned int i
, Point src
, int &dx
, int &dy
, Point
&deltapt
, double &delta
, bool &collided
, bool followrooms
);
228 bool validInRoomSystem();
229 bool const validInRoomSystem(Point p
, unsigned int w
, unsigned int h
, int testperm
);
233 void unhandledException(std::string info
, bool wasscript
);
235 virtual void setZOrder(unsigned int plane
); // should be overridden!
236 virtual unsigned int getZOrder() const;
238 class shared_ptr
<script
> findScript(unsigned short event
);
241 std::string
identify() const;
243 void setAttributes(unsigned int a
) { attr
.setInt(a
); }
244 unsigned int getAttributes() const { return attr
.getInt(); }
246 void playAudio(std::string filename
, bool controlled
, bool loop
);
248 shared_ptr
<class genomeFile
> getSlot(unsigned int s
) { return slots
[s
]; }
255 LifeAssert(const AgentRef
&ref
) {
260 LifeAssert(const boost::weak_ptr
<Agent
> &p_
) {
265 LifeAssert(const boost::shared_ptr
<Agent
> &p_
) {
270 LifeAssert(Agent
*p_
) {