Some code cleanup in soccer world

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14741 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
deveee 2013-12-20 21:11:22 +00:00
parent ae2a41f2d0
commit 49be95b966

View File

@ -41,23 +41,28 @@
*/
SoccerWorld::SoccerWorld() : WorldWithRank()
{
if(race_manager->hasTimeTarget()){
if(race_manager->hasTimeTarget())
{
WorldStatus::setClockMode(WorldStatus::CLOCK_COUNTDOWN, race_manager->getTimeTarget());
countDownReachedZero = false;
}
else WorldStatus::setClockMode(CLOCK_CHRONO);
else
{
WorldStatus::setClockMode(CLOCK_CHRONO);
}
m_use_highscores = false;
} // SoccerWorld
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/** The destructor frees al data structures.
*/
SoccerWorld::~SoccerWorld()
{
sfx_manager->deleteSFX(m_goal_sound);
} // ~SoccerWorld
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/** Initializes the soccer world. It sets up the data structure
* to keep track of points etc. for each kart.
*/
@ -85,7 +90,8 @@ void SoccerWorld::init()
void SoccerWorld::reset()
{
WorldWithRank::reset();
if(race_manager->hasTimeTarget()){
if(race_manager->hasTimeTarget())
{
WorldStatus::setClockMode(WorldStatus::CLOCK_COUNTDOWN, race_manager->getTimeTarget());
countDownReachedZero = false;
}
@ -151,35 +157,30 @@ void SoccerWorld::update(float dt)
m_goal_timer = 0;
}
}
// TODO
} // update
//-----------------------------------------------------------------------------
void SoccerWorld::onCheckGoalTriggered(bool first_goal)
{
if (m_can_score_points)
{
//I18N: soccer mode
//~ m_race_gui->addMessage(_("GOAL!"), NULL,
//~ /* time */ 5.0f,
//~ video::SColor(255,255,255,255),
//~ /*important*/ true,
//~ /*big font*/ true);
m_team_goals[first_goal ? 0 : 1]++;
//printf("Score:\nTeam One %d : %d Team Two\n", m_team_goals[0], m_team_goals[1]);
World *world = World::getWorld();
world->setPhase(WorldStatus::GOAL_PHASE);
m_goal_sound->play();
if(m_lastKartToHitBall != -1)
{
if(first_goal){
if(first_goal)
{
m_redScorers.push_back(m_lastKartToHitBall);
if(race_manager->hasTimeTarget())
m_redScoreTimes.push_back(race_manager->getTimeTarget() - world->getTime());
else
m_redScoreTimes.push_back(world->getTime());
}
else{
else
{
m_blueScorers.push_back(m_lastKartToHitBall);
if(race_manager->hasTimeTarget())
m_blueScoreTimes.push_back(race_manager->getTimeTarget() - world->getTime());
@ -189,8 +190,6 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
}
}
//m_check_goals_enabled = false; // TODO: remove?
// Reset original positions for the soccer balls
TrackObjectManager* tom = getTrack()->getTrackObjectManager();
assert(tom);
@ -226,9 +225,11 @@ void SoccerWorld::onCheckGoalTriggered(bool first_goal)
/** Sets the last kart that hit the ball, to be able to
* identify the scorer later.
*/
void SoccerWorld::setLastKartTohitBall(unsigned int kartId){
void SoccerWorld::setLastKartTohitBall(unsigned int kartId)
{
m_lastKartToHitBall = kartId;
}
} // setLastKartTohitBall
//-----------------------------------------------------------------------------
/** The battle is over if only one kart is left, or no player kart.
*/
@ -240,17 +241,16 @@ bool SoccerWorld::isRaceOver()
return false;
}
else if(race_manager->hasTimeTarget()){
if(race_manager->hasTimeTarget())
{
return countDownReachedZero;
}
// One team scored the target goals ...
else if(getScore(0) >= m_goal_target ||
getScore(1) >= m_goal_target )
else
{
return true;
return (getScore(0) >= m_goal_target || getScore(1) >= m_goal_target);
}
// TODO
return getCurrentNumKarts()==1 || getCurrentNumPlayers()==0;
} // isRaceOver
//-----------------------------------------------------------------------------
@ -263,12 +263,14 @@ void SoccerWorld::terminateRace()
m_can_score_points = false;
WorldWithRank::terminateRace();
} // terminateRace
//-----------------------------------------------------------------------------
/** Called when the match time ends.
*/
void SoccerWorld::countdownReachedZero(){
void SoccerWorld::countdownReachedZero()
{
countDownReachedZero = true;
}
} // countdownReachedZero
//-----------------------------------------------------------------------------
/** Returns the data to display in the race gui.
@ -391,55 +393,32 @@ void SoccerWorld::moveKartAfterRescue(AbstractKart* kart)
}
} // moveKartAfterRescue
//-----------------------------------------------------------------------------/** Set position and team for the karts */
//-----------------------------------------------------------------------------
/** Set position and team for the karts */
void SoccerWorld::initKartList()
{
const unsigned int kart_amount = m_karts.size();
// Set kart positions, ordering them by team
for(unsigned int n=0; n<kart_amount; n++)
{
m_karts[n]->setPosition(-1);
}
// TODO: remove
int team_karts_amount[NB_SOCCER_TEAMS];
memset(team_karts_amount, 0, sizeof(team_karts_amount));
{
// Set the kart teams if they haven't been already set by the setup screen
// (happens when the setup screen is skipped, with 1 player)
SoccerTeam round_robin_team = SOCCER_TEAM_RED;
for(unsigned int n=0; n<kart_amount; n++)
{
if(race_manager->getLocalKartInfo(n).getSoccerTeam() == SOCCER_TEAM_NONE)
race_manager->setLocalKartSoccerTeam(
race_manager->getLocalKartInfo(n).getLocalPlayerId(),round_robin_team);
team_karts_amount[race_manager->getLocalKartInfo(n).getSoccerTeam()]++;
round_robin_team = (round_robin_team==SOCCER_TEAM_RED ?
SOCCER_TEAM_BLUE : SOCCER_TEAM_RED);
}// next kart
}
//Loading the indicator textures
irr::video::ITexture *redTeamTexture =
irr_driver->getTexture(FileManager::GUI,"soccer_player_red.png");
irr_driver->getTexture(FileManager::GUI, "soccer_player_red.png");
irr::video::ITexture *blueTeamTexture =
irr_driver->getTexture(FileManager::GUI, "soccer_player_blue.png");
//Assigning indicators
for(unsigned int i=0; i<kart_amount; i++)
{
scene::ISceneNode *arrowNode;
float arrow_pos_height = m_karts[i]->getKartModel()->getHeight()+0.5f;
SoccerTeam team = race_manager->getLocalKartInfo(i).getSoccerTeam();
if(race_manager->getLocalKartInfo(i).getSoccerTeam() == SOCCER_TEAM_RED)
arrowNode = irr_driver->addBillboard(core::dimension2d<irr::f32>(0.3f,0.3f),
redTeamTexture,m_karts[i]->getNode(), true);
else
arrowNode = irr_driver->addBillboard(core::dimension2d<irr::f32>(0.3f,0.3f),
blueTeamTexture,m_karts[i]->getNode(),true);
team==SOCCER_TEAM_RED ? redTeamTexture : blueTeamTexture,
m_karts[i]->getNode(), true);
arrowNode->setPosition(core::vector3df(0, arrow_pos_height, 0));
}
@ -452,7 +431,6 @@ void SoccerWorld::initKartList()
// Set kart positions, ordering them by team
for(unsigned int n=0; n<kart_amount; n++)
{
SoccerTeam team = race_manager->getLocalKartInfo(n).getSoccerTeam();
m_karts[n]->setPosition(team_cur_position[team]);
team_cur_position[team]++;
@ -463,7 +441,8 @@ void SoccerWorld::initKartList()
int SoccerWorld::getScore(unsigned int i)
{
return m_team_goals[i];
}
} // getScore
//-----------------------------------------------------------------------------
int SoccerWorld::getTeamLeader(unsigned int team)
{
@ -481,19 +460,23 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
RaceManager::KartType kart_type)
{
int posIndex = index;
int position = index+1;
if(race_manager->getLocalKartInfo(index).getSoccerTeam() == SOCCER_TEAM_RED)
{
if(index % 2 != 1) posIndex += 1;
}
else if(race_manager->getLocalKartInfo(index).getSoccerTeam() == SOCCER_TEAM_BLUE)
else
{
if(index % 2 != 0) posIndex += 1;
}
int position = index+1;
btTransform init_pos = m_track->getStartTransform(posIndex);
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos);
new_kart->init(race_manager->getKartType(index));
Controller *controller = NULL;
switch(kart_type)
{
case RaceManager::KT_PLAYER: