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
*);
108 class oldCreature
: public Creature
{
111 unsigned char chemicals
[256];
113 class oldBrain
*brain
;
115 unsigned int biochemticks
;
116 bioHalfLivesGene
*halflives
;
119 unsigned char floatingloci
[8];
120 unsigned char muscleenergy
;
121 unsigned char lifestageloci
[7];
122 unsigned char fertile
, receptive
, pregnant
;
124 unsigned char involaction
[8];
126 void addGene(gene
*);
128 virtual void tickBiochemistry();
130 inline unsigned int calculateTickMask(unsigned char);
131 inline unsigned int calculateMultiplier(unsigned char);
133 oldCreature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
138 void addChemical(unsigned char id
, unsigned char val
);
139 void subChemical(unsigned char id
, unsigned char val
);
140 unsigned char getChemical(unsigned char id
) { return chemicals
[id
]; }
142 // TODO: is it really worth having drives outside oldCreature?
143 virtual unsigned char getDrive(unsigned int id
) = 0;
145 oldBrain
*getBrain() { return brain
; }
151 bioReactionGene
*data
;
152 void init(bioReactionGene
*);
156 bioReceptorGene
*data
;
157 unsigned char *locus
;
158 void init(bioReceptorGene
*, class c1Creature
*);
162 bioEmitterGene
*data
;
163 unsigned char *locus
;
164 void init(bioEmitterGene
*, class c1Creature
*);
167 class c1Creature
: public oldCreature
{
169 std::vector
<shared_ptr
<c1Reaction
> > reactions
;
170 std::vector
<c1Receptor
> receptors
;
171 std::vector
<c1Emitter
> emitters
;
174 unsigned char senses
[6];
175 unsigned char gaitloci
[8];
176 unsigned char drives
[16];
178 void addGene(gene
*);
179 void tickBiochemistry();
180 void processReaction(c1Reaction
&);
181 void processEmitter(c1Emitter
&);
182 void processReceptor(c1Receptor
&);
185 c1Creature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
189 unsigned char getDrive(unsigned int id
) { assert(id
< 16); return drives
[id
]; }
191 unsigned char *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
);
193 unsigned int getGait();
199 bioReactionGene
*data
;
201 unsigned int receptors
;
202 void init(bioReactionGene
*);
206 bioReceptorGene
*data
;
210 unsigned int *receptors
;
211 float nominal
, threshold
, gain
;
212 void init(bioReceptorGene
*, class c2Organ
*, shared_ptr
<c2Reaction
>);
216 bioEmitterGene
*data
;
217 unsigned char sampletick
;
219 float threshold
, gain
;
220 void init(bioEmitterGene
*, class c2Organ
*);
226 class c2Creature
*parent
;
229 std::vector
<shared_ptr
<c2Reaction
> > reactions
;
230 std::vector
<c2Receptor
> receptors
;
231 std::vector
<c2Emitter
> emitters
;
234 unsigned char energycost
, atpdamagecoefficient
;
237 float lifeforce
, shorttermlifeforce
, longtermlifeforce
;
240 unsigned char biotick
, damagerate
, repairrate
, clockrate
, injurytoapply
;
241 unsigned int clockratereceptors
, repairratereceptors
, injuryreceptors
;
243 void processReaction(c2Reaction
&);
244 void processEmitter(c2Emitter
&);
245 void processReceptor(c2Receptor
&, bool checkchem
);
247 unsigned char *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
, unsigned int **receptors
);
250 c2Organ(c2Creature
*p
, organGene
*g
);
255 unsigned char getClockRate() { return clockrate
; }
256 unsigned char getRepairRate() { return repairrate
; }
257 unsigned char getDamageRate() { return damagerate
; }
258 unsigned char getEnergyCost() { return energycost
; }
259 unsigned char getInjuryToApply() { return injurytoapply
; }
260 float getInitialLifeforce() { return lifeforce
; }
261 float getShortTermLifeforce() { return shorttermlifeforce
; }
262 float getLongTermLifeforce() { return longtermlifeforce
; }
263 unsigned char getATPDamageCoefficient() { return atpdamagecoefficient
; }
265 unsigned int getReceptorCount() { return receptors
.size(); }
266 unsigned int getEmitterCount() { return emitters
.size(); }
267 unsigned int getReactionCount() { return reactions
.size(); }
269 void applyInjury(float);
273 class c2Creature
: public oldCreature
{
276 std::vector
<shared_ptr
<c2Organ
> > organs
;
279 unsigned char senses
[14];
280 unsigned char gaitloci
[16];
281 unsigned char drives
[17];
282 unsigned char mutationchance
, mutationdegree
;
284 void addGene(gene
*);
285 void tickBiochemistry();
289 c2Creature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
293 unsigned char getDrive(unsigned int id
) { assert(id
< 17); return drives
[id
]; }
295 unsigned char *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
);
297 unsigned int getGait();
303 bioReactionGene
*data
;
305 unsigned int receptors
;
306 void init(bioReactionGene
*);
310 bioReceptorGene
*data
;
314 unsigned int *receptors
;
315 float nominal
, threshold
, gain
;
316 void init(bioReceptorGene
*, class c2eOrgan
*, shared_ptr
<c2eReaction
>);
320 bioEmitterGene
*data
;
321 unsigned char sampletick
;
323 float threshold
, gain
;
324 void init(bioEmitterGene
*, class c2eOrgan
*);
329 friend struct c2eReceptor
;
330 friend struct c2eEmitter
;
332 class c2eCreature
*parent
;
335 std::vector
<shared_ptr
<c2eReaction
> > reactions
;
336 std::vector
<c2eReceptor
> receptors
;
337 std::vector
<c2eEmitter
> emitters
;
340 float energycost
, atpdamagecoefficient
;
343 float lifeforce
, shorttermlifeforce
, longtermlifeforce
;
346 float biotick
, damagerate
, repairrate
, clockrate
, injurytoapply
;
347 unsigned int clockratereceptors
, repairratereceptors
, injuryreceptors
;
349 void processReaction(c2eReaction
&);
350 void processEmitter(c2eEmitter
&);
351 void processReceptor(c2eReceptor
&, bool checkchem
);
353 float *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
, unsigned int **receptors
);
356 c2eOrgan(c2eCreature
*p
, organGene
*g
);
361 float getClockRate() { return clockrate
; }
362 float getRepairRate() { return repairrate
; }
363 float getDamageRate() { return damagerate
; }
364 float getEnergyCost() { return energycost
; }
365 float getInjuryToApply() { return injurytoapply
; }
366 float getInitialLifeforce() { return lifeforce
; }
367 float getShortTermLifeforce() { return shorttermlifeforce
; }
368 float getLongTermLifeforce() { return longtermlifeforce
; }
369 float getATPDamageCoefficient() { return atpdamagecoefficient
; }
371 unsigned int getReceptorCount() { return receptors
.size(); }
372 unsigned int getEmitterCount() { return emitters
.size(); }
373 unsigned int getReactionCount() { return reactions
.size(); }
375 void applyInjury(float);
385 float drive_amount
[4];
386 bool drive_silent
[4];
388 c2eStim() { noun_id
= -1; verb_id
= -1; drive_id
[0] = -1; drive_id
[1] = -1; drive_id
[2] = -1; drive_id
[3] = -1; }
389 void setupDriveStim(unsigned int num
, int id
, float amt
, bool si
) { drive_id
[num
] = id
; drive_amount
[num
] = amt
; drive_silent
[num
] = si
; }
392 class c2eCreature
: public Creature
{
394 // brain config: should possibly be global
395 std::vector
<unsigned int> mappinginfo
;
398 std::vector
<shared_ptr
<c2eOrgan
> > organs
;
399 float chemicals
[256];
402 float lifestageloci
[7];
404 float floatingloci
[32];
405 float fertile
, pregnant
, ovulate
, receptive
, chanceofmutation
, degreeofmutation
;
407 float senses
[14], involaction
[8], gaitloci
[16];
410 unsigned int involactionlatency
[8];
412 bioHalfLivesGene
*halflives
;
414 class c2eBrain
*brain
;
417 bool processInstinct();
418 void tickBiochemistry();
420 void addGene(gene
*);
422 int reverseMapVerbToNeuron(unsigned int verb
);
423 AgentRef
selectRepresentativeAgent(int type
, std::vector
<AgentRef
> possibles
);
426 c2eCreature(shared_ptr
<genomeFile
> g
, bool is_female
, unsigned char _variant
, CreatureAgent
*a
);
430 void adjustChemical(unsigned char id
, float value
);
431 float getChemical(unsigned char id
) { return chemicals
[id
]; }
432 void adjustDrive(unsigned int id
, float value
);
433 float getDrive(unsigned int id
) { assert(id
< 20); return drives
[id
]; }
435 void setInvolActionLatency(unsigned int id
, unsigned int n
) { assert(id
< 8); involactionlatency
[id
] = n
; }
437 void handleStimulus(c2eStim
&stim
);
438 void handleStimulus(unsigned int id
, float strength
);
440 unsigned int noOrgans() { return organs
.size(); }
441 shared_ptr
<c2eOrgan
> getOrgan(unsigned int i
) { assert(i
< organs
.size()); return organs
[i
]; }
443 class c2eBrain
*getBrain() { return brain
; }
445 float *getLocusPointer(bool receptor
, unsigned char o
, unsigned char t
, unsigned char l
);
447 unsigned int getGait();