11 if (filename.empty()) {
22 nodes.push_back(
Node::MakeNode(
"Please move into a green docking box and press d.", 0 ) );
28 nodes.push_back(
Node::MakeNode(
"Prepare To Be Searched. Maintain Speed and Course.", 0 ) );
34 vector< unsigned int >edges;
36 for (i = 0; i <
nodes.size()-13; i++)
38 for (i = 0; i <
nodes.size(); i++)
39 nodes[i].edges = edges;
47 return nodes.size()-16;
52 return nodes.size()-15;
57 return nodes.size()-14;
62 return nodes.size()-13;
67 return nodes.size()-12;
72 return nodes.size()-11;
77 return nodes.size()-10;
82 return nodes.size()-9;
87 return nodes.size()-8;
92 return nodes.size()-7;
97 return nodes.size()-6;
102 return nodes.size()-5;
107 return nodes.size()-1;
112 return nodes.size()-2;
117 return nodes.size()-3;
122 return nodes.size()-4;
125 static float sq(
float i )
147 unsigned int index = multiple+( (
unsigned int) sex )*messages.size();
148 if ( index < sounds.size() ) {
149 if (sounds[index] < 0) {
151 return sounds[
index];
153 return sounds[
index];
162 unsigned int index = ( (
unsigned int) sex )*messages.size();
164 for (
unsigned int i = index;
i < index+messages.size() &&
i < sounds.size(); ++
i)
175 for (
unsigned int i = 0;
i <
nodes.size(); ++
i)
176 if (
nodes[
i].StopSound( sex ) )
183 static std::string emptystr;
185 for (
int multiple = 0;; ++multiple) {
186 unsigned int index = ( (
unsigned int) sex )*messages.size()+multiple;
187 while ( index >= sounds.size() ) {
188 sounds.push_back( -1 );
189 soundfiles.push_back(emptystr);
192 if (soundfiles[index].empty()) {
193 soundfiles[
index] = soundfile;
197 GetSound(sex, multiple);
208 mood += -randomresponse+2*randomresponse*( (
float) rand() )/RAND_MAX;
212 float bestchoice = 4;
213 bool fitmood =
false;
214 for (
unsigned i = 0;
i < n->
edges.size();
i++) {
217 if ( (!fitmood) || newfitmood ) {
218 float newbestchoice =
sq( md-mood );
219 if ( (newbestchoice <= bestchoice) || (fitmood ==
false && newfitmood ==
true) )
220 if ( (newbestchoice == bestchoice && rand()%2) || newbestchoice < bestchoice ) {
222 fitmood = newfitmood;
224 bestchoice = newbestchoice;
229 vector< unsigned int >
g;
230 vector< unsigned int >
b;
232 "LowestPositiveCommChoice",
235 "LowestNegativeCommChoice",
237 for (
unsigned int i = 0;
i < n->
edges.size();
i++) {
244 if ( g.size() != 0 && ( relationship > 0 || (b.size() == 0) ) )
245 choice = g[( rand()%g.size() )];
247 choice = b[rand()%b.size()];
253 if (relationship < -1) relationship = -1;
254 if (relationship > 1) relationship = 1;
255 float mood = relationship;
256 float randomresponse = .01;
260 mood += -randomresponse+2*randomresponse*( (
float) rand() )/RAND_MAX;
263 float bestchoice = 16;
264 bool fitmood =
false;
265 for (
unsigned i = 0;
i < n->
edges.size();
i++) {
268 if ( (!fitmood) || newfitmood ) {
269 float newbestchoice =
sq( md-mood );
270 if ( (newbestchoice <= bestchoice) || (fitmood ==
false && newfitmood ==
true) ) {
271 if ( (newbestchoice == bestchoice && rand()%2) || newbestchoice < bestchoice ) {
273 fitmood = newfitmood;
275 bestchoice = newbestchoice;
280 return nodes[0].edges[choice];
285 std::string retval =
"\n";
286 if (
nodes.size() <= curstate) {
287 fprintf( stderr,
"Error with faction relationship due to %d not being in range of faction\n", curstate );
288 return "\n1. Transmit Error\n2. Transmit Error\n3. Transmit Error\n";
290 for (
unsigned int i = 0;
i <
nodes[curstate].edges.size();
i++)
292 static bool print_docking =
295 retval +=
"0. Request Docking Clearence";
301 if (
nodes.size() <= current_state) {
302 fprintf( stderr,
"Error with faction relationship due to %d not being in range of faction\n", current_state );
305 return nodes[current_state].messagedelta;
308 void CommunicationMessage::Init(
Unit *send,
Unit *
recv )
310 if (send == NULL)
return;
312 sender.SetUnit( send );
313 this->prevstate = this->curstate = fsm->getDefaultState( send->
getRelation( recv ) );
319 float j = floor( i );
333 void CommunicationMessage::SetAnimation( std::vector< Animation* > *ani,
unsigned char sex )
337 if (ani->size() > 0) {
338 float mood = fsm->getDeltaRelation( this->prevstate, this->curstate );
340 mood *= ( ani->size() )/.2;
342 if ( index >= ani->size() )
343 index = ani->size()-1;
344 this->ani = (*ani)[
index];
356 SetAnimation( ani, sex );
357 assert( this->curstate >= 0 );
363 std::vector< Animation* > *ani,
367 prevstate = fsm->getDefaultState( send->
getRelation( recv ) );
368 if ( fsm->nodes[prevstate].edges.size() ) {
369 this->edgenum = messagechoice%fsm->nodes[prevstate].edges.size();
370 curstate = fsm->nodes[prevstate].edges[this->edgenum];
372 SetAnimation( ani, sex );
373 assert( this->curstate >= 0 );
380 std::vector< Animation* > *ani,
384 prevstate = laststate;
385 curstate = thisstate;
386 SetAnimation( ani, sex );
387 assert( this->curstate >= 0 );
393 SetAnimation( ani, sex );
394 assert( this->curstate >= 0 );
401 std::vector< Animation* > *ani,
405 this->prevstate = prevstate.
curstate;
406 if ( fsm->nodes[this->prevstate].edges.size() ) {
407 this->edgenum = curstate%fsm->nodes[this->prevstate].edges.size();
408 this->curstate = fsm->nodes[this->prevstate].edges[edgenum];
410 SetAnimation( ani, sex );
411 assert( this->curstate >= 0 );