first try for a Random GP generator

This commit is contained in:
konstin 2014-05-18 15:27:57 +02:00
parent 359c846df4
commit 0fdfe16a93
11 changed files with 65 additions and 37 deletions

View File

@ -376,8 +376,7 @@ void ChallengeData::setRace(RaceManager::Difficulty d) const
else if(m_mode==CM_GRAND_PRIX)
{
race_manager->setMinorMode(m_minor);
const GrandPrixData *gp = grand_prix_manager->getGrandPrix(m_gp_id);
race_manager->setGrandPrix(*gp);
race_manager->setGrandPrix(grand_prix_manager->getGrandPrix(m_gp_id));
race_manager->setDifficulty(d);
race_manager->setNumKarts(m_num_karts[d]);
race_manager->setNumLocalPlayers(1);

View File

@ -359,7 +359,7 @@ void gamepadVisualisation()
} // gamepadVisualisation
// ============================================================================
/** Sets the hat mesh name depending on the current christmas mode
/** Sets the hat mesh name depending on the current christmas mode
* m_xmas_mode (0: use current date, 1: always on, 2: always off).
*/
void handleXmasMode()
@ -808,14 +808,14 @@ int handleCmdLine()
if(CommandLine::has("--gp", &s))
{
race_manager->setMajorMode(RaceManager::MAJOR_MODE_GRAND_PRIX);
const GrandPrixData *gp = grand_prix_manager->getGrandPrix(s);
GrandPrixData *gp = grand_prix_manager->getGrandPrix(s);
if (!gp)
{
Log::warn("main", "There is no GP named '%s'.", s.c_str());
return 0;
}
race_manager->setGrandPrix(*gp);
race_manager->setGrandPrix(gp);
} // --gp
if(CommandLine::has("--numkarts", &n) ||CommandLine::has("-k", &n))
@ -1266,7 +1266,7 @@ int main(int argc, char *argv[] )
// displayed (if necessary), so we have to make sure there is
// a current player
PlayerManager::get()->enforceCurrentPlayer();
InputDevice *device;
// Use keyboard 0 by default in --no-start-screen

View File

@ -28,9 +28,10 @@
#include "tracks/track.hpp"
#include "utils/string_utils.hpp"
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <memory>
#include <algorithm>
#include <stdexcept>
@ -44,6 +45,33 @@ GrandPrixData::GrandPrixData(const std::string& filename)
reload();
}
// ----------------------------------------------------------------------------
GrandPrixData::GrandPrixData(const unsigned int number_of_tracks,
const std::string& track_group,
const bool use_reverse)
{
m_filename = "Random GP - Not loaded from a file!";
m_id = "random";
m_name = L"Random";
m_editable = false;
const std::vector<int> track_indices = track_manager->getTracksInGroup(track_group);
const size_t available_tracks = track_indices.size();
assert(number_of_tracks <= available_tracks);
m_tracks.reserve(number_of_tracks);
m_laps.reserve(number_of_tracks);
m_reversed.reserve(number_of_tracks);
for (unsigned int i = 0; i < number_of_tracks; i++)
{
int index = track_indices[int(rand() % available_tracks)];
m_tracks.push_back(std::string(track_manager->getTrack(index)->getIdent()));
m_laps.push_back(3);
m_reversed.push_back(rand() % 2);
}
}
// ----------------------------------------------------------------------------
void GrandPrixData::setId(const std::string& id)
{

View File

@ -76,6 +76,10 @@ public:
GrandPrixData(const std::string& filename);
/** Needed for simple creation of an instance of GrandPrixData */
GrandPrixData() {};
/** TODO */
GrandPrixData(const unsigned int number_of_tracks,
const std::string& m_track_group,
const bool use_reverse);
// Methods for the GP editor
void setId(const std::string& id);
@ -117,7 +121,6 @@ public:
// ------------------------------------------------------------------------
/** Returns the filename of the grand prix xml file. */
const std::string& getFilename() const { return m_filename; }
}; // GrandPrixData
#endif

