@@ -82,7 +73,9 @@
+
+
@@ -93,15 +86,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
diff --git a/src/modes/world.cpp b/src/modes/world.cpp
index 5af6c73a7..b8c761b43 100644
--- a/src/modes/world.cpp
+++ b/src/modes/world.cpp
@@ -1549,8 +1549,21 @@ KartTeam World::getKartTeam(unsigned int kart_id) const
//-----------------------------------------------------------------------------
void World::setAITeam()
{
- m_red_ai = UserConfigParams::m_soccer_red_ai_num;
- m_blue_ai = UserConfigParams::m_soccer_blue_ai_num;
+ m_red_ai = race_manager->getNumberOfRedAIKarts();
+ m_blue_ai = race_manager->getNumberOfBlueAIKarts();
+
+ for (int i = 0; i < (int)race_manager->getNumLocalPlayers(); i++)
+ {
+ KartTeam team = race_manager->getKartInfo(i).getKartTeam();
+
+ // Happen in profiling mode
+ if (team == KART_TEAM_NONE)
+ {
+ race_manager->setKartTeam(i, KART_TEAM_BLUE);
+ team = KART_TEAM_BLUE;
+ continue; //FIXME, this is illogical
+ }
+ }
Log::debug("World", "Blue AI: %d red AI: %d", m_blue_ai, m_red_ai);
diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp
index 062e63160..f5450461f 100644
--- a/src/race/race_manager.hpp
+++ b/src/race/race_manager.hpp
@@ -327,6 +327,8 @@ private:
GrandPrixData m_grand_prix;
SavedGrandPrix* m_saved_gp;
int m_num_karts;
+ unsigned int m_num_red_ai;
+ unsigned int m_num_blue_ai;
unsigned int m_num_ghost_karts;
unsigned int m_num_spare_tire_karts;
unsigned int m_num_finished_karts;
@@ -474,6 +476,16 @@ public:
m_ai_superpower = SUPERPOWER_NONE;
} // setNumKarts
// ------------------------------------------------------------------------
+ void setNumRedAI(unsigned int num)
+ {
+ m_num_red_ai = num;
+ } // setNumRedAI
+ // ------------------------------------------------------------------------
+ void setNumBlueAI(unsigned int num)
+ {
+ m_num_blue_ai = num;
+ } // setNumBlueAI
+ // ------------------------------------------------------------------------
void setTimeTarget(float time)
{
m_goal_target = 0;
@@ -505,13 +517,17 @@ public:
// ------------------------------------------------------------------------
/** Returns the selected number of karts (selected number of players and
* AI karts. */
- unsigned int getNumberOfKarts() const {return m_num_karts; }
+ unsigned int getNumberOfKarts() const { return m_num_karts; }
// ------------------------------------------------------------------------
unsigned int getNumberOfAIKarts() const
{
return (unsigned int)m_ai_kart_list.size();
} // getNumberOfAIKarts
// ------------------------------------------------------------------------
+ unsigned int getNumberOfRedAIKarts() const { return m_num_red_ai; }
+ // ------------------------------------------------------------------------
+ unsigned int getNumberOfBlueAIKarts() const { return m_num_blue_ai; }
+ // ------------------------------------------------------------------------
unsigned int getNumNonGhostKarts() const
{ return m_num_karts - m_num_ghost_karts; }
// ------------------------------------------------------------------------
diff --git a/src/states_screens/track_info_screen.cpp b/src/states_screens/track_info_screen.cpp
index 66fa075bf..7d31093bf 100644
--- a/src/states_screens/track_info_screen.cpp
+++ b/src/states_screens/track_info_screen.cpp
@@ -106,8 +106,6 @@ void TrackInfoScreen::loadedFromFile()
m_is_soccer = false;
m_show_ffa_spinner = false;
- m_red_players = 0;
- m_blue_players = 0;
} // loadedFromFile
@@ -144,6 +142,7 @@ void TrackInfoScreen::init()
m_record_this_race = false;
const int max_arena_players = m_track->getMaxArenaPlayers();
+ const int local_players = race_manager->getNumLocalPlayers();
const bool has_laps = race_manager->modeHasLaps();
const bool has_highscores = race_manager->modeHasHighscores();
@@ -256,7 +255,6 @@ void TrackInfoScreen::init()
// Number of AIs
// -------------
- const int local_players = race_manager->getNumLocalPlayers();
const bool has_AI =
(race_manager->getMinorMode() == RaceManager::MINOR_MODE_3_STRIKES ||
race_manager->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL ||
@@ -268,93 +266,90 @@ void TrackInfoScreen::init()
if (has_AI)
{
- m_ai_kart_spinner->setActive(true);
- if (m_is_soccer) // Soccer mode: red + blue AI
+ m_ai_kart_label->setText(_("Number of AI karts"), false); // change to label back for other modes
+
+ int num_ai = int(UserConfigParams::m_num_karts_per_gamemode
+ [race_manager->getMinorMode()]) - local_players;
+
+ // Avoid negative numbers (which can happen if e.g. the number of karts
+ // in a previous race was lower than the number of players now.
+
+ if (num_ai < 0) num_ai = 0;
+ m_ai_kart_spinner->setValue(num_ai);
+
+ race_manager->setNumKarts(num_ai + local_players);
+
+ // Check if there's any local players in both team
+ int num_blue_players = 0, num_red_players = 0;
+
+ if (race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER)
{
- m_ai_blue_spinner->setVisible(true);
- m_ai_blue_label->setVisible(true);
- m_ai_blue_spinner->setActive(true);
- m_ai_kart_label->setText(_("Number of red team AI karts"), false);
-
- const int max_arena_players = m_track->getMaxArenaPlayers();
- const int local_players = race_manager->getNumLocalPlayers();
- const int num_ai = max_arena_players - local_players; // possible AI number
-
- getRedBluePlayerNumber();
-
- int num_blue_lower = (m_blue_players > 0) ? 0 : 1;
- int num_red_lower = (m_red_players > 0) ? 0 : 1;
- int num_blue_upper_hard = max_arena_players - local_players - num_red_lower; // possible upper bound
- int num_red_upper_hard = max_arena_players - local_players - num_blue_lower;// possible upper bound
-
- int num_red_ai = UserConfigParams::m_soccer_red_ai_num;
- int num_blue_ai = UserConfigParams::m_soccer_blue_ai_num;
-
- // Try the saved value, recalculate AI number (Balanced) if cannot use the saved values
- if (!((num_red_ai >= num_red_lower) && (num_red_ai <= num_red_upper_hard) &&
- (num_blue_ai >= num_blue_lower) && (num_blue_ai <= num_blue_upper_hard) &&
- (num_red_ai + num_blue_ai <= num_ai)))
+ for (int i = 0; i < local_players; i++)
{
- int additional_blue = m_red_players - m_blue_players;
- num_blue_ai = (num_ai - additional_blue) / 2 + additional_blue;
- num_red_ai = (num_ai - additional_blue) / 2;
+ KartTeam team = race_manager->getKartInfo(i).getKartTeam();
+ // Happen in profiling mode
+ if (team == KART_TEAM_NONE)
+ num_blue_players ++; // None team will set to blue
+ else
+ team == KART_TEAM_BLUE ? num_blue_players ++ : num_red_players ++;
+ }
+
+ const int max_num_ai = max_arena_players - local_players;
+ // Try the saved value, recalculate AI number (Balanced) if cannot use the saved values
+ if (UserConfigParams::m_soccer_red_ai_num + UserConfigParams::m_soccer_blue_ai_num > max_num_ai)
+ {
+ const int additional_blue = num_red_players - num_blue_players;
+ int num_blue_ai = (max_num_ai - additional_blue) / 2 + additional_blue;
+ int num_red_ai = (max_num_ai - additional_blue) / 2;
- if ((num_ai + additional_blue)%2 == 1)
- (additional_blue < 0) ? num_red_ai++ : num_blue_ai++;
+ if ((max_num_ai + additional_blue)%2 == 1)
+ additional_blue < 0 ? num_red_ai++ : num_blue_ai++;
UserConfigParams::m_soccer_red_ai_num = num_red_ai;
UserConfigParams::m_soccer_blue_ai_num = num_blue_ai;
}
-
- int num_blue_upper = max_arena_players - local_players - num_red_ai;
- int num_red_upper = max_arena_players - local_players - num_blue_ai;
- m_ai_kart_spinner->setMin(num_red_lower);
- m_ai_blue_spinner->setMin(num_blue_lower);
- m_ai_kart_spinner->setMax(std::min( (num_red_ai == num_red_lower ? num_red_upper_hard : num_red_upper + 1), num_red_upper_hard )); // +1 to allow adding AI
- m_ai_blue_spinner->setMax(std::min( (num_blue_ai == num_blue_lower ? num_blue_upper_hard : num_blue_upper + 1), num_blue_upper_hard )); // +1 to allow adding AI
-
- // Set the values
+ m_ai_blue_spinner->setVisible(true);
+ m_ai_blue_label->setVisible(true);
+ m_ai_blue_spinner->setActive(true);
+ m_ai_kart_label->setText(_("Number of red team AI karts"), false);
m_ai_kart_spinner->setValue(UserConfigParams::m_soccer_red_ai_num);
m_ai_blue_spinner->setValue(UserConfigParams::m_soccer_blue_ai_num);
-
- race_manager->setNumKarts(num_ai + local_players);
+ }
+
+ // Set the max karts supported based on the battle arena selected
+ if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
+ race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER)
+ {
+ m_ai_kart_spinner->setMax(max_arena_players - local_players);
+ m_ai_blue_spinner->setMax(max_arena_players - local_players);
+ if(num_blue_players == 0 && !UserConfigParams::m_artist_debug_mode)
+ m_ai_kart_spinner->setMax(max_arena_players - local_players - 1);
+ if(num_red_players == 0 && !UserConfigParams::m_artist_debug_mode)
+ m_ai_blue_spinner->setMax(max_arena_players - local_players - 1);
}
else
+ m_ai_kart_spinner->setMax(stk_config->m_max_karts - local_players);
+ // A ftl reace needs at least three karts to make any sense
+ if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
{
- m_ai_kart_label->setText(_("Number of AI karts"), false); // change to label back for other modes
-
- int num_ai = int(UserConfigParams::m_num_karts_per_gamemode
- [race_manager->getMinorMode()]) - local_players;
-
- // Avoid negative numbers (which can happen if e.g. the number of karts
- // in a previous race was lower than the number of players now.
-
- if (num_ai < 0) num_ai = 0;
- m_ai_kart_spinner->setValue(num_ai);
-
- race_manager->setNumKarts(num_ai + local_players);
- // Set the max karts supported based on the battle arena selected
- if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
- race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER)
- {
- m_ai_kart_spinner->setMax(max_arena_players - local_players);
- }
- else
- m_ai_kart_spinner->setMax(stk_config->m_max_karts - local_players);
- // A ftl reace needs at least three karts to make any sense
- if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_FOLLOW_LEADER)
- {
- m_ai_kart_spinner->setMin(std::max(0, 3 - local_players));
- }
- // Make sure in battle and soccer mode at least 1 ai for single player
- else if((race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES ||
- race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER) &&
- local_players == 1 &&
- !UserConfigParams::m_artist_debug_mode)
- m_ai_kart_spinner->setMin(1);
- else
- m_ai_kart_spinner->setMin(0);
+ m_ai_kart_spinner->setMin(std::max(0, 3 - local_players));
}
+ // Make sure in battle and soccer mode at least 1 ai for single player
+ else if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_3_STRIKES &&
+ local_players == 1 &&
+ !UserConfigParams::m_artist_debug_mode)
+ m_ai_kart_spinner->setMin(1);
+ else if(race_manager->getMinorMode()==RaceManager::MINOR_MODE_SOCCER)
+ {
+ m_ai_blue_spinner->setMin(0);
+ m_ai_kart_spinner->setMin(0);
+ if(num_blue_players == 0 && !UserConfigParams::m_artist_debug_mode)
+ m_ai_blue_spinner->setMin(1);
+ if(num_red_players == 0 && !UserConfigParams::m_artist_debug_mode)
+ m_ai_kart_spinner->setMin(1);
+ }
+ else
+ m_ai_kart_spinner->setMin(0);
} // has_AI
else
race_manager->setNumKarts(local_players);
@@ -551,13 +546,11 @@ void TrackInfoScreen::onEnterPressedInternal()
int num_ai = 0;
if (has_AI)
{
+ num_ai = m_ai_kart_spinner->getValue();
+
if (m_is_soccer) // Soccer mode
{
- num_ai = UserConfigParams::m_soccer_red_ai_num + UserConfigParams::m_soccer_blue_ai_num;
- }
- else // Other modes
- {
- num_ai = m_ai_kart_spinner->getValue();
+ num_ai += m_ai_blue_spinner->getValue();
}
}
@@ -590,6 +583,11 @@ void TrackInfoScreen::onEnterPressedInternal()
PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
race_manager->setNumKarts(num_ai + local_players);
+ if (m_is_soccer)
+ {
+ race_manager->setNumRedAI(m_ai_kart_spinner->getValue());
+ race_manager->setNumBlueAI(m_ai_blue_spinner->getValue());
+ }
race_manager->startSingleRace(m_track->getIdent(), num_laps, false);
} // onEnterPressedInternal
@@ -701,37 +699,13 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name,
{
const int max_arena_players = m_track->getMaxArenaPlayers();
const int local_players = race_manager->getNumLocalPlayers();
- const int num_ai = max_arena_players - local_players; // possible AI number
- int num_red = m_ai_kart_spinner->getValue();
- int num_blue = m_ai_blue_spinner->getValue();
-
- getRedBluePlayerNumber();
-
- int num_blue_lower = (m_blue_players > 0) ? 0 : 1;
- int num_red_lower = (m_red_players > 0) ? 0 : 1;
- int num_blue_upper = num_ai - num_red; // upper bound determined by the new num_red
- int num_blue_upper_hard = num_ai - num_red_lower; // possible upper bound
- int num_red_upper = num_ai - num_blue; // upper bound determined by the new num_blue
- int num_red_upper_hard = num_ai - num_blue_lower;// possible upper bound
-
- // Check if need to change blue in response to the red change
- if (num_blue > num_blue_upper)
- {
- num_blue = num_blue_upper; // change blue
- num_red_upper = num_ai - num_blue; // recalculate the upper bound determined by the new num_blue
- }
-
- m_ai_kart_spinner->setMax(std::min( (num_red == num_red_lower ? num_red_upper_hard : num_red_upper + 1), num_red_upper_hard )); // cannot be higher than the hard upper limit
- m_ai_blue_spinner->setMax(std::min( (num_blue == num_blue_lower ? num_blue_upper_hard : num_blue_upper + 1), num_blue_upper_hard )); // cannot be higher than the hard upper limit
- m_ai_kart_spinner->setMin(num_red_lower);
- m_ai_blue_spinner->setMin(num_blue_lower);
- m_ai_kart_spinner->setValue(num_red);
- m_ai_blue_spinner->setValue(num_blue);
-
- UserConfigParams::m_soccer_red_ai_num = num_red;
- UserConfigParams::m_soccer_blue_ai_num = num_blue;
-
- UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers() + num_red + num_blue;
+ const int num_ai = max_arena_players - local_players;
+
+ if(m_ai_kart_spinner->getValue() + m_ai_blue_spinner->getValue() > num_ai)
+ m_ai_blue_spinner->setValue(num_ai - m_ai_kart_spinner->getValue());
+ UserConfigParams::m_soccer_red_ai_num = m_ai_kart_spinner->getValue();
+ UserConfigParams::m_soccer_blue_ai_num = m_ai_blue_spinner->getValue();
+
//updateHighScores();
}
else // Other modes
@@ -743,69 +717,20 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name,
}
else if (name == "ai-blue-spinner")
{
- if (m_is_soccer) // AI distribution: Custom
+ if (m_is_soccer)
{
const int max_arena_players = m_track->getMaxArenaPlayers();
const int local_players = race_manager->getNumLocalPlayers();
- const int num_ai = max_arena_players - local_players; // possible AI number
- int num_red = m_ai_kart_spinner->getValue();
- int num_blue = m_ai_blue_spinner->getValue();
-
- getRedBluePlayerNumber();
-
- int num_blue_lower = (m_blue_players > 0) ? 0 : 1;
- int num_red_lower = (m_red_players > 0) ? 0 : 1;
- int num_blue_upper = num_ai - num_red; // upper bound determined by the new num_red
- int num_blue_upper_hard = num_ai - num_red_lower; // possible upper bound
- int num_red_upper = num_ai - num_blue; // upper bound determined by the new num_blue
- int num_red_upper_hard = num_ai - num_blue_lower;// possible upper bound
-
- // Check if need to change red in response to the blue change
- if (num_red > num_red_upper)
- {
- num_red = num_red_upper; // change red
- num_blue_upper = num_ai - num_red; // recalculate the upper bound determined by the new num_red
- }
-
- m_ai_kart_spinner->setMax(std::min( (num_red == num_red_lower ? num_red_upper_hard : num_red_upper + 1), num_red_upper_hard )); // cannot be higher than the hard upper limit
- m_ai_blue_spinner->setMax(std::min( (num_blue == num_blue_lower ? num_blue_upper_hard : num_blue_upper + 1), num_blue_upper_hard )); // cannot be higher than the hard upper limit
- m_ai_kart_spinner->setMin(num_red_lower);
- m_ai_blue_spinner->setMin(num_blue_lower);
- m_ai_kart_spinner->setValue(num_red);
- m_ai_blue_spinner->setValue(num_blue);
-
- UserConfigParams::m_soccer_red_ai_num = num_red;
- UserConfigParams::m_soccer_blue_ai_num = num_blue;
-
- UserConfigParams::m_num_karts_per_gamemode[race_manager->getMinorMode()] = race_manager->getNumLocalPlayers() + num_red + num_blue;
+ const int num_ai = max_arena_players - local_players;
+
+ if(m_ai_kart_spinner->getValue() + m_ai_blue_spinner->getValue() > num_ai)
+ m_ai_kart_spinner->setValue(num_ai - m_ai_blue_spinner->getValue());
+ UserConfigParams::m_soccer_red_ai_num = m_ai_kart_spinner->getValue();
+ UserConfigParams::m_soccer_blue_ai_num = m_ai_blue_spinner->getValue();
+
//updateHighScores();
}
}
} // eventCallback
// ----------------------------------------------------------------------------
-void TrackInfoScreen::getRedBluePlayerNumber()
-{
- const int local_players = race_manager->getNumLocalPlayers();
- int red_players = 0;
- int blue_players = 0;
- for (int i = 0; i < local_players; i++)
- {
- KartTeam team = race_manager->getKartInfo(i).getKartTeam();
-
- // Happen in profiling mode
- if (team == KART_TEAM_NONE)
- {
- race_manager->setKartTeam(i, KART_TEAM_BLUE);
- team = KART_TEAM_BLUE;
- continue; //FIXME, this is illogical
- }
-
- team == KART_TEAM_BLUE ? blue_players++ : red_players++;
- }
- m_red_players = red_players;
- m_blue_players = blue_players;
-} // getRedBluePlayerNumber
-
-// ----------------------------------------------------------------------------
-
diff --git a/src/states_screens/track_info_screen.hpp b/src/states_screens/track_info_screen.hpp
index bcdcf9d81..f2b674eb2 100644
--- a/src/states_screens/track_info_screen.hpp
+++ b/src/states_screens/track_info_screen.hpp
@@ -100,14 +100,8 @@ class TrackInfoScreen : public GUIEngine::Screen,
int m_icon_unknown_kart;
- /* The number of red and blue players */
- int m_red_players;
- int m_blue_players;
-
void updateHighScores();
- void getRedBluePlayerNumber();
-
public:
TrackInfoScreen();
virtual ~TrackInfoScreen();