Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

Cube.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
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  * Create new model.
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  * Delete all member but not field.
00047  */
00048 Cube::~Cube()
00049 {
00050     //NOTE: rules must be destroyed before shape because they unmask self
00051     delete m_rules;
00052     delete m_shape;
00053     delete m_anim;
00054 }
00055 //-----------------------------------------------------------------
00056 /**
00057  * Die.
00058  */
00059     void
00060 Cube::change_die()
00061 {
00062     m_alive = false;
00063     anim()->changeEffect(new EffectDisintegrate());
00064 }
00065 //-----------------------------------------------------------------
00066 /**
00067  * Go out of room.
00068  */
00069     void
00070 Cube::change_goOut()
00071 {
00072     m_out = true;
00073     change_remove();
00074 }
00075 //-----------------------------------------------------------------
00076 /**
00077  * Go out of game, e.g. disintegrated skeleton.
00078  */
00079     void
00080 Cube::change_remove()
00081 {
00082     m_lost = true;
00083     m_weight = NONE;
00084     //NOTE: hack, object is moved out
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  * Special model 'output_DIR' has capacity to absorb two fishes,
00109  * then it changes to normal 'item_light'.
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 

Generated on Wed Jun 1 09:54:30 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2