5 * Created by Alyssa Milburn on Tue May 25 2004.
6 * Copyright (c) 2004-2006 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.
33 CreatureAgent
*parent
;
34 shared_ptr
<genomeFile
> genome
;
42 bool alive
, asleep
, dreaming
, tickage
;
46 unsigned int age
; // in ticks
52 std::vector
<AgentRef
> chosenagents
;
53 bool agentInSight(AgentRef a
);
55 virtual AgentRef
selectRepresentativeAgent(int type
, std::vector
<AgentRef
> possibles
) { return AgentRef(); } // TODO: make pure virtual?
59 // to-be-processed instincts
60 std::deque
<creatureInstinctGene
*> unprocessedinstincts
;
62 // conscious flag? brain/motor enabled flags? flags for each 'faculty'?
64 unsigned short tintinfo
[5]; // red, green, blue, rotation, swap
66 virtual void processGenes();
67 virtual void addGene(gene
*);
69 Creature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
76 virtual void ageCreature();
77 lifestage
getStage() { return stage
; }
79 void setAsleep(bool asleep
);
80 bool isAsleep() { return asleep
; }
81 void setDreaming(bool dreaming
);
82 bool isDreaming() { return dreaming
; }
83 bool isFemale() { return female
; }
84 bool isAlive() { return alive
; }
85 void setZombie(bool z
) { zombie
= z
; }
86 bool isZombie() { return zombie
; }
87 unsigned int getAge() { return age
; }
88 shared_ptr
<genomeFile
> getGenome() { return genome
; }
90 unsigned short getGenus() { return genus
; }
91 unsigned int getVariant() { return variant
; }
92 unsigned short getTint(unsigned int id
) { return tintinfo
[id
]; }
94 AgentRef
getAttentionFocus() { return attention
; }
95 int getAttentionId() { return attn
; }
96 int getDecisionId() { return decn
; }
98 virtual unsigned int getGait() = 0;
103 bool shouldProcessGene(gene
*);
109 bioReactionGene
*data
;
110 void init(bioReactionGene
*);
114 bioReceptorGene
*data
;
115 unsigned char *locus
;
116 void init(bioReceptorGene
*, class c1Creature
*);
120 bioEmitterGene
*data
;
121 unsigned char *locus
;
122 void init(bioEmitterGene
*, class c1Creature
*);
125 class oldCreature
: public Creature
{
128 unsigned char chemicals
[256];
130 class oldBrain
*brain
;
132 unsigned int biochemticks
;
133 bioHalfLivesGene
*halflives
;
136 unsigned char floatingloci
[8];
137 unsigned char muscleenergy
;
138 unsigned char lifestageloci
[7];
139 unsigned char fertile
, receptive
, pregnant
;
141 unsigned char involaction
[8];
143 void addGene(gene
*);
145 virtual void tickBiochemistry();
147 inline unsigned int calculateTickMask(unsigned char);
148 inline unsigned int calculateMultiplier(unsigned char);
150 oldCreature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
155 void addChemical(unsigned char id
, unsigned char val
);
156 void subChemical(unsigned char id
, unsigned char val
);
157 unsigned char getChemical(unsigned char id
) { return chemicals
[id
]; }
159 // TODO: is it really worth having drives outside oldCreature?
160 virtual unsigned char getDrive(unsigned int id
) = 0;
162 oldBrain
*getBrain() { return brain
; }
165 class c1Creature
: public oldCreature
{
167 std::vector
<shared_ptr
<c1Reaction
> > reactions
;
168 std::vector
<c1Receptor
> receptors
;
169 std::vector
<c1Emitter
> emitters
;
172 unsigned char senses
[6];
173 unsigned char gaitloci
[8];
174 unsigned char drives
[16];
176 void addGene(gene
*);
177 void tickBiochemistry();
178 void processReaction(c1Reaction
&);
179 void processEmitter(c1Emitter
&);
180 void processReceptor(c1Receptor
&);
183 c1Creature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
187 unsigned char getDrive(unsigned int id
) { assert(id
< 16); return drives
[id
]; }
189 unsigned char *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
);
191 unsigned int getGait();
194 class c2Creature
: public oldCreature
{
197 unsigned char senses
[14];
198 unsigned char gaitloci
[16];
199 unsigned char drives
[17];
200 unsigned char mutationchance
, mutationdegree
;
203 c2Creature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
205 unsigned char getDrive(unsigned int id
) { assert(id
< 17); return drives
[id
]; }
207 unsigned int getGait();
213 bioReactionGene
*data
;
215 unsigned int receptors
;
216 void init(bioReactionGene
*);
220 bioReceptorGene
*data
;
224 unsigned int *receptors
;
225 float nominal
, threshold
, gain
;
226 void init(bioReceptorGene
*, class c2eOrgan
*, shared_ptr
<c2eReaction
>);
230 bioEmitterGene
*data
;
231 unsigned char sampletick
;
233 float threshold
, gain
;
234 void init(bioEmitterGene
*, class c2eOrgan
*);
239 friend struct c2eReceptor
;
240 friend struct c2eEmitter
;
242 class c2eCreature
*parent
;
245 std::vector
<shared_ptr
<c2eReaction
> > reactions
;
246 std::vector
<c2eReceptor
> receptors
;
247 std::vector
<c2eEmitter
> emitters
;
250 float energycost
, atpdamagecoefficient
;
253 float lifeforce
, shorttermlifeforce
, longtermlifeforce
;
256 float biotick
, damagerate
, repairrate
, clockrate
, injurytoapply
;
257 unsigned int clockratereceptors
, repairratereceptors
, injuryreceptors
;
259 void processReaction(c2eReaction
&);
260 void processEmitter(c2eEmitter
&);
261 void processReceptor(c2eReceptor
&, bool checkchem
);
263 float *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
, unsigned int **receptors
);
266 c2eOrgan(c2eCreature
*p
, organGene
*g
);
271 float getClockRate() { return clockrate
; }
272 float getRepairRate() { return repairrate
; }
273 float getDamageRate() { return damagerate
; }
274 float getEnergyCost() { return energycost
; }
275 float getInjuryToApply() { return injurytoapply
; }
276 float getInitialLifeforce() { return lifeforce
; }
277 float getShortTermLifeforce() { return shorttermlifeforce
; }
278 float getLongTermLifeforce() { return longtermlifeforce
; }
279 float getATPDamageCoefficient() { return atpdamagecoefficient
; }
281 unsigned int getReceptorCount() { return receptors
.size(); }
282 unsigned int getEmitterCount() { return emitters
.size(); }
283 unsigned int getReactionCount() { return reactions
.size(); }
285 void applyInjury(float);
295 float drive_amount
[4];
296 bool drive_silent
[4];
298 c2eStim() { noun_id
= -1; verb_id
= -1; drive_id
[0] = -1; drive_id
[1] = -1; drive_id
[2] = -1; drive_id
[3] = -1; }
299 void setupDriveStim(unsigned int num
, int id
, float amt
, bool si
) { drive_id
[num
] = id
; drive_amount
[num
] = amt
; drive_silent
[num
] = si
; }
302 class c2eCreature
: public Creature
{
304 // brain config: should possibly be global
305 std::vector
<unsigned int> mappinginfo
;
308 std::vector
<shared_ptr
<c2eOrgan
> > organs
;
309 float chemicals
[256];
312 float lifestageloci
[7];
314 float floatingloci
[32];
315 float fertile
, pregnant
, ovulate
, receptive
, chanceofmutation
, degreeofmutation
;
317 float senses
[14], involaction
[8], gaitloci
[16];
320 unsigned int involactionlatency
[8];
322 bioHalfLivesGene
*halflives
;
324 class c2eBrain
*brain
;
327 bool processInstinct();
328 void tickBiochemistry();
330 void addGene(gene
*);
332 int reverseMapVerbToNeuron(unsigned int verb
);
333 AgentRef
selectRepresentativeAgent(int type
, std::vector
<AgentRef
> possibles
);
336 c2eCreature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
340 void adjustChemical(unsigned char id
, float value
);
341 float getChemical(unsigned char id
) { return chemicals
[id
]; }
342 void adjustDrive(unsigned int id
, float value
);
343 float getDrive(unsigned int id
) { assert(id
< 20); return drives
[id
]; }
345 void setInvolActionLatency(unsigned int id
, unsigned int n
) { assert(id
< 8); involactionlatency
[id
] = n
; }
347 void handleStimulus(c2eStim
&stim
);
348 void handleStimulus(unsigned int id
, float strength
);
350 unsigned int noOrgans() { return organs
.size(); }
351 shared_ptr
<c2eOrgan
> getOrgan(unsigned int i
) { assert(i
< organs
.size()); return organs
[i
]; }
353 class c2eBrain
*getBrain() { return brain
; }
355 float *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
);
357 unsigned int getGait();