📄 aipemotion.cpp
字号:
//
// Subclasses may want to override this function, for efficiency
// reasons, if nothing else.
void aipCompEmotion::calc_compound () {
aipG g = aipNeutral;
aipEmotionItr itr = emotion_iterator();
for ( aipEmotion *e=itr.first(); e; e=itr.next() ) {
g += e->g();
}
aipEmotion::set_g(g); // compound emotion is sum of its aspects
}
//----------------------------------------------------------------------
// add_emotion - set the owning emotion
void aipCompEmotion::add_emotion (aipEmotion *x) {
x->set_owner_emotion(this);
aipEmotion::add_aspect(x);
calc_compound();
}
//----------------------------------------------------------------------
// set_g - works only if argument is aipNeutral
//
// If different behavior is required, override this function.
void aipCompEmotion::set_g (aipG x) {
if (x != aipNeutral) return;
aipEmotionItr itr = emotion_iterator();
for ( aipEmotion *e=itr.first(); e; e=itr.next() ) {
e->aipEmotion::set_g(aipNeutral);
}
aipEmotion::set_g(aipNeutral);
}
//----------------------------------------------------------------------
// post_msg_behavior - called after take_msg() is called for aspects
// The behavior apart from the aspects (emotion components).
//
// Subclasses may want to override this function, but in any case,
// calc_compound() must be called to set the emotion m_g.
void aipCompEmotion::post_msg_behavior (aipMsg *m) {
if (m) calc_compound();
}
//----------------------------------------------------------------------
// emotion_iterator
aipEmotionItr aipCompEmotion::emotion_iterator() const {
aipEmotionItr i(aspect_pandemonium());
return i;
}
//======================================================================
// aipFear - how bad something might be.
//
//----------------------------------------------------------------------
// dump_to_ptr
void aipFear::dump_to_ptr (char *p) const {
p[0] = 'f';
p[1] = ':';
aipEmotion::dump_to_ptr(p+2);
}
//======================================================================
// aipGreed - how good something is known to be.
//
//----------------------------------------------------------------------
// dump_to_ptr
void aipGreed::dump_to_ptr (char *p) const {
p[0] = 'g';
p[1] = ':';
aipEmotion::dump_to_ptr(p+2);
}
//======================================================================
// aipCuriosity - how good something unknown might be.
//
//----------------------------------------------------------------------
// dump_to_ptr
void aipCuriosity::dump_to_ptr (char *p) const {
p[0] = 'c';
p[1] = ':';
aipEmotion::dump_to_ptr(p+2);
}
//======================================================================
// aipHope - fear plus greed plus curiosity
//
//----------------------------------------------------------------------
// Constructor
//
// This requires no further initialization - by default, emotions
// are created with a goodness of aipNeutral.
aipHope::aipHope () {
m_fear = new aipFear;
m_greed = new aipGreed;
m_curiosity = new aipCuriosity;
if (m_fear && m_greed && m_curiosity) {
add_emotion (m_fear);
add_emotion (m_greed);
add_emotion (m_curiosity);
}
}
//----------------------------------------------------------------------
// enable_slowly_degrade
void aipHope::enable_slowly_degrade () {
if (m_fear) m_fear->enable_slowly_degrade();
if (m_greed) m_greed->enable_slowly_degrade();
if (m_curiosity) m_curiosity->enable_slowly_degrade();
}
//----------------------------------------------------------------------
// disable_slowly_degrade
void aipHope::disable_slowly_degrade () {
if (m_fear) m_fear->disable_slowly_degrade();
if (m_greed) m_greed->disable_slowly_degrade();
if (m_curiosity) m_curiosity->disable_slowly_degrade();
}
//----------------------------------------------------------------------
// dump_to_ptr
void aipHope::dump_to_ptr (char *p) const {
strcpy (p, "h(fgc)(");
long len = strlen(p);
m_fear->aipEmotion::dump_to_ptr(p+len);
strcat (p, ",");
len = strlen(p);
m_greed->aipEmotion::dump_to_ptr(p+len);
strcat (p, ",");
len = strlen(p);
m_curiosity->aipEmotion::dump_to_ptr(p+len);
strcat (p, ")");
}
//----------------------------------------------------------------------
// set_g - set the goodness of this compound emotion
void aipHope::set_g (aipG x) {
if (x != aipNeutral) return;
if (!m_fear || !m_greed || !m_curiosity) return;
m_fear->set_g (aipNeutral);
m_greed->set_g (aipNeutral);
m_curiosity->set_g (aipNeutral);
aipEmotion::set_g (aipNeutral);
}
//----------------------------------------------------------------------
// post_msg_behavior - called after take_msg() is called for aspects
//
// This function does the same thing as the one it is overriding,
// aipCompEmotion::post_msg_behavior(), but it is faster because
// we already have pointers to all the aspect-emotions.
void aipHope::post_msg_behavior (aipMsg *m) {
if (!m_fear || !m_greed || !m_curiosity) return;
if (m) calc_compound();
}
//----------------------------------------------------------------------
// set_fear
void aipHope::set_fear (aipG x) {
m_fear->set_g(x);
calc_compound();
}
//----------------------------------------------------------------------
// set_greed
void aipHope::set_greed (aipG x) {
m_greed->set_g(x);
calc_compound();
}
//----------------------------------------------------------------------
// set_curiosity
void aipHope::set_curiosity (aipG x) {
m_curiosity->set_g(x);
calc_compound();
}
//======================================================================
// aipAspectItr - Aspect iterator
//
// All function bodies are in the header file
//
//======================================================================
// aipEmotionItr - Emotion iterator
//
// All function bodies are in the header file
//
//======================================================================
// License
//
// Permission is hereby granted, free of charge, to any
// person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to
// whom the Software is furnished to do so, subject to the
// following conditions:
//
// The copyright notice and this license shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
//
//**********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -