1 /*
2 * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "Cube.h"
10
11 #include "Shape.h"
12 #include "Rules.h"
13 #include "LayoutException.h"
14 #include "Anim.h"
15 #include "EffectDisintegrate.h"
16 #include "DialogStack.h"
17
18 //-----------------------------------------------------------------
19 /**
20 * Create new model.
21 */
Cube(const V2 & location,eWeight weight,eWeight power,bool alive,Shape * new_shape)22 Cube::Cube(const V2 &location,
23 eWeight weight, eWeight power, bool alive,
24 Shape *new_shape)
25 : m_loc(location), m_goal(Goal::noGoal())
26 {
27 m_index = -1;
28 m_busy = false;
29
30 m_weight = weight;
31 m_power = power;
32 m_alive = alive;
33 m_out = false;
34 m_lookLeft = true;
35 m_lost = false;
36 m_outDir = Dir::DIR_NO;
37 m_outCapacity = 0;
38
39 m_shape = new_shape;
40 m_rules = new Rules(this);
41 m_anim = new Anim();
42 m_dialogs = NULL;
43 }
44 //-----------------------------------------------------------------
45 /**
46 * Delete all member but not field.
47 */
~Cube()48 Cube::~Cube()
49 {
50 //NOTE: rules must be destroyed before shape because they unmask self
51 delete m_rules;
52 delete m_shape;
53 delete m_anim;
54 }
55 //-----------------------------------------------------------------
56 /**
57 * Die.
58 */
59 void
change_die()60 Cube::change_die()
61 {
62 m_alive = false;
63 anim()->changeEffect(new EffectDisintegrate());
64 }
65 //-----------------------------------------------------------------
66 /**
67 * Make the object unmovable
68 * when it is going out of the room.
69 */
70 void
change_goingOut()71 Cube::change_goingOut()
72 {
73 m_weight = Cube::FIXED;
74 }
75 //-----------------------------------------------------------------
76 /**
77 * Go out of room.
78 */
79 void
change_goOut()80 Cube::change_goOut()
81 {
82 m_out = true;
83 change_remove();
84 }
85 //-----------------------------------------------------------------
86 /**
87 * Go out of game, e.g. disintegrated skeleton.
88 */
89 void
change_remove()90 Cube::change_remove()
91 {
92 m_lost = true;
93 m_weight = NONE;
94 //NOTE: hack, object is moved out
95 m_loc = V2(-1000, -1000);
96 }
97 //-----------------------------------------------------------------
98 void
change_turnSide()99 Cube::change_turnSide()
100 {
101 m_lookLeft = !m_lookLeft;
102 }
103 //-----------------------------------------------------------------
104 Dir::eDir
getLastMoveDir() const105 Cube::getLastMoveDir() const
106 {
107 return m_rules->getDir();
108 }
109 //-----------------------------------------------------------------
110 /**
111 * Set params for special 'output_DIR' model.
112 * Used just for the 'spuntik' in windoze level.
113 */
114 void
setOutDir(Dir::eDir dir,int capacity,eWeight weight)115 Cube::setOutDir(Dir::eDir dir, int capacity, eWeight weight)
116 {
117 m_outCapacity = capacity;
118 m_outDir = dir;
119 m_weight = weight;
120 }
121 //-----------------------------------------------------------------
122 /**
123 * Set extra parameters from a saved undo state.
124 * They have to restore just the parameters used by the View.
125 */
126 void
setExtraParams()127 Cube::setExtraParams()
128 {
129 m_lost = false;
130 m_rules->resetLastDir();
131 }
132 //-----------------------------------------------------------------
133 /**
134 * Special model 'output_DIR' has capacity to absorb two fishes,
135 * then it changes to normal 'item_light'.
136 */
137 void
decOutCapacity()138 Cube::decOutCapacity()
139 {
140 if (m_outCapacity > 0) {
141 m_outCapacity--;
142 if (m_outCapacity == 0) {
143 m_outDir = Dir::DIR_NO;
144 m_weight = LIGHT;
145 m_outCapacity = -1;
146 }
147 }
148 }
149 //-----------------------------------------------------------------
150 bool
isDisintegrated()151 Cube::isDisintegrated()
152 {
153 return m_anim->isDisintegrated();
154 }
155 //-----------------------------------------------------------------
156 bool
isInvisible()157 Cube::isInvisible()
158 {
159 return m_anim->isInvisible();
160 }
161 //-----------------------------------------------------------------
162 bool
isTalking() const163 Cube::isTalking() const
164 {
165 return (m_dialogs && m_dialogs->isTalking(m_index));
166 }
167 //-----------------------------------------------------------------
168 std::string
toString() const169 Cube::toString() const
170 {
171 return ExInfo("model")
172 .addInfo("loc", m_loc.toString())
173 .addInfo("alive", m_alive)
174 .addInfo("weight", m_weight)
175 .addInfo("power", m_power)
176 .addInfo("shape", m_shape->toString()).info();
177 }
178
179
180