Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / assoc_mem / brain.cpp
blobc9665174f38c761e5644ac4f40c31301df94f1d9
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "brain.h"
19 CBrain::CBrain(float f,float a,float e,float ha,float hu) : CMood(f,a,e,ha,hu)
21 _UpdateEvery = 0;
24 CBrain::CBrain(CMood &personality) : CMood(personality)
26 _UpdateEvery = 0;
29 CBrain::CBrain(const CBrain &c) : CMood()
31 _Personality = c._Personality;
32 _RealTime = c._RealTime;
33 _UpdateEvery = c._UpdateEvery;
34 _LastUpdate = c._LastUpdate;
37 void CBrain::setUpdateEvery(int nb_cycles)
39 _UpdateEvery = nb_cycles;
42 float CBrain::getFear()
44 if ( _Personality.getFear() > _RealTime.getFear() )
45 return _Personality.getFear();
46 else
47 return _RealTime.getFear();
50 float CBrain::getAgressivity()
52 if ( _Personality.getAgressivity() > _RealTime.getAgressivity() )
53 return _Personality.getAgressivity();
54 else
55 return _RealTime.getAgressivity();
58 float CBrain::getEmpathy()
60 if ( _Personality.getEmpathy() > _RealTime.getEmpathy() )
61 return _Personality.getEmpathy();
62 else
63 return _RealTime.getEmpathy();
66 float CBrain::getHappiness()
68 if ( _Personality.getHappiness() > _RealTime.getHappiness() )
69 return _Personality.getHappiness();
70 else
71 return _RealTime.getHappiness();
75 float CBrain::getHunger()
77 if ( _Personality.getHunger() > _RealTime.getHunger() )
78 return _Personality.getHunger();
79 else
80 return _RealTime.getHunger();
83 void CBrain::setInput(CRecord *input)
85 std::vector<CTree *>::iterator it_t = _Trees.begin();
86 while ( it_t != _Trees.end() )
88 (*it_t)->getOutput( input );
89 it_t++;
94 void CBrain::addField(CField *field)
96 _Fields.push_back( field );
99 void CBrain::addTree(CTree *tree)
101 _Trees.push_back( tree );
104 std::vector<std::string> CBrain::getOutputs()
106 std::vector<std::string> outputs;
107 std::vector<CTree *>::iterator it_t = _Trees.begin();
108 while ( it_t != _Trees.end() )
110 outputs.push_back( _Fields[ (*it_t)->getKey() ]->getName() );
111 it_t++;
113 return outputs;
116 void CBrain::build()
118 std::vector<CTree *>::iterator it_tree = _Trees.begin();
119 while ( it_tree != _Trees.end() )
121 (*it_tree)->rebuild( _Records, _Fields );
122 it_tree++;
124 _LastUpdate = 0;
127 std::string CBrain::getDebugString()
129 std::string debug_string;
130 std::vector<CTree *>::iterator it_tree = _Trees.begin();
131 while ( it_tree != _Trees.end() )
133 debug_string += (*it_tree)->getDebugString( _Records, _Fields );
134 debug_string += "\n";
135 it_tree++;
137 return debug_string;
140 void CBrain::forget()
142 while ( !_Records.empty() )
144 delete _Records.front();
145 _Records.erase( _Records.begin() );
149 void CBrain::addRecord(CRecord *record)
151 _Records.push_back( record );
152 _LastUpdate++;
153 if ( _LastUpdate > _UpdateEvery )
154 build();