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"
28 #include <boost/enable_shared_from_this.hpp>
35 bool operator()(const class Agent
*s1
, const class Agent
*s2
) const;
38 class Agent
: public boost::enable_shared_from_this
<Agent
> {
40 friend struct agentzorder
;
42 friend class AgentRef
;
46 friend class LifeAssert
;
48 friend class SFCSimpleObject
;
49 friend class SFCCompoundObject
;
50 friend class QtOpenc2e
; // i despise c++ - fuzzie
52 FRIEND_SERIALIZE(Agent
);
56 virtual void finishInit();
60 Agent() { core_init(); } // for boost only
64 caosVar var
[100]; // OVxx
65 std::map
<caosVar
, caosVar
, caosVarCompare
> name_variables
;
66 std::map
<unsigned int, shared_ptr
<class genomeFile
> > slots
;
73 unsigned int tickssincelasttimer
, timerrate
;
77 int emitca_index
; float emitca_amount
;
78 int lastcollidedirection
;
80 std::multiset
<Agent
*, agentzorder
>::iterator zorder_iter
;
81 std::list
<boost::shared_ptr
<Agent
> >::iterator agents_iter
;
82 std::list
<caosVM
*> vmstack
; // for CALL etc
83 std::vector
<AgentRef
> floated
;
85 void updateAudio(boost::shared_ptr
<class AudioSource
>);
89 virtual bool fireScript(unsigned short event
, Agent
*from
, caosVar one
, caosVar two
);
91 virtual void physicsTick();
94 std::map
<unsigned int, std::pair
<int, int> > carry_points
, carried_points
;
96 virtual void carry(AgentRef
);
97 virtual void drop(AgentRef
);
99 virtual std::pair
<int, int> getCarryPoint();
100 virtual std::pair
<int, int> getCarriedPoint();
101 virtual void adjustCarried(float xoffset
, float yoffset
);
104 boost::shared_ptr
<class AudioSource
> sound
;
110 inline bool isDying() const {
116 // values which are always the same
117 bool carryable() { return attr
.getInt() & 1; }
118 bool mouseable() { return attr
.getInt() & 2; }
119 bool activateable() { return attr
.getInt() & 4; }
120 bool greedycabin() { return attr
.getInt() & 8; }
121 bool invisible() { return attr
.getInt() & 16; }
122 bool floatable() { return attr
.getInt() & 32; }
123 // version-specific values
125 bool groundbound() { return attr
.getInt() & 64; }
126 bool roombound() { return attr
.getInt() & 128; }
128 bool suffercollisions() { return attr
.getInt() & 64; }
129 bool sufferphysics() { return attr
.getInt() & 128; }
131 bool camerashy() { return attr
.getInt() & 256; }
132 bool openaircabin() { return attr
.getInt() & 512; }
133 bool rotatable() { return attr
.getInt() & 1024; }
134 bool presence() { return attr
.getInt() & 2048; }
137 bool cr_can_push
: 1;
138 bool cr_can_pull
: 1;
139 bool cr_can_stop
: 1;
142 bool cr_can_pickup
: 1;
144 bool imsk_key_down
: 1;
145 bool imsk_key_up
: 1;
146 bool imsk_mouse_move
: 1;
147 bool imsk_mouse_down
: 1;
148 bool imsk_mouse_up
: 1;
149 bool imsk_mouse_wheel
: 1;
150 bool imsk_translated_char
: 1;
155 bool displaycore
: 1;
157 int clac
[3]; int clik
;
159 void setClassifier(unsigned char f
, unsigned char g
, unsigned short s
);
160 unsigned char family
, genus
;
161 unsigned short species
;
167 unsigned int friction
;
171 bool falling
: 1; // TODO: icky hack, possibly
175 AgentRef floatingagent
;
177 // Creatures 1/2 bits
178 caosVar objp
, babymoniker
;
181 // TODO: size/grav likely duplicates of perm/falling
182 caosVar actv
, thrt
, size
, grav
;
184 Agent(unsigned char f
, unsigned char g
, unsigned short s
, unsigned int p
);
189 void addFloated(AgentRef
);
190 void delFloated(AgentRef
);
191 void floatTo(AgentRef
);
192 void floatTo(float x
, float y
);
196 void addCarried(AgentRef
);
197 void dropCarried(AgentRef
);
199 bool queueScript(unsigned short event
, AgentRef from
= AgentRef(), caosVar p0
= caosVar(), caosVar p1
= caosVar());
201 void pushVM(caosVM
*newvm
);
204 void moveTo(float, float, bool force
= false);
205 bool tryMoveToPlaceAround(float x
, float y
);
207 void setTimerRate(unsigned int r
) { tickssincelasttimer
= 0; timerrate
= r
; }
209 virtual void handleClick(float, float);
211 virtual CompoundPart
*part(unsigned int id
) = 0;
213 unsigned int getWidth() { return part(0)->getWidth(); }
214 unsigned int getHeight() { return part(0)->getHeight(); }
215 Point
const boundingBoxPoint(unsigned int n
);
216 Point
const boundingBoxPoint(unsigned int n
, Point p
, unsigned int w
, unsigned int h
);
217 shared_ptr
<class Room
> const bestRoomAt(unsigned int x
, unsigned int y
, unsigned int direction
, shared_ptr
<Room
> exclude
);
218 void const findCollisionInDirection(unsigned int i
, Point src
, int &dx
, int &dy
, Point
&deltapt
, double &delta
, bool &collided
, bool followrooms
);
220 bool validInRoomSystem();
221 bool const validInRoomSystem(Point p
, unsigned int w
, unsigned int h
, int testperm
);
225 void unhandledException(std::string info
, bool wasscript
);
227 virtual void setZOrder(unsigned int plane
); // should be overridden!
228 virtual unsigned int getZOrder() const;
230 class shared_ptr
<script
> findScript(unsigned short event
);
233 std::string
identify() const;
235 void setAttributes(unsigned int a
) { attr
.setInt(a
); }
236 unsigned int getAttributes() const { return attr
.getInt(); }
238 void playAudio(std::string filename
, bool controlled
, bool loop
);
240 shared_ptr
<class genomeFile
> getSlot(unsigned int s
) { return slots
[s
]; }
247 LifeAssert(const AgentRef
&ref
) {
252 LifeAssert(const boost::weak_ptr
<Agent
> &p_
) {
257 LifeAssert(const boost::shared_ptr
<Agent
> &p_
) {
262 LifeAssert(Agent
*p_
) {