00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "Cube.h"
00010
00011 #include "Shape.h"
00012 #include "Rules.h"
00013 #include "LayoutException.h"
00014 #include "Anim.h"
00015 #include "EffectDisintegrate.h"
00016 #include "DialogStack.h"
00017
00018
00019
00020
00021
00022 Cube::Cube(const V2 &location,
00023 eWeight weight, eWeight power, bool alive,
00024 Shape *new_shape)
00025 : m_loc(location), m_goal(Goal::noGoal())
00026 {
00027 m_index = -1;
00028 m_busy = false;
00029
00030 m_weight = weight;
00031 m_power = power;
00032 m_alive = alive;
00033 m_out = false;
00034 m_lookLeft = true;
00035 m_lost = false;
00036 m_outDir = Dir::DIR_NO;
00037 m_outCapacity = 0;
00038
00039 m_shape = new_shape;
00040 m_rules = new Rules(this);
00041 m_anim = new Anim();
00042 m_dialogs = NULL;
00043 }
00044
00045
00046
00047
00048 Cube::~Cube()
00049 {
00050
00051 delete m_rules;
00052 delete m_shape;
00053 delete m_anim;
00054 }
00055
00056
00057
00058
00059 void
00060 Cube::change_die()
00061 {
00062 m_alive = false;
00063 anim()->changeEffect(new EffectDisintegrate());
00064 }
00065
00066
00067
00068
00069 void
00070 Cube::change_goOut()
00071 {
00072 m_out = true;
00073 change_remove();
00074 }
00075
00076
00077
00078
00079 void
00080 Cube::change_remove()
00081 {
00082 m_lost = true;
00083 m_weight = NONE;
00084
00085 m_loc = V2(-1000, -1000);
00086 }
00087
00088 void
00089 Cube::change_turnSide()
00090 {
00091 m_lookLeft = !m_lookLeft;
00092 }
00093
00094 Dir::eDir
00095 Cube::getLastMoveDir() const
00096 {
00097 return m_rules->getDir();
00098 }
00099
00100 void
00101 Cube::setOutDir(Dir::eDir dir)
00102 {
00103 m_outCapacity = 2;
00104 m_outDir = dir;
00105 }
00106
00107
00108
00109
00110
00111 void
00112 Cube::decOutCapacity()
00113 {
00114 if (m_outCapacity > 0) {
00115 m_outCapacity--;
00116 if (m_outCapacity == 0) {
00117 m_outDir = Dir::DIR_NO;
00118 m_weight = LIGHT;
00119 }
00120 }
00121 }
00122
00123 bool
00124 Cube::isDisintegrated()
00125 {
00126 return m_anim->isDisintegrated();
00127 }
00128
00129 bool
00130 Cube::isInvisible()
00131 {
00132 return m_anim->isInvisible();
00133 }
00134
00135 bool
00136 Cube::isTalking() const
00137 {
00138 return (m_dialogs && m_dialogs->isTalking(m_index));
00139 }
00140
00141 std::string
00142 Cube::toString() const
00143 {
00144 return ExInfo("model")
00145 .addInfo("loc", m_loc.toString())
00146 .addInfo("alive", m_alive)
00147 .addInfo("weight", m_weight)
00148 .addInfo("power", m_power)
00149 .addInfo("shape", m_shape->toString()).info();
00150 }
00151
00152