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
);
61 Agent() { core_init(); } // for boost only
65 caosVar var
[100]; // OVxx
66 std::map
<caosVar
, caosVar
, caosVarCompare
> name_variables
;
67 std::map
<unsigned int, shared_ptr
<class genomeFile
> > slots
;
74 unsigned int tickssincelasttimer
, timerrate
;
78 int emitca_index
; float emitca_amount
;
79 int lastcollidedirection
;
81 std::multiset
<Agent
*, agentzorder
>::iterator zorder_iter
;
82 std::list
<boost::shared_ptr
<Agent
> >::iterator agents_iter
;
83 std::list
<caosVM
*> vmstack
; // for CALL etc
84 std::vector
<AgentRef
> floated
;
86 void updateAudio(boost::shared_ptr
<class AudioSource
>);
90 virtual bool fireScript(unsigned short event
, Agent
*from
, caosVar one
, caosVar two
);
92 virtual void physicsTick();
95 virtual void carry(AgentRef
);
96 virtual void drop(AgentRef
);
98 virtual std::pair
<int, int> getCarryPoint();
99 virtual std::pair
<int, int> getCarriedPoint();
100 virtual void adjustCarried(float xoffset
, float yoffset
);
103 std::map
<unsigned int, std::pair
<int, int> > carry_points
, carried_points
;
105 boost::shared_ptr
<class AudioSource
> sound
;
107 // these are maps rather than vectors because ports can be destroyed
108 std::map
<unsigned int, boost::shared_ptr
<InputPort
> > inports
; // XXX: do these need to be shared_ptr?
109 std::map
<unsigned int, boost::shared_ptr
<OutputPort
> > outports
;
111 void join(unsigned int outid
, AgentRef dest
, unsigned int inid
);
117 inline bool isDying() const {
123 // values which are always the same
124 bool carryable() { return attr
.getInt() & 1; }
125 bool mouseable() { return attr
.getInt() & 2; }
126 bool activateable() { return attr
.getInt() & 4; }
127 bool greedycabin() { return attr
.getInt() & 8; }
128 bool invisible() { return attr
.getInt() & 16; }
129 bool floatable() { return attr
.getInt() & 32; }
130 // version-specific values
132 bool groundbound() { return attr
.getInt() & 64; }
133 bool roombound() { return attr
.getInt() & 128; }
135 bool suffercollisions() { return attr
.getInt() & 64; }
136 bool sufferphysics() { return attr
.getInt() & 128; }
138 bool camerashy() { return attr
.getInt() & 256; }
139 bool openaircabin() { return attr
.getInt() & 512; }
140 bool rotatable() { return attr
.getInt() & 1024; }
141 bool presence() { return attr
.getInt() & 2048; }
144 bool cr_can_push
: 1;
145 bool cr_can_pull
: 1;
146 bool cr_can_stop
: 1;
149 bool cr_can_pickup
: 1;
151 bool imsk_key_down
: 1;
152 bool imsk_key_up
: 1;
153 bool imsk_mouse_move
: 1;
154 bool imsk_mouse_down
: 1;
155 bool imsk_mouse_up
: 1;
156 bool imsk_mouse_wheel
: 1;
157 bool imsk_translated_char
: 1;
162 bool displaycore
: 1;
164 int clac
[3]; int clik
;
166 void setClassifier(unsigned char f
, unsigned char g
, unsigned short s
);
167 unsigned char family
, genus
;
168 unsigned short species
;
174 unsigned int friction
;
178 bool falling
: 1; // TODO: icky hack, possibly
182 AgentRef floatingagent
;
184 // Creatures 1/2 bits
185 caosVar objp
, babymoniker
;
188 // TODO: size/grav likely duplicates of perm/falling
189 caosVar actv
, thrt
, size
, grav
;
191 Agent(unsigned char f
, unsigned char g
, unsigned short s
, unsigned int p
);
194 virtual void finishInit();
198 void addFloated(AgentRef
);
199 void delFloated(AgentRef
);
200 void floatTo(AgentRef
);
201 void floatTo(float x
, float y
);
205 void addCarried(AgentRef
);
206 void dropCarried(AgentRef
);
208 bool queueScript(unsigned short event
, AgentRef from
= AgentRef(), caosVar p0
= caosVar(), caosVar p1
= caosVar());
210 void pushVM(caosVM
*newvm
);
213 void moveTo(float, float, bool force
= false);
214 bool tryMoveToPlaceAround(float x
, float y
);
216 void setTimerRate(unsigned int r
) { tickssincelasttimer
= 0; timerrate
= r
; }
218 virtual int handleClick(float, float);
220 virtual CompoundPart
*part(unsigned int id
) = 0;
222 unsigned int getWidth() { return part(0)->getWidth(); }
223 unsigned int getHeight() { return part(0)->getHeight(); }
224 Point
const boundingBoxPoint(unsigned int n
);
225 Point
const boundingBoxPoint(unsigned int n
, Point p
, unsigned int w
, unsigned int h
);
226 shared_ptr
<class Room
> const bestRoomAt(unsigned int x
, unsigned int y
, unsigned int direction
, class MetaRoom
*m
, shared_ptr
<Room
> exclude
);
227 void const findCollisionInDirection(unsigned int i
, class MetaRoom
*m
, Point src
, int &dx
, int &dy
, Point
&deltapt
, double &delta
, bool &collided
, bool followrooms
);
229 bool validInRoomSystem();
230 bool const validInRoomSystem(Point p
, unsigned int w
, unsigned int h
, int testperm
);
234 void unhandledException(std::string info
, bool wasscript
);
236 virtual void setZOrder(unsigned int plane
); // should be overridden!
237 virtual unsigned int getZOrder() const;
239 class shared_ptr
<script
> findScript(unsigned short event
);
242 std::string
identify() const;
244 void setAttributes(unsigned int a
) { attr
.setInt(a
); }
245 unsigned int getAttributes() const { return attr
.getInt(); }
247 void playAudio(std::string filename
, bool controlled
, bool loop
);
249 shared_ptr
<class genomeFile
> getSlot(unsigned int s
) { return slots
[s
]; }
256 LifeAssert(const AgentRef
&ref
) {
261 LifeAssert(const boost::weak_ptr
<Agent
> &p_
) {
266 LifeAssert(const boost::shared_ptr
<Agent
> &p_
) {
271 LifeAssert(Agent
*p_
) {