View File

@ -283,9 +283,9 @@ void RaceManager::startNew(bool from_overworld)
if(m_major_mode==MAJOR_MODE_GRAND_PRIX)
{
// GP: get tracks, laps and reverse info from grand prix
m_tracks = m_grand_prix.getTrackNames();
m_num_laps = m_grand_prix.getLaps();
m_reverse_track = m_grand_prix.getReverse();
m_tracks = m_grand_prix->getTrackNames();
m_num_laps = m_grand_prix->getLaps();
m_reverse_track = m_grand_prix->getReverse();
}
//assert(m_player_karts.size() > 0);
@ -348,7 +348,7 @@ void RaceManager::startNew(bool from_overworld)
SavedGrandPrix* gp = SavedGrandPrix::getSavedGP( StateManager::get()
->getActivePlayerProfile(0)
->getUniqueID(),
m_grand_prix.getId(),
m_grand_prix->getId(),
m_difficulty,
m_num_karts,
m_player_karts.size());
@ -499,7 +499,7 @@ void RaceManager::next()
SavedGrandPrix::getSavedGP(StateManager::get()
->getActivePlayerProfile(0)
->getUniqueID(),
m_grand_prix.getId(),
m_grand_prix->getId(),
m_difficulty,
m_num_karts,
m_player_karts.size());
@ -516,7 +516,7 @@ void RaceManager::next()
new SavedGrandPrix(
StateManager::get()->getActivePlayerProfile(0)
->getUniqueID(),
m_grand_prix.getId(),
m_grand_prix->getId(),
m_difficulty,
m_player_karts.size(),
m_track_number,
@ -642,7 +642,7 @@ void RaceManager::exitRace(bool delete_world)
SavedGrandPrix::getSavedGP(StateManager::get()
->getActivePlayerProfile(0)
->getUniqueID(),
m_grand_prix.getId(),
m_grand_prix->getId(),
m_difficulty,
m_num_karts,
m_player_karts.size());
@ -774,13 +774,14 @@ void RaceManager::rerunRace()
//-----------------------------------------------------------------------------
void RaceManager::startGP(const GrandPrixData* gp, bool from_overworld,
void RaceManager::startGP(GrandPrixData* gp, bool from_overworld,
bool continue_saved_gp)
{
assert(gp != NULL);
//std::cout << gp->getId();
StateManager::get()->enterGameState();
setGrandPrix(*gp);
setGrandPrix(gp);
setCoinTarget( 0 ); // Might still be set from a previous challenge
race_manager->setupPlayerKartInfo();
m_continue_saved_gp = continue_saved_gp;

View File

@ -324,14 +324,14 @@ private:
* same list of AIs is used for all tracks of a GP. */
std::vector<std::string> m_ai_kart_list;
int m_track_number;
GrandPrixData m_grand_prix;
GrandPrixData* m_grand_prix;
int m_num_karts;
unsigned int m_num_finished_karts;
unsigned int m_num_finished_players;
int m_coin_target;
bool m_has_time_target;
float m_time_target;
int m_goal_target;
int m_goal_target;
void startNextRace(); // start a next race
@ -344,7 +344,7 @@ private:
bool m_have_kart_last_position_on_overworld;
Vec3 m_kart_last_position_on_overworld;
/** Determines if saved GP should be continued or not*/
bool m_continue_saved_gp;
@ -410,7 +410,7 @@ public:
void setDifficulty(Difficulty diff);
// ------------------------------------------------------------------------
void setGrandPrix(const GrandPrixData &gp)
void setGrandPrix(GrandPrixData* gp)
{
m_grand_prix = gp;
m_coin_target = 0;
@ -525,7 +525,7 @@ public:
// ------------------------------------------------------------------------
const std::string& getTrackName() const { return m_tracks[m_track_number];}
// ------------------------------------------------------------------------
const GrandPrixData *getGrandPrix() const { return &m_grand_prix; }
GrandPrixData* getGrandPrix() const { return m_grand_prix; }
// ------------------------------------------------------------------------
unsigned int getFinishedKarts() const { return m_num_finished_karts; }
// ------------------------------------------------------------------------
@ -682,7 +682,7 @@ public:
* \brief Higher-level method to start a GP without having to care about
* the exact startup sequence
*/
void startGP(const GrandPrixData* gp, bool from_overworld,
void startGP(GrandPrixData* gp, bool from_overworld,
bool continue_saved_gp);
/**

View File

@ -123,7 +123,6 @@ void GPInfoDialog::InitAfterDrawingTheHeader(const int y1,
}
// ---- Track screenshot
m_screenshot_widget = new IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO,
false /* tab stop */, false /* focusable */,
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE /* Track gives us absolute paths */);
@ -215,7 +214,7 @@ void GPInfoDialog::onEnterPressedInternal()
ModalDialog::dismiss();
// Disable accidentally unlocking of a challenge
PlayerManager::getCurrentPlayer()->setCurrentChallenge("");
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false);
race_manager->startGP(m_gp, false, false);
}
// ----------------------------------------------------------------------------
@ -225,9 +224,8 @@ GUIEngine::EventPropagation GPInfoDialog::processEvent(const std::string& eventS
if (eventSource == "start")
{
// Save GP identifier, since dismiss will delete this object.
std::string gp_id = m_gp_ident;
ModalDialog::dismiss();
race_manager->startGP(grand_prix_manager->getGrandPrix(gp_id), false, false);
race_manager->startGP(m_gp, false, false);
return GUIEngine::EVENT_BLOCK;
}
if (eventSource == "continue")

View File

@ -33,7 +33,7 @@ namespace GUIEngine
*/
class GPInfoDialog : public GUIEngine::ModalDialog
{
protected: // Needed for randomGPInfoDialog
protected: // Necessary for randomGPInfoDialog
std::string m_gp_ident;
GUIEngine::IconButtonWidget* m_screenshot_widget;
float m_curr_time;
@ -46,7 +46,7 @@ public:
* Creates a modal dialog with given percentage of screen width and height
* atm only used in track_screen.cpp
*/
GPInfoDialog() : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) {} // FIXME: This line's only here for compiling
GPInfoDialog() : ModalDialog(PERCENT_WIDTH, PERCENT_HEIGHT) {}
GPInfoDialog(const std::string& gpIdent);
virtual ~GPInfoDialog();

View File

@ -30,9 +30,9 @@ using namespace GUIEngine;
randomGPInfoDialog::randomGPInfoDialog()
{
// Defaults - loading selection from last time frrom a file would be better
int m_number_of_tracks = 4;
std::string m_track_group = "standart";
bool m_use_reverse = true;
m_number_of_tracks = 2;
m_track_group = "nextgen";
m_use_reverse = true;
doInit();
m_curr_time = 0.0f;
@ -41,9 +41,7 @@ randomGPInfoDialog::randomGPInfoDialog()
const int y2 = m_area.getHeight()*6/7;
m_gp_ident = "random";
//const GrandPrixData* gp = grand_prix_manager->newRandomGP(m_number_of_tracks, m_track_group, m_use_reverse);
m_gp = grand_prix_manager->getGrandPrix("1_penguinplayground");
m_gp = new GrandPrixData(m_number_of_tracks, m_track_group, m_use_reverse);
// ---- GP Name
core::rect< s32 > area_top(0, 0, m_area.getWidth(), y1);

View File

@ -25,11 +25,13 @@
class randomGPInfoDialog : public GPInfoDialog
{
private:
int m_number_of_laps;
unsigned int m_number_of_tracks;
std::string m_track_group;
bool m_use_reverse;
public:
randomGPInfoDialog();
~randomGPInfoDialog() { delete m_gp; }
};
#endif

View File

@ -119,7 +119,6 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name,
}
else
{
std::cout << selection << std::endl;
if (selection != "Random")
new GPInfoDialog(selection);
else