#include <City.h>
Inheritance diagram for City:


Public Methods | |
| City (const Vec3D &location, Player *owner=0) | |
| virtual | ~City (void) |
| virtual void | draw (void) const |
| void | drawSelectBox () const |
| If the city is selected, draw a box around to indicate its selected. | |
| void | update (void) |
| Updates the production of the city. This function should be called for each city every game tick. | |
| bool | contains (Vec2D that) const |
| Vec3D | position (void) const |
| The position of the city. | |
| Player * | owner (void) const |
| The owner of the city. | |
| Vec3D | color (void) const |
| the team color of the city | |
| void | changeOwner (Player *newOwner, bool taunting=false) |
| Changes the owner of the city. | |
| bool | collision (const MilitaryUnit *unit) const |
| Returns true if the given unit touches the city. | |
| void | setRallyPoint (Vec3D rallyPoint) |
| Sets the rallypoint, the place where units that are built gather. | |
| Vec3D & | rallyPoint () |
| Returns the rallypoint of this city. | |
| void | trainUnit (int type) |
| If the owners funds allow it, train a unit of the given type. | |
| const deque< int > & | trainees () const |
| returns a view of the unit training queue | |
| int | trainingTimeLeft () const |
| time left to train the current unit in game ticks | |
| int | timeUntilFinishEconUpgrade () |
| will be -1 if not upgrading, otherwise returns time in sec | |
| int | econLevel () |
| void | upgradeEcon () |
| if fund allows, start upgrading econ 1 level | |
| void | addJetGaurd () |
| void | deleteJetGuard () |
| int | jetGaurdSize () |
| virtual unsigned int | uniqueID (void) const |
Private Methods | |
| void | startEconUpgrade (int secToComplete) |
| start upgrading its economy. will complete in specified seconds | |
Private Attributes | |
| Vec3D | m_size |
| Vec3D | m_position |
| Player * | m_pOwner |
| Vec3D | m_color |
| Vec3D | m_rallyPoint |
| deque< int > | m_trainees |
| int | m_timer |
| int | m_currUnitType |
| DWORD | m_timeOfLastDeposit |
| int | m_econLevel |
| int | m_econRemainingTime |
| int | m_jetGaurdSize |
|
||||||||||||
|
Definition at line 41 of file City.cpp. References Vec3D.
00041 : 00042 m_size(Vec3D(15.0f, 15.0f, 15.0)), 00043 m_position(location), 00044 m_color( (theOwner ? theOwner->color() : Globals::NO_OWNER) ), 00045 m_rallyPoint(location), 00046 m_trainees(), 00047 m_timer(-1), 00048 m_currUnitType(-1), 00049 m_pOwner(theOwner), 00050 m_timeOfLastDeposit(-5000), // so that at the 1st game tick, everyone get exactly 1 deposit 00051 // regardless of how long the game has been spinning before host starts 00052 m_econLevel(1), 00053 m_econRemainingTime(-1), 00054 m_jetGaurdSize(0) 00055 { 00056 } |
|
|
Definition at line 58 of file City.cpp.
00059 {
00060 }
|
|
|
Definition at line 307 of file City.cpp. References m_jetGaurdSize. Referenced by Jet::Jet().
00307 { ++m_jetGaurdSize; }
|
|
||||||||||||
|
Changes the owner of the city.
Definition at line 218 of file City.cpp. References color(), Player::color(), Overhead::deleteMilitaryUnit(), m_color, m_pOwner, GameState::messagesReceived(), Helper::playerColorToPlayerName(), sys_randInt(), UniqueID::uniqueID(), and GameState::units().
00219 {
00220 Player* preOwner = m_pOwner;
00221 m_pOwner = newOwner;
00222 m_color = m_pOwner->color();
00223 //m_jetGaurdSize = 0;
00224 vector<MilitaryUnit*> toDelete;
00225 for(UnitIter unitIter(GameState::units().begin()); unitIter != GameState::units().end(); ++unitIter)
00226 {
00227 if ((*unitIter)->unitType() == UnitTypes::JET)
00228 {
00229 if ((*unitIter)->color() != this->color() && dynamic_cast<Jet*>((*unitIter))->getCityID() == this->uniqueID())
00230 {
00231 toDelete.push_back(*unitIter);
00232 }
00233 }
00234 }
00235 for(UnitIter unitIter(toDelete.begin()); unitIter != toDelete.end(); ++unitIter)
00236 {
00237 Overhead::deleteMilitaryUnit(*unitIter);
00238 }
00239 if (taunting && preOwner)
00240 {
00241 Overhead::battleCircleAnimation.push_back( BattleSprite(this->position(), 60, BattleSpriteTypes::EXPLO_LARGE));
00242 Overhead::battleCircleAnimation.push_back( BattleSprite(this->position(), 100, BattleSpriteTypes::SMOKE_LARGE));
00243 stringstream sstr;
00244 if (preOwner->color() == Colors::white)
00245 {
00246 sstr << Helper::playerColorToPlayerName(newOwner->color()) << " took over a neutral city";
00247 } else
00248 {
00249 sstr << Helper::playerColorToPlayerName(newOwner->color()) << " says: ";
00250 switch (sys_randInt() % 4)
00251 {
00252 case 0:
00253 sstr << "I took over " << Helper::playerColorToPlayerName(preOwner->color()) << "'s city!";
00254 break;
00255 case 1:
00256 sstr << "Another city mine! " << Helper::playerColorToPlayerName(preOwner->color()) << " is taking a woopin";
00257 break;
00258 case 2:
00259 sstr << "Another city mine! " << Helper::playerColorToPlayerName(preOwner->color()) << " is getting a butt woopin";
00260 break;
00261 case 3:
00262 sstr << "Some people are destined to loose! City's mine";
00263 break;
00264 default:
00265 break;
00266 }
00267 }
00268 GameState::messagesReceived().addMessage(sstr.str());
00269 }
00270 }
|
|
|
Returns true if the given unit touches the city.
Definition at line 272 of file City.cpp. References citySize(), m_position, and MilitaryUnit::position().
00273 {
00274 return ((this->m_position.x + citySize.x > unit->position().x) &&
00275 (this->m_position.x - citySize.x < unit->position().x) &&
00276 (this->m_position.y + citySize.y > unit->position().y) &&
00277 (this->m_position.y - citySize.y < unit->position().y));
00278 }
|
|
|
the team color of the city
Definition at line 213 of file City.cpp. References m_color, and Vec3D. Referenced by changeOwner(), AI::Player::IsNeutralCity::operator()(), trainUnit(), and Overhead::updateBattleEntries().
00214 {
00215 return m_color;
00216 }
|
|
|
if the 2D point is 'roughly' inside the city Definition at line 197 of file City.cpp. References math_dist2D(), math_translateWorldToScreen(), and Vec2D.
00198 {
00199 Vec2D city2Dpos( math_translateWorldToScreen(m_position) );
00200 return math_dist2D( city2Dpos,that ) < 0.07f;
00201 }
|
|
|
Definition at line 309 of file City.cpp. References m_jetGaurdSize, sys_console(), sys_flushConsole(), and Globals::WARNING(). Referenced by Jet::goal(), and Jet::~Jet().
00310 {
00311 if (!(--m_jetGaurdSize >= 0))
00312 {
00313 sys_console() << WARNING << "!(--m_jetGaurdSize >= 0)" << endl;
00314 sys_flushConsole();
00315 }
00316 }
|
|
|
Draws the object at its current location. Implements DrawableObject. Definition at line 62 of file City.cpp. References Globals::artWork, mesh_render(), and Vec3D.
00063 {
00064 using namespace Globals;
00065 mesh_render( artWork->city_mesh, this->m_position, citySize, Vec3D(0.0f,90.0f,0.0f), artWork->city_texture, 0, this->color() );
00066 }
|
|
|
If the city is selected, draw a box around to indicate its selected.
Definition at line 68 of file City.cpp. References Globals::artWork, m_position, math_translateWorldToScreen(), mesh_render(), overlay_line(), overlay_text(), overlay_textOut(), Vec2D, and Vec3D. Referenced by Overhead::overheadRender().
00069 {
00070 Vec3D pos = m_position;
00071 pos.z += 1.2f;
00072 FLOAT angle = (FLOAT)( (Globals::currGameTick*5) % 360 );
00073 mesh_render( artWork->circle, pos, Vec3D(13.0f,13.0f,0.001f), Vec3D(angle,0,0), artWork->colorGreen );
00074
00075 // also draw the rally point
00076 Vec2D screenPoint = math_translateWorldToScreen(this->m_position + Vec3D(0.0f,0.0f,0.0f));
00077 Vec2D rp = math_translateWorldToScreen(m_rallyPoint);
00078 overlay_line(screenPoint, rp, Colors::red);
00080 overlay_text() << "Rally Point";
00081 overlay_textOut(rp, 1.0f, Colors::red);
00082 }
|
|
|
Definition at line 96 of file City.cpp. References m_econLevel. Referenced by HUD::render().
00097 {
00098 return m_econLevel;
00099 }
|
|
|
Definition at line 318 of file City.cpp. References m_jetGaurdSize. Referenced by Jet::Jet().
00318 { return m_jetGaurdSize; }
|
|
|
The owner of the city.
Definition at line 208 of file City.cpp. References m_pOwner.
00209 {
00210 return this->m_pOwner;
00211 }
|
|
|
The position of the city.
Definition at line 203 of file City.cpp. References m_position, and Vec3D. Referenced by AI::Player::CityLessThreatened::operator()(), Overhead::overhead_init(), AI::Player::sendUnitsToCity(), and Overhead::updateBattleEntries().
00204 {
00205 return m_position;
00206 }
|
|
|
Returns the rallypoint of this city.
Definition at line 282 of file City.cpp. References m_rallyPoint, and Vec3D.
00282 { return m_rallyPoint; }
|
|
|
Sets the rallypoint, the place where units that are built gather.
Definition at line 280 of file City.cpp. References m_rallyPoint. Referenced by NetworkSubsystem::processNetworkData().
00280 { m_rallyPoint = rp; }
|
|
|
start upgrading its economy. will complete in specified seconds
Definition at line 85 of file City.cpp. References m_econRemainingTime. Referenced by upgradeEcon().
00086 {
00087 m_econRemainingTime = 62*secToComplete;
00088 }
|
|
|
will be -1 if not upgrading, otherwise returns time in sec
Definition at line 90 of file City.cpp. References m_econRemainingTime. Referenced by HUD::render().
00091 {
00092 if( m_econRemainingTime==-1 ) return -1;
00093 return m_econRemainingTime / 62;
00094 }
|
|
|
returns a view of the unit training queue
Definition at line 303 of file City.cpp. References m_trainees. Referenced by HUD::render().
00303 { return m_trainees; }
|
|
|
time left to train the current unit in game ticks
Definition at line 305 of file City.cpp. References m_timer. Referenced by HUD::render().
00305 { return m_timer; }
|
|
|
If the owners funds allow it, train a unit of the given type.
Definition at line 284 of file City.cpp. References Player::bank(), Player::color(), color(), GameState::consolePlayer(), m_pOwner, m_trainees, Globals::MAX_UNITS_FOR_EACH_PLAYER(), GameState::messagesReceived(), Helper::totalUnitsBeingBuiltForPlayer(), Helper::totalUnitsForPlayer(), and Bank::withdraw(). Referenced by NetworkSubsystem::processNetworkData().
00285 {
00286 if( !m_pOwner ) return; // can't train unit from a neutral city
00287 if( m_pOwner->bank().withdraw(EconData::getObj().unitAmount(type)) )
00288 {
00289 if ((Helper::totalUnitsForPlayer(this->color()) + Helper::totalUnitsBeingBuiltForPlayer(this->color())) < MAX_UNITS_FOR_EACH_PLAYER)
00290 {
00291 m_trainees.push_back(type);
00292 } else
00293 {
00294 GameState::messagesReceived().addMessage("Cannot Build: Max unit limit reached");
00295 }
00296 } else if (this->color() == GameState::consolePlayer()->color())
00297 {
00298 GameState::messagesReceived().addMessage("Cannot Build: Not enough funds");
00299 }
00300
00301 }
|
|
|
Definition at line 31 of file UniqueID.cpp. References UniqueID::m_uniqueID. Referenced by changeOwner(), BattleEntry::inputIssueGroupCommand(), BattleEntry::inputIssueJetsCommand(), Overhead::processOverheadInput(), HUD::processOverheadInput(), sendReinforcement(), and update().
00032 {
00033 return m_uniqueID;
00034 }
|
|
|
Updates the production of the city. This function should be called for each city every game tick.
Definition at line 111 of file City.cpp. References GameState::addMilitaryUnit(), Globals::artWork, Player::bank(), Player::color(), GameState::consolePlayer(), Bank::deposit(), EconData::depositInterval(), EconData::depositPerCity(), DWORD, Singleton< EconData >::getObj(), MilitaryUnit::goal(), m_color, m_currUnitType, m_econLevel, m_econRemainingTime, m_position, m_pOwner, m_timeOfLastDeposit, m_timer, m_trainees, Sound::playRandomSound(), sys_console(), terrain_getHeight(), UniqueID::uniqueID(), and EconData::unitTrainingTime().
00112 {
00113 m_position.z = terrain_getHeight( artWork->worldMap, m_position.x, m_position.y );
00114
00115 DWORD currTime = Globals::currGameTick;
00116 if( m_pOwner && (currTime - m_timeOfLastDeposit >= EconData::getObj().depositInterval()) )
00117 {
00118 m_pOwner->bank().deposit(Helper::maintenanceMultiplier(this->color(), EconData::getObj().depositPerCity(m_econLevel)));
00119 m_timeOfLastDeposit = currTime;
00120 }
00121
00122 // check econ upgrades
00123 if(m_econRemainingTime>-1) m_econRemainingTime--;
00124 if( m_econRemainingTime==0 )
00125 {
00126 m_econRemainingTime = -1;
00127 if( m_econLevel<5 ) m_econLevel++;
00128 }
00129
00130 // check timers for unit building
00131 if(m_timer > 0) --m_timer;
00132 else if (m_timer == 0)
00133 {
00134 // only play sounds if the unit being created is on the console players team
00135 switch(m_currUnitType)
00136 {
00137 case UnitTypes::LIGHT_TANK:
00138 {
00139 MilitaryUnit* mu = new LightTank(m_position, m_pOwner, DEFAULT_LIGHT_TANK_SIZE);
00140 mu->goal(m_rallyPoint);
00141 GameState::addMilitaryUnit(mu);
00142 if(m_color == GameState::consolePlayer()->color())
00143 Sound::playRandomSound(Sound::CLASS_CREATE_LT);
00144 break;
00145 }
00146 case UnitTypes::HEAVY_TANK:
00147 {
00148 MilitaryUnit* mu = new HeavyTank(m_position, m_pOwner, DEFAULT_HEAVY_TANK_SIZE);
00149 mu->goal(m_rallyPoint);
00150 GameState::addMilitaryUnit(mu);
00151 if(m_color == GameState::consolePlayer()->color())
00152 Sound::playRandomSound(Sound::CLASS_CREATE_HT);
00153 break;
00154 }
00155 case UnitTypes::LAUNCHER:
00156 {
00157 MilitaryUnit* mu = new RocketLauncher(m_position, m_pOwner, DEFAULT_ROCKET_LAUNCHER_SIZE);
00158 mu->goal(m_rallyPoint);
00159 GameState::addMilitaryUnit(mu);
00160 if(m_color == GameState::consolePlayer()->color())
00161 Sound::playRandomSound(Sound::CLASS_CREATE_RT);
00162 }
00163 break;
00164 case UnitTypes::ARTILLERY:
00165 {
00166 MilitaryUnit* mu = new Artillery(m_position, m_pOwner, DEFAULT_ARTILLERY_SIZE);
00167 mu->goal(m_rallyPoint);
00168 GameState::addMilitaryUnit(mu);
00169 if(m_color == GameState::consolePlayer()->color())
00170 Sound::playRandomSound(Sound::CLASS_CREATE_AR);
00171 break;
00172 }
00173 case UnitTypes::JET:
00174 {
00175 MilitaryUnit* mu = new Jet(m_position, m_pOwner, 12, (int)uniqueID() );
00176 GameState::addMilitaryUnit(mu);
00177 if(m_color == GameState::consolePlayer()->color())
00178 Sound::playRandomSound(Sound::CLASS_CREATE_JT);
00179 break;
00180 }
00181 default:
00182 sys_console() << "Warning! Invalid unit given as UnitType when trying to have a city build a new unit. Type:"
00183 << m_currUnitType << endl;
00184 }
00185 // so that we train the next unit
00186 m_trainees.pop_front();
00187 --m_timer;
00188 }
00189 else if( !m_trainees.empty() )
00190 {
00191 m_currUnitType = m_trainees.front();
00192 m_timer = EconData::getObj().unitTrainingTime(m_currUnitType);
00193 }
00194
00195 }
|
|
|
if fund allows, start upgrading econ 1 level
Definition at line 101 of file City.cpp. References Player::bank(), m_econRemainingTime, m_pOwner, startEconUpgrade(), and Bank::withdraw(). Referenced by NetworkSubsystem::processNetworkData().
00102 {
00103 if( !m_pOwner ) return; // can't train unit from a neutral city
00104 if( m_econRemainingTime!=-1 ) return; // already upgrading
00105 if( m_pOwner->bank().withdraw(EconData::getObj().econUpgradeCost(m_econLevel)) )
00106 {
00107 startEconUpgrade( EconData::getObj().econUpgradeTime(m_econLevel) );
00108 }
00109 }
|
|
|
Definition at line 89 of file City.h. Referenced by changeOwner(), color(), and update(). |
|
|
Definition at line 93 of file City.h. Referenced by update(). |
|
|
Definition at line 95 of file City.h. Referenced by econLevel(), and update(). |
|
|
Definition at line 96 of file City.h. Referenced by startEconUpgrade(), timeUntilFinishEconUpgrade(), update(), and upgradeEcon(). |
|
|
Definition at line 99 of file City.h. Referenced by addJetGaurd(), deleteJetGuard(), and jetGaurdSize(). |
|
|
Definition at line 87 of file City.h. Referenced by collision(), drawSelectBox(), position(), and update(). |
|
|
Definition at line 88 of file City.h. Referenced by changeOwner(), owner(), trainUnit(), update(), and upgradeEcon(). |
|
|
Definition at line 90 of file City.h. Referenced by rallyPoint(), and setRallyPoint(). |
|
|
|
|
|
Definition at line 94 of file City.h. Referenced by update(). |
|
|
Definition at line 92 of file City.h. Referenced by trainingTimeLeft(), and update(). |
|
|
Definition at line 91 of file City.h. Referenced by trainees(), trainUnit(), and update(). |
1.3-rc2