Add GUI option in track info screen for random item location.
This commit is contained in:
parent
d2509baf5c
commit
5b7161710d
@ -70,11 +70,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<spacer height="10"/>
|
<spacer height="10"/>
|
||||||
<div width="100%" height="fit" layout="horizontal-row" >
|
<div width="100%" height="fit" layout="horizontal-row" >
|
||||||
<label id="reverse-text" proportion="1" I18N="In the track info screen" text="Drive in reverse" text_align="right"/>
|
<label id="option-text" proportion="1" I18N="In the track info screen" text_align="right"/>
|
||||||
<spacer width="40"/>
|
<spacer width="40"/>
|
||||||
<div proportion="1" height="fit" layout="horizontal-row">
|
<div proportion="1" height="fit" layout="horizontal-row">
|
||||||
<div width="50%" height="fit" text-align="center" layout="vertical-row" >
|
<div width="50%" height="fit" text-align="center" layout="vertical-row" >
|
||||||
<checkbox id="reverse" align="center"/>
|
<checkbox id="option" align="center"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -515,6 +515,9 @@ namespace UserConfigParams
|
|||||||
/** If track debugging is enabled. */
|
/** If track debugging is enabled. */
|
||||||
PARAM_PREFIX int m_track_debug PARAM_DEFAULT( false );
|
PARAM_PREFIX int m_track_debug PARAM_DEFAULT( false );
|
||||||
|
|
||||||
|
/** If random number of items is used in an arena. */
|
||||||
|
PARAM_PREFIX bool m_random_arena_item PARAM_DEFAULT( false );
|
||||||
|
|
||||||
/** True if check structures should be debugged. */
|
/** True if check structures should be debugged. */
|
||||||
PARAM_PREFIX bool m_check_debug PARAM_DEFAULT( false );
|
PARAM_PREFIX bool m_check_debug PARAM_DEFAULT( false );
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "config/stk_config.hpp"
|
#include "config/stk_config.hpp"
|
||||||
|
#include "config/user_config.hpp"
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "graphics/material.hpp"
|
#include "graphics/material.hpp"
|
||||||
#include "graphics/material_manager.hpp"
|
#include "graphics/material_manager.hpp"
|
||||||
@ -476,18 +477,13 @@ void ItemManager::switchItems()
|
|||||||
} // switchItems
|
} // switchItems
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool ItemManager::randomItemsForArena(const AlignedArray<btTransform>& pos,
|
bool ItemManager::randomItemsForArena(const AlignedArray<btTransform>& pos)
|
||||||
unsigned int bonus, unsigned int big_nitro,
|
|
||||||
unsigned int small_nitro, unsigned int banana)
|
|
||||||
{
|
{
|
||||||
|
if (!UserConfigParams::m_random_arena_item) return false;
|
||||||
if (!BattleGraph::get()) return false;
|
if (!BattleGraph::get()) return false;
|
||||||
|
|
||||||
if (bonus == 0 && big_nitro == 0 && small_nitro == 0 && banana == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<int> used_location;
|
std::vector<int> used_location;
|
||||||
std::vector<int> invalid_location;
|
std::vector<int> invalid_location;
|
||||||
std::vector<int> final_location;
|
|
||||||
for (unsigned int i = 0; i < pos.size(); i++)
|
for (unsigned int i = 0; i < pos.size(); i++)
|
||||||
{
|
{
|
||||||
// Load all starting positions of arena, so no items will be near them
|
// Load all starting positions of arena, so no items will be near them
|
||||||
@ -498,21 +494,25 @@ bool ItemManager::randomItemsForArena(const AlignedArray<btTransform>& pos,
|
|||||||
invalid_location.push_back(node);
|
invalid_location.push_back(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsigned int total_item = bonus + big_nitro + small_nitro + banana;
|
RandomGenerator random;
|
||||||
for (unsigned int i = 0; i < total_item; i++)
|
const unsigned int MIN_DIST = sqrt(BattleGraph::get()->getNumNodes());
|
||||||
|
const unsigned int TOTAL_ITEM = MIN_DIST / 2;
|
||||||
|
|
||||||
|
Log::info("[ItemManager]","Creating %d random items for arena", TOTAL_ITEM);
|
||||||
|
for (unsigned int i = 0; i < TOTAL_ITEM; i++)
|
||||||
{
|
{
|
||||||
int chosen_node = -1;
|
int chosen_node = -1;
|
||||||
const unsigned int total_node = BattleGraph::get()->getNumNodes();
|
const unsigned int total_node = BattleGraph::get()->getNumNodes();
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if (final_location.size() + invalid_location.size() == total_node)
|
if (used_location.size() - pos.size() +
|
||||||
|
invalid_location.size() == total_node)
|
||||||
{
|
{
|
||||||
Log::warn("[ItemManager]","Can't place more random items! "
|
Log::warn("[ItemManager]","Can't place more random items! "
|
||||||
"Use default item location.");
|
"Use default item location.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomGenerator random;
|
|
||||||
const int node = random.get(total_node);
|
const int node = random.get(total_node);
|
||||||
|
|
||||||
// Check if tried
|
// Check if tried
|
||||||
@ -535,7 +535,7 @@ bool ItemManager::randomItemsForArena(const AlignedArray<btTransform>& pos,
|
|||||||
Vec3 d = BattleGraph::get()
|
Vec3 d = BattleGraph::get()
|
||||||
->getPolyOfNode(used_location[j]).getCenter() -
|
->getPolyOfNode(used_location[j]).getCenter() -
|
||||||
BattleGraph::get()->getPolyOfNode(node).getCenter();
|
BattleGraph::get()->getPolyOfNode(node).getCenter();
|
||||||
found = d.length_2d() > 20.0f;
|
found = d.length_2d() > MIN_DIST;
|
||||||
}
|
}
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
@ -549,20 +549,28 @@ bool ItemManager::randomItemsForArena(const AlignedArray<btTransform>& pos,
|
|||||||
|
|
||||||
assert(chosen_node != -1);
|
assert(chosen_node != -1);
|
||||||
used_location.push_back(chosen_node);
|
used_location.push_back(chosen_node);
|
||||||
final_location.push_back(chosen_node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert (final_location.size() == total_item);
|
for (unsigned int i = 0; i < pos.size(); i++)
|
||||||
for (unsigned int i = 0; i < total_item; i++)
|
used_location.erase(used_location.begin());
|
||||||
|
|
||||||
|
assert (used_location.size() == TOTAL_ITEM);
|
||||||
|
|
||||||
|
// Hard-coded ratio for now
|
||||||
|
const int BONUS_BOX = 4;
|
||||||
|
const int NITRO_BIG = 2;
|
||||||
|
const int NITRO_SMALL = 1;
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < TOTAL_ITEM; i++)
|
||||||
{
|
{
|
||||||
Item::ItemType type = (i < bonus ? Item::ITEM_BONUS_BOX :
|
const int j = random.get(10);
|
||||||
i < bonus + big_nitro ? Item::ITEM_NITRO_BIG :
|
Item::ItemType type = (j > BONUS_BOX ? Item::ITEM_BONUS_BOX :
|
||||||
i < bonus + big_nitro + small_nitro ? Item::ITEM_NITRO_SMALL :
|
j > NITRO_BIG ? Item::ITEM_NITRO_BIG :
|
||||||
Item::ITEM_BANANA);
|
j > NITRO_SMALL ? Item::ITEM_NITRO_SMALL : Item::ITEM_BANANA);
|
||||||
Vec3 loc = BattleGraph::get()
|
Vec3 loc = BattleGraph::get()
|
||||||
->getPolyOfNode(final_location[i]).getCenter();
|
->getPolyOfNode(used_location[i]).getCenter();
|
||||||
Item* item = newItem(type, loc, Vec3(0, 1, 0));
|
Item* item = newItem(type, loc, Vec3(0, 1, 0));
|
||||||
BattleGraph::get()->insertItems(item, final_location[i]);
|
BattleGraph::get()->insertItems(item, used_location[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -113,9 +113,7 @@ public:
|
|||||||
int add_info=-1);
|
int add_info=-1);
|
||||||
void switchItems ();
|
void switchItems ();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool randomItemsForArena(const AlignedArray<btTransform>& pos,
|
bool randomItemsForArena(const AlignedArray<btTransform>& pos);
|
||||||
unsigned int bonus, unsigned int big_nitro,
|
|
||||||
unsigned int small_nitro, unsigned int banana);
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the number of items. */
|
/** Returns the number of items. */
|
||||||
unsigned int getNumberOfItems() const { return (unsigned int) m_all_items.size(); }
|
unsigned int getNumberOfItems() const { return (unsigned int) m_all_items.size(); }
|
||||||
|
@ -67,9 +67,9 @@ void TrackInfoScreen::loadedFromFile()
|
|||||||
{
|
{
|
||||||
m_lap_spinner = getWidget<SpinnerWidget>("lap-spinner");
|
m_lap_spinner = getWidget<SpinnerWidget>("lap-spinner");
|
||||||
m_ai_kart_spinner = getWidget<SpinnerWidget>("ai-spinner");
|
m_ai_kart_spinner = getWidget<SpinnerWidget>("ai-spinner");
|
||||||
m_reverse = getWidget<CheckBoxWidget>("reverse");
|
m_option = getWidget<CheckBoxWidget>("option");
|
||||||
m_record_race = getWidget<CheckBoxWidget>("record");
|
m_record_race = getWidget<CheckBoxWidget>("record");
|
||||||
m_reverse->setState(false);
|
m_option->setState(false);
|
||||||
m_record_race->setState(false);
|
m_record_race->setState(false);
|
||||||
|
|
||||||
m_highscore_label = getWidget<LabelWidget>("highscores");
|
m_highscore_label = getWidget<LabelWidget>("highscores");
|
||||||
@ -198,18 +198,31 @@ void TrackInfoScreen::init()
|
|||||||
else
|
else
|
||||||
race_manager->setNumKarts(local_players);
|
race_manager->setNumKarts(local_players);
|
||||||
|
|
||||||
// Reverse track
|
// Reverse track or random item in arena
|
||||||
// -------------
|
// -------------
|
||||||
const bool reverse_available = m_track->reverseAvailable() &&
|
const bool reverse_available = m_track->reverseAvailable() &&
|
||||||
race_manager->getMinorMode() != RaceManager::MINOR_MODE_EASTER_EGG;
|
race_manager->getMinorMode() != RaceManager::MINOR_MODE_EASTER_EGG;
|
||||||
m_reverse->setVisible(reverse_available);
|
const bool random_item = m_track->hasNavMesh();
|
||||||
getWidget<LabelWidget>("reverse-text")->setVisible(reverse_available);
|
|
||||||
|
m_option->setVisible(reverse_available || random_item);
|
||||||
|
getWidget<LabelWidget>("option-text")->setVisible(reverse_available || random_item);
|
||||||
if (reverse_available)
|
if (reverse_available)
|
||||||
{
|
{
|
||||||
m_reverse->setState(race_manager->getReverseTrack());
|
//I18N: In the track info screen
|
||||||
|
getWidget<LabelWidget>("option-text")->setText(_("Drive in reverse"), false);
|
||||||
|
}
|
||||||
|
else if (random_item)
|
||||||
|
{
|
||||||
|
//I18N: In the track info screen
|
||||||
|
getWidget<LabelWidget>("option-text")->setText(_("Random item location"), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reverse_available)
|
||||||
|
{
|
||||||
|
m_option->setState(race_manager->getReverseTrack());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_reverse->setState(false);
|
m_option->setState(false);
|
||||||
|
|
||||||
// Record race or not
|
// Record race or not
|
||||||
// -------------
|
// -------------
|
||||||
@ -312,12 +325,16 @@ void TrackInfoScreen::onEnterPressedInternal()
|
|||||||
// not be accessible after dismiss:
|
// not be accessible after dismiss:
|
||||||
const int num_laps = race_manager->modeHasLaps() ? m_lap_spinner->getValue()
|
const int num_laps = race_manager->modeHasLaps() ? m_lap_spinner->getValue()
|
||||||
: -1;
|
: -1;
|
||||||
const bool reverse_track = m_reverse == NULL ? false
|
const bool option_state = m_option == NULL ? false
|
||||||
: m_reverse->getState();
|
: m_option->getState();
|
||||||
// Avoid negative lap numbers (after e.g. easter egg mode).
|
// Avoid negative lap numbers (after e.g. easter egg mode).
|
||||||
if(num_laps>=0)
|
if(num_laps>=0)
|
||||||
m_track->setActualNumberOfLaps(num_laps);
|
m_track->setActualNumberOfLaps(num_laps);
|
||||||
race_manager->setReverseTrack(reverse_track);
|
|
||||||
|
if(m_track->hasNavMesh())
|
||||||
|
UserConfigParams::m_random_arena_item = option_state;
|
||||||
|
else
|
||||||
|
race_manager->setReverseTrack(option_state);
|
||||||
|
|
||||||
// Avoid invaild Ai karts number during switching game modes
|
// Avoid invaild Ai karts number during switching game modes
|
||||||
const int max_arena_players = m_track->getMaxArenaPlayers();
|
const int max_arena_players = m_track->getMaxArenaPlayers();
|
||||||
@ -361,13 +378,20 @@ void TrackInfoScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
{
|
{
|
||||||
StateManager::get()->escapePressed();
|
StateManager::get()->escapePressed();
|
||||||
}
|
}
|
||||||
else if (name == "reverse")
|
else if (name == "option")
|
||||||
{
|
{
|
||||||
race_manager->setReverseTrack(m_reverse->getState());
|
if (m_track->hasNavMesh())
|
||||||
|
{
|
||||||
|
UserConfigParams::m_random_arena_item = m_option->getState();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
race_manager->setReverseTrack(m_option->getState());
|
||||||
// Makes sure the highscores get swapped when clicking the 'reverse'
|
// Makes sure the highscores get swapped when clicking the 'reverse'
|
||||||
// checkbox.
|
// checkbox.
|
||||||
updateHighScores();
|
updateHighScores();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (name == "record")
|
else if (name == "record")
|
||||||
{
|
{
|
||||||
const bool record = m_record_race->getState();
|
const bool record = m_record_race->getState();
|
||||||
|
@ -52,8 +52,8 @@ class TrackInfoScreen : public GUIEngine::Screen,
|
|||||||
/** Spinner for number of AI karts. */
|
/** Spinner for number of AI karts. */
|
||||||
GUIEngine::SpinnerWidget* m_ai_kart_spinner;
|
GUIEngine::SpinnerWidget* m_ai_kart_spinner;
|
||||||
|
|
||||||
/** Check box for reverse mode. */
|
/** Check box for reverse mode or random item in arena. */
|
||||||
GUIEngine::CheckBoxWidget* m_reverse;
|
GUIEngine::CheckBoxWidget* m_option;
|
||||||
|
|
||||||
/** Check box for record race. */
|
/** Check box for record race. */
|
||||||
GUIEngine::CheckBoxWidget* m_record_race;
|
GUIEngine::CheckBoxWidget* m_record_race;
|
||||||
|
@ -1862,10 +1862,10 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
|||||||
|
|
||||||
createPhysicsModel(main_track_count);
|
createPhysicsModel(main_track_count);
|
||||||
|
|
||||||
const bool arena_random_item = (m_has_navmesh && ItemManager::get()
|
const bool arena_random_item_created =
|
||||||
->randomItemsForArena(m_start_transforms,5,2,2,1));
|
ItemManager::get()->randomItemsForArena(m_start_transforms);
|
||||||
|
|
||||||
if (!arena_random_item)
|
if (!arena_random_item_created)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i<root->getNumNodes(); i++)
|
for (unsigned int i=0; i<root->getNumNodes(); i++)
|
||||||
{
|
{
|
||||||
@ -1882,7 +1882,7 @@ void Track::loadTrackModel(bool reverse_track, unsigned int mode_id)
|
|||||||
|
|
||||||
delete root;
|
delete root;
|
||||||
|
|
||||||
if ((m_is_arena || m_is_soccer) && !m_is_cutscene && m_has_navmesh && !arena_random_item)
|
if ((m_is_arena || m_is_soccer) && !m_is_cutscene && m_has_navmesh && !arena_random_item_created)
|
||||||
BattleGraph::get()->findItemsOnGraphNodes();
|
BattleGraph::get()->findItemsOnGraphNodes();
|
||||||
|
|
||||||
if (UserConfigParams::m_track_debug &&
|
if (UserConfigParams::m_track_debug &&
|
||||||
|
Loading…
Reference in New Issue
Block a user