--- gWinZone.cpp 2009-02-27 11:31:36.000000000 -0600 +++ zFortress.cpp 2009-02-27 11:35:21.000000000 -0600 @@ -27,29 +27,34 @@ #include "rSDL.h" -#include "gWinZone.h" #include "eFloor.h" #include "eTimer.h" #include "eGrid.h" #include "gCycle.h" #include "gGame.h" +#include "gParser.h" #include "eTeam.h" #include "ePlayer.h" #include "rRender.h" #include "nConfig.h" #include "tString.h" +#include "tPolynomial.h" #include "rScreen.h" #include "eSoundMixer.h" +#include "zone/zFortress.h" +#include "zone/zZone.h" + #include #include #include #include -#include "nProtoBuf.h" -#include "gZone.pb.h" -// ======= Bunch of generic gZone stuff, including settings ======= +#define sg_segments sz_zoneSegments +#define gZone zZone +#define gBaseZoneHack zFortressZone + // ******************************************************************************* // * @@ -58,12 +63,11 @@ // ******************************************************************************* //! //! @param grid Grid to put the zone into -//! @param pos Position to spawn the zone at //! // ******************************************************************************* -gBaseZoneHack::gBaseZoneHack( eGrid * grid, const eCoord & pos ) - :gZone( grid, pos), onlySurvivor_( false ), currentState_( State_Safe ) +gBaseZoneHack::gBaseZoneHack( eGrid * grid ) + :gZone( grid ), onlySurvivor_( false ), currentState_( State_Safe ) { enemiesInside_ = ownersInside_ = 0; conquered_ = 0; @@ -71,8 +75,6 @@ teamDistance_ = 0; lastEnemyContact_ = se_GameTime(); touchy_ = false; - - color_.r_ = color_.g_ = color_.b_ = 0; } // ******************************************************************************* @@ -120,6 +122,17 @@ static int sg_baseZonesPerTeam = 0; static tSettingItem< int > sg_baseZonesPerTeamConfig( "FORTRESS_MAX_PER_TEAM", sg_baseZonesPerTeam ); +void gBaseZoneHack::setupVisuals(gParser::State_t & state) +{ + REAL tpR[] = {.0f, .3f}; + tPolynomial tpr(tpR, 2); + state.set("rotation", tpr); +} + +void gBaseZoneHack::readXML(tXmlParser::node const & node) +{ +} + // count zones belonging to the given team. // fill in count and the zone that is farthest to the team. void gBaseZoneHack::CountZonesOfTeam( eGrid const * grid, eTeam * otherTeam, int & count, gBaseZoneHack * & farthest ) @@ -169,35 +182,54 @@ if ( currentState_ == State_Conquering ) { + if (shape) + { // let zone vanish - SetReferenceTime(); + shape->setReferenceTime(lastTime); // let it light up in agony if ( sg_collapseSpeed < .4 ) { + rColor color_ = shape->getColor(); color_.r_ = color_.g_ = color_.b_ = 1; + shape->setColor(color_); } - SetExpansionSpeed( -GetRadius()*sg_collapseSpeed ); - SetRotationAcceleration( -GetRotationSpeed()*.4 ); - RequestSync(); + shape->collapse( sg_collapseSpeed ); + shape->SetRotationAcceleration( -shape->GetRotationSpeed()*.4 ); + shape->RequestSync(); + + } + else + OnVanish(); currentState_ = State_Conquered; } - else if ( currentState_ == State_Conquered && GetRotationSpeed() < 0 ) + else if ( currentState_ == State_Conquered && ( !shape || shape->GetRotationSpeed() < 0 ) ) + { + if (shape) { + // FIXME: Why does Zones v1 *not* do this, and should we? + // let zone vanish - SetReferenceTime(); - SetRotationSpeed( 0 ); - SetRotationAcceleration( 0 ); + shape->setReferenceTime(lastTime); + shape->SetRotationSpeed( 0 ); + shape->SetRotationAcceleration( 0 ); + + rColor color_ = shape->getColor(); color_.r_ = color_.g_ = color_.b_ = .5; - RequestSync(); + shape->setColor(color_); + shape->RequestSync(); + } + else + OnVanish(); } REAL dt = time - lastTime; // conquest going on REAL conquest = sg_conquestRate * enemiesInside_ - sg_defendRate * ownersInside_ - sg_conquestDecayRate; +//fprintf(stderr, "conq %f + (dt %f * (conqRate %f * badIn %d - defRate %f * OwnIn %d - decay %f))\n", conquered_,dt,sg_conquestRate,enemiesInside_,sg_defendRate,ownersInside_,sg_conquestDecayRate); conquered_ += dt * conquest; if ( touchy_ && enemiesInside_ > 0 ) @@ -230,12 +262,13 @@ timeStep *= 100; if ( sn_GetNetState() != nCLIENT && - ( ( fabs( omega - GetRotationSpeed() ) + fabs( omegaDot - GetRotationAcceleration() ) ) * timeStep > .5 ) ) + shape && + ( ( fabs( omega - shape->GetRotationSpeed() ) + fabs( omegaDot - shape->GetRotationAcceleration() ) ) * timeStep > .5 ) ) { - SetRotationSpeed( omega ); - SetRotationAcceleration( omegaDot ); - SetReferenceTime(); - RequestSync(); + shape->SetRotationSpeed( omega ); + shape->SetRotationAcceleration( omegaDot ); + shape->setReferenceTime(lastSync_); + shape->RequestSync(); lastSync_ = lastTime; } @@ -310,6 +343,10 @@ { int kills = int( sg_onConquestKillRatio * team->NumPlayers() ); kills = kills > sg_onConquestKillMin ? kills : sg_onConquestKillMin; + tCoord pos; + if (shape) + pos = shape->Position(); + // FIXME: What should we use for origin if there is no shape? while ( kills > 0 ) { @@ -363,25 +400,29 @@ { if ( team ) { - sg_basezoneConqueredWriter << ePlayerNetID::FilterName(team->Name()) << GetPosition().x << GetPosition().y; + if (shape) + { + tCoord p = shape->Position(); + + sg_basezoneConqueredWriter << ePlayerNetID::FilterName(team->Name()) << p.x << p.y; + } + else + sg_basezoneConqueredWriter << ePlayerNetID::FilterName(team->Name()); sg_basezoneConqueredWriter.write(); } - float rr = GetRadius(); - rr *= rr; + if (shape) + { for(int i = se_PlayerNetIDs.Len()-1; i >=0; --i) { ePlayerNetID *player = se_PlayerNetIDs(i); if(!player) { continue; } - gCycle *cycle = dynamic_cast(player->Object()); - if(!cycle) { - continue; - } - if(cycle->Alive() && (cycle->Position() - Position()).NormSquared() < rr) { + if (shape->isInteracting(player->Object())) { sg_basezoneConquererWriter << player->GetUserName(); sg_basezoneConquererWriter.write(); } } + } // calculate score. If nobody really was inside the zone any more, half it. int totalScore = sg_onConquestScore; @@ -524,6 +565,10 @@ const tList& gameObjects = Grid()->GameObjects(); gCycle * closest = NULL; REAL closestDistance = 0; + tCoord pos; + if (shape) + pos = shape->Position(); + // FIXME: What should we use for origin if there is no shape? for (int i=gameObjects.Len()-1;i>=0;i--) { gCycle *other=dynamic_cast(gameObjects(i)); @@ -555,12 +600,17 @@ { // take over team and color team = closest->Player()->CurrentTeam(); + if (shape) + { + rColor color_ = shape->getColor(); color_.r_ = team->R()/15.0; color_.g_ = team->G()/15.0; color_.b_ = team->B()/15.0; - teamDistance_ = closestDistance; + shape->setColor(color_); - RequestSync(); + shape->RequestSync(); + } + teamDistance_ = closestDistance; } // if this zone does not belong to a team, discard it. @@ -608,7 +658,7 @@ // ******************************************************************************* // * -// * OnEnter +// * OnInside // * // ******************************************************************************* //! @@ -617,7 +667,7 @@ //! // ******************************************************************************* -void gBaseZoneHack::OnEnter( gCycle * target, REAL time ) +void zFortressZone::OnInside( gCycle * target, REAL time ) { // determine the team of the player tASSERT( target ); @@ -647,4 +697,4 @@ } } -// ======= Bunch of generic gZone stuff ======= +static zZoneExtRegistration regFortress("fortress", "", zFortressZone::create); --- gWinZone.h 2009-02-27 11:32:30.000000000 -0600 +++ zFortress.h 2009-02-27 11:38:07.000000000 -0600 @@ -25,34 +25,35 @@ */ -#ifndef ArmageTron_WinZone_H -#define ArmageTron_WinZone_H +#ifndef ArmageTron_zFortress_H +#define ArmageTron_zFortress_H -#include "eNetGameObject.h" +#include "zone/zZone.h" #include -#include "rColor.h" -#include "tFunction.h" - -// ======= Bunch of generic zone setting stuff ======= +#define gBaseZoneHack zFortressZone +#define gZone zZone class eTeam; class gCycle; +class gParser; -// ======= Bunch of generic gZone stuff ======= - -//! base zone: belongs to a team, enemy players who manage to stay inside win the round (will be replaced +//! fortress zone: belongs to a team, enemy players who manage to stay inside win the round class gBaseZoneHack: public gZone { public: - gBaseZoneHack(eGrid *grid, const eCoord &pos ); //!< local constructor + static zZone* create(eGrid*grid, std::string const & type) { return new zFortressZone(grid); }; + zFortressZone(eGrid *grid); //!< local constructor ~gBaseZoneHack(); //!< destructor + void setupVisuals(gParser::State_t &); + void readXML(tXmlParser::node const &); + private: virtual bool Timestep(REAL currentTime); //!< simulates behaviour up to currentTime - virtual void OnEnter( gCycle *target, REAL time ); //!< reacts on objects inside the zone + virtual void OnInside( gCycle *target, REAL time ); //!< reacts on objects inside the zone virtual void OnVanish(); //!< called when the zone vanishes virtual void OnConquest(); //!< called when the zone gets conquered virtual void CheckSurvivor(); //!< checks for the only surviving zone @@ -89,7 +90,4 @@ REAL lastSync_; //!< time of the last sync request }; -//! creates a win or death zone (according to configuration) at the specified position -gZone * sg_CreateWinDeathZone( eGrid * grid, const eCoord & pos ); - #endif