More soccer mode improvements:

1. Max 8 karts are supported now

2. Clearer starting position assignment in soccer world

3. Reset all karts to starting position after each goal
This commit is contained in:
Benau
2016-01-21 15:28:11 +08:00
parent 35ce3d8299
commit 1ee9979fe1
5 changed files with 81 additions and 12 deletions

View File

@@ -267,6 +267,13 @@ void PlayerController::update(float dt)
if (!history->replayHistory())
steer(dt, m_steer_val);
if (World::getWorld()->getPhase() == World::GOAL_PHASE)
{
m_controls->m_brake = false;
m_controls->m_accel = 0.0f;
return;
}
if (World::getWorld()->isStartPhase())
{
if (m_controls->m_accel || m_controls->m_brake ||

View File

@@ -106,6 +106,13 @@ void SoccerAI::reset()
//-----------------------------------------------------------------------------
void SoccerAI::update(float dt)
{
if (World::getWorld()->getPhase() == World::GOAL_PHASE)
{
m_controls->m_accel = 0.0f;
AIBaseController::update(dt);
return;
}
ArenaAI::update(dt);
} // update

View File

@@ -71,6 +71,7 @@ SoccerWorld::~SoccerWorld()
void SoccerWorld::init()
{
m_kart_team_map.clear();
m_kart_position_map.clear();
WorldWithRank::init();
m_display_rank = false;
m_goal_timer = 0.0f;
@@ -158,12 +159,24 @@ void SoccerWorld::update(float dt)
if (world->getPhase() == World::GOAL_PHASE)
{
if (m_goal_timer == 0.0f)
{
// Stop all karts
for (unsigned int i = 0; i < m_karts.size(); i++)
m_karts[i]->setVelocity(btVector3(0, 0, 0));
}
m_goal_timer += dt;
if (m_goal_timer > 3.0f)
{
world->setPhase(WorldStatus::RACE_PHASE);
m_goal_timer = 0.0f;
if (!isRaceOver())
{
// Reset all karts
for (unsigned int i = 0; i < m_karts.size(); i++)
moveKartAfterRescue(m_karts[i]);
}
}
}
@@ -309,14 +322,15 @@ void SoccerWorld::initKartList()
//Assigning indicators
for(unsigned int i=0; i<kart_amount; i++)
{
scene::ISceneNode *arrowNode;
scene::ISceneNode *arrow_node;
float arrow_pos_height = m_karts[i]->getKartModel()->getHeight()+0.5f;
SoccerTeam team = getKartTeam(i);
arrowNode = irr_driver->addBillboard(core::dimension2d<irr::f32>(0.3f,0.3f),
team == SOCCER_TEAM_BLUE ? blue : red, m_karts[i]->getNode(), true);
arrow_node = irr_driver->addBillboard(core::dimension2d<irr::f32>(0.3f,
0.3f), team == SOCCER_TEAM_BLUE ? blue : red, m_karts[i]
->getNode(), true);
arrowNode->setPosition(core::vector3df(0, arrow_pos_height, 0));
arrow_node->setPosition(core::vector3df(0, arrow_pos_height, 0));
}
} // initKartList
@@ -343,8 +357,10 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
RaceManager::KartType kart_type,
PerPlayerDifficulty difficulty)
{
int posIndex = index;
int position = index+1;
int cur_red = getTeamNum(SOCCER_TEAM_RED);
int cur_blue = getTeamNum(SOCCER_TEAM_BLUE);
int pos_index = 0;
int position = index + 1;
SoccerTeam team = SOCCER_TEAM_BLUE;
if (kart_type == RaceManager::KT_AI)
@@ -377,16 +393,19 @@ AbstractKart *SoccerWorld::createKart(const std::string &kart_ident, int index,
m_kart_team_map[index] = team;
}
if(!team)
// Notice: In blender, please set 1,3,5,7... for blue starting position;
// 2,4,6,8... for red.
if (team == SOCCER_TEAM_BLUE)
{
if(index % 2 != 1) posIndex += 1;
pos_index = 1 + 2 * cur_blue;
}
else
{
if(index % 2 != 0) posIndex += 1;
pos_index = 2 + 2 * cur_red;
}
btTransform init_pos = getStartTransform(posIndex);
btTransform init_pos = getStartTransform(pos_index - 1);
m_kart_position_map[index] = (unsigned)(pos_index - 1);
AbstractKart *new_kart = new Kart(kart_ident, index, position, init_pos,
difficulty);
@@ -591,3 +610,32 @@ void SoccerWorld::updateDefenders()
if (defender != -1) m_blue_defender = defender;
} // updateDefenders
//-----------------------------------------------------------------------------
int SoccerWorld::getTeamNum(SoccerTeam team) const
{
int total = 0;
if (m_kart_team_map.empty()) return total;
for (unsigned int i = 0; i < (unsigned)m_karts.size(); ++i)
{
if (team == getKartTeam(m_karts[i]->getWorldKartId())) total++;
}
return total;
} // getTeamNum
//-----------------------------------------------------------------------------
unsigned int SoccerWorld::getRescuePositionIndex(AbstractKart *kart)
{
std::map<int, unsigned int>::const_iterator n =
m_kart_position_map.find(kart->getWorldKartId());
if (n != m_kart_position_map.end())
{
return n->second;
}
// Fallback
Log::warn("SoccerWorld", "Unknown kart, using default starting position.");
return 0;
} // getRescuePositionIndex

View File

@@ -73,7 +73,9 @@ private:
std::vector<float> m_red_score_times;
std::vector<ScorerData> m_blue_scorers;
std::vector<float> m_blue_score_times;
std::map<int, SoccerTeam> m_kart_team_map;
std::map<int, unsigned int> m_kart_position_map;
/** Data generated from navmesh */
std::vector<int> m_kart_on_node;
@@ -95,7 +97,10 @@ private:
void updateBallPosition();
/** Clean up */
void resetAllNodes();
/** Function to update the AI which is the closest to its goal to defend. */
void updateDefenders();
/** Get number of teammates in a team, used by starting position assign. */
int getTeamNum(SoccerTeam team) const;
public:
@@ -112,6 +117,8 @@ public:
// overriding World methods
virtual void reset();
virtual unsigned int getRescuePositionIndex(AbstractKart *kart) OVERRIDE;
virtual bool useFastMusicNearEnd() const { return false; }
virtual void getKartsDisplayInfo(
std::vector<RaceGUIBase::KartIconDisplayInfo> *info) {}

View File

@@ -596,8 +596,8 @@ void Track::loadTrackInfo()
}
if (m_is_soccer)
{
// Currently only max six players in soccer mode
m_max_arena_players = 6;
// Currently only max eight players in soccer mode
m_max_arena_players = 8;
}
} // loadTrackInfo