5 * Created by Alyssa Milburn on Fri Dec 9 2005.
6 * Copyright (c) 2005 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.
22 #include "CreatureAgent.h"
26 GENE CLON (command) dest_agent (agent) dest_slot (integer) src_agent (agent) src_slot (integer)
29 Clone a genome. A new moniker is created.
31 void caosVM::c_GENE_CLON() {
32 VM_PARAM_INTEGER(src_slot
)
33 VM_PARAM_VALIDAGENT(src_agent
)
34 VM_PARAM_INTEGER(dest_slot
)
35 VM_PARAM_VALIDAGENT(dest_agent
)
41 GENE CROS (command) dest_agent (agent) dest_slot (integer) mum_agent (agent) mum_slot (integer) dad_agent (agent) dad_slot (integer) mum_mutation_chance (integer) mum_mutation_degree (integer) dad_mutation_chance (integer) dad_mutation_degree (integer)
44 Cross two genomes, creating a new one.
46 void caosVM::c_GENE_CROS() {
47 VM_PARAM_INTEGER(dad_mutation_degree
)
48 VM_PARAM_INTEGER(dad_mutation_chance
)
49 VM_PARAM_INTEGER(mum_mutation_degree
)
50 VM_PARAM_INTEGER(mum_mutation_chance
)
51 VM_PARAM_INTEGER(dad_slot
)
52 VM_PARAM_VALIDAGENT(dad_agent
)
53 VM_PARAM_INTEGER(mum_slot
)
54 VM_PARAM_VALIDAGENT(mum_agent
)
55 VM_PARAM_INTEGER(dest_slot
)
56 VM_PARAM_VALIDAGENT(dest_agent
)
62 GENE KILL (command) agent (agent) slot (integer)
65 Delete a genome from a slot.
67 void caosVM::c_GENE_KILL() {
68 VM_PARAM_INTEGER(slot
)
69 VM_PARAM_VALIDAGENT(agent
)
75 GENE LOAD (command) agent (agent) slot (integer) genefile (string)
78 Load a genome file into a slot. You can use * and ? wildcards in the filename.
80 void caosVM::c_GENE_LOAD() {
81 VM_PARAM_STRING(genefile
)
82 VM_PARAM_INTEGER(slot
)
83 VM_PARAM_VALIDAGENT(agent
)
85 shared_ptr
<genomeFile
> p
= world
.loadGenome(genefile
);
87 throw creaturesException("failed to find genome file '" + genefile
+ '"');
89 caos_assert(p
->getVersion() == 3);
91 agent
->slots
[slot
] = p
;
92 world
.newMoniker(p
, genefile
, agent
);
96 GENE MOVE (command) dest_agent (agent) dest_slot (integer) src_agent (agent) src_slot (integer)
99 Move a genome to another slot.
101 void caosVM::c_GENE_MOVE() {
102 VM_PARAM_INTEGER(src_slot
)
103 VM_PARAM_VALIDAGENT(src_agent
)
104 VM_PARAM_INTEGER(dest_slot
)
105 VM_PARAM_VALIDAGENT(dest_agent
)
107 std::map
<unsigned int, shared_ptr
<class genomeFile
> >::iterator i
= src_agent
->slots
.find(src_slot
);
108 caos_assert(i
!= src_agent
->slots
.end());
110 std::string moniker
= world
.history
.findMoniker(i
->second
);
111 assert(moniker
!= std::string("")); // internal consistency, i think..
113 dest_agent
->slots
[dest_slot
] = src_agent
->slots
[src_slot
];
114 src_agent
->slots
.erase(i
);
115 world
.history
.getMoniker(moniker
).moveToAgent(dest_agent
);
119 GTOS (string) slot (integer)
122 Return the moniker stored in the given gene slot of the target agent.
124 void caosVM::v_GTOS() {
125 VM_PARAM_INTEGER(slot
)
128 if (targ
->slots
.find(slot
) == targ
->slots
.end()) {
129 result
.setString(""); // CV needs this, at least
131 shared_ptr
<class genomeFile
> g
= targ
->slots
[slot
];
132 result
.setString(world
.history
.findMoniker(g
));
137 MTOA (agent) moniker (string)
140 Return the agent which has the given moniker stored in a gene slot, or NULL if none.
142 void caosVM::v_MTOA() {
143 VM_PARAM_STRING(moniker
)
145 caos_assert(world
.history
.hasMoniker(moniker
));
146 result
.setAgent(world
.history
.getMoniker(moniker
).owner
);
150 MTOC (agent) moniker (string)
153 Return the live creature with the given moniker, or NULL if none.
155 void caosVM::v_MTOC() {
156 VM_PARAM_STRING(moniker
)
159 if (!world
.history
.hasMoniker(moniker
)) return;
160 Agent
*a
= world
.history
.getMoniker(moniker
).owner
;
162 CreatureAgent
*c
= dynamic_cast<CreatureAgent
*>(a
);
163 assert(c
); // TODO: is this assert valid? can history events have non-creature owners?
168 NEW: GENE (command) mum (integer) dad (integer) destination (variable)
170 %pragma variants c1 c2
172 void caosVM::c_NEW_GENE() {
173 VM_PARAM_VARIABLE(destination
)
174 VM_PARAM_INTEGER(dad
)
175 VM_PARAM_INTEGER(mum
)
177 destination
->setInt(mum
); // TODO