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

Landslip.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 "Landslip.h"
00010 
00011 #include "Rules.h"
00012 #include "minmax.h"
00013 
00014 //-----------------------------------------------------------------
00015     Landslip::Landslip(const ModelList &models)
00016 : m_models(models)
00017 {
00018     m_impact = Cube::NONE;
00019     m_stoned = new bool[m_models.size()];
00020     memset(m_stoned, false, sizeof(bool) * m_models.size());
00021 }
00022 //-----------------------------------------------------------------
00023 Landslip::~Landslip()
00024 {
00025     delete[] m_stoned;
00026 }
00027 //-----------------------------------------------------------------
00028 /**
00029  * Indentify falling objects.
00030  * @return whether something is falling.
00031  */
00032     bool
00033 Landslip::computeFall()
00034 {
00035     while (m_models.stoneOn(this)) {
00036         /* empty */
00037     }
00038     return m_models.fallOn(this);
00039 }
00040 //-----------------------------------------------------------------
00041     bool
00042 Landslip::stoneModel(const Cube *model)
00043 {
00044     bool change = false;
00045     if (!isStoned(model)) {
00046         if (isFixed(model) || isOnPad(model)) {
00047             stone(model);
00048             change = true;
00049         }
00050     }
00051     return change;
00052 }
00053 //-----------------------------------------------------------------
00054     bool
00055 Landslip::isOnPad(const Cube *model) const
00056 {
00057     const Cube::t_models pad = model->const_rules()->getResist(Dir::DIR_DOWN);
00058     Cube::t_models::const_iterator end = pad.end();
00059     for (Cube::t_models::const_iterator i = pad.begin(); i != end; ++i) {
00060         if (isFixed(*i)) {
00061             return true;
00062         }
00063     }
00064     return false;
00065 }
00066 //-----------------------------------------------------------------
00067     bool
00068 Landslip::isFixed(const Cube *model) const
00069 {
00070     return isStoned(model) || model->isWall() ||
00071         model->isAlive() || model->isLost();
00072 }
00073 //-----------------------------------------------------------------
00074     bool
00075 Landslip::isStoned(const Cube *model) const
00076 {
00077     int index = model->getIndex();
00078     if (index > -1) {
00079         return m_stoned[index];
00080     }
00081     else {
00082         return true;
00083     }
00084 }
00085 //-----------------------------------------------------------------
00086     void
00087 Landslip::stone(const Cube *model)
00088 {
00089     int index = model->getIndex();
00090     if (index > -1) {
00091         m_stoned[index] = true;
00092     }
00093 }
00094 //-----------------------------------------------------------------
00095 /**
00096  * Let model to fall.
00097  * @return true when model is falling
00098  */
00099     bool
00100 Landslip::fallModel(Cube *model)
00101 {
00102     bool falling = false;
00103     if (!isFixed(model)) {
00104         model->rules()->actionFall();
00105         falling = true;
00106     }
00107     else {
00108         bool lastFall = model->rules()->clearLastFall();
00109         if (lastFall && m_impact < model->getWeight()) {
00110             m_impact = model->getWeight();
00111         }
00112     }
00113     return falling;
00114 }
00115 

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