Merge pull request #1286 from marcoll/master
Avoid the use of the new GP editor as a cheating aid
This commit is contained in:
commit
4388f230a4
@ -218,30 +218,49 @@ bool GrandPrixData::checkConsistency(bool chatty) const
|
||||
/** Returns true if the track is available. This is used to test if Fort Magma
|
||||
* is available (this way FortMagma is not used in the last Grand Prix in
|
||||
* story mode, but will be available once all challenges are done and nolok
|
||||
* is unlocked).
|
||||
* is unlocked). It also prevents people from using the grand prix editor as
|
||||
* a way to play tracks that still haven't been unlocked
|
||||
*/
|
||||
bool GrandPrixData::isTrackAvailable(const std::string &id) const
|
||||
bool GrandPrixData::isTrackAvailable(const std::string &id, bool includeLocked) const
|
||||
{
|
||||
return id!="fortmagma" ||
|
||||
!PlayerManager::getCurrentPlayer()->isLocked("fortmagma");
|
||||
if (includeLocked)
|
||||
return true;
|
||||
else if (id == "fortmagma")
|
||||
return !PlayerManager::getCurrentPlayer()->isLocked("fortmagma");
|
||||
else
|
||||
return (!m_editable || !PlayerManager::get()->getCurrentPlayer()->isLocked(id));
|
||||
} // isTrackAvailable
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::getLaps(std::vector<int> *laps) const
|
||||
std::vector<std::string> GrandPrixData::getTrackNames(bool includeLocked) const
|
||||
{
|
||||
laps->clear();
|
||||
std::vector<std::string> names;
|
||||
for (unsigned int i = 0; i < m_tracks.size(); i++)
|
||||
{
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
names.push_back(m_tracks[i]);
|
||||
} // for i
|
||||
return names;
|
||||
} // getTrackNames
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::vector<int> GrandPrixData::getLaps(bool includeLocked) const
|
||||
{
|
||||
std::vector<int> laps;
|
||||
for (unsigned int i = 0; i< m_tracks.size(); i++)
|
||||
if(isTrackAvailable(m_tracks[i]))
|
||||
laps->push_back(m_laps[i]);
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
laps.push_back(m_laps[i]);
|
||||
return laps;
|
||||
} // getLaps
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::getReverse(std::vector<bool> *reverse) const
|
||||
std::vector<bool> GrandPrixData::getReverse(bool includeLocked) const
|
||||
{
|
||||
reverse->clear();
|
||||
std::vector<bool> reverse;
|
||||
for (unsigned int i = 0; i< m_tracks.size(); i++)
|
||||
if(isTrackAvailable(m_tracks[i]))
|
||||
reverse->push_back(m_reversed[i]);
|
||||
if(isTrackAvailable(m_tracks[i], includeLocked))
|
||||
reverse.push_back(m_reversed[i]);
|
||||
return reverse;
|
||||
} // getReverse
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -251,15 +270,18 @@ bool GrandPrixData::isEditable() const
|
||||
} // isEditable
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned int GrandPrixData::getNumberOfTracks() const
|
||||
unsigned int GrandPrixData::getNumberOfTracks(bool includeLocked) const
|
||||
{
|
||||
return m_tracks.size();
|
||||
if (includeLocked)
|
||||
return m_tracks.size();
|
||||
else
|
||||
return getTrackNames(false).size();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
irr::core::stringw GrandPrixData::getTrackName(const unsigned int track) const
|
||||
{
|
||||
assert(track < getNumberOfTracks());
|
||||
assert(track < getNumberOfTracks(true));
|
||||
Track* t = track_manager->getTrack(m_tracks[track]);
|
||||
assert(t != NULL);
|
||||
return t->getName();
|
||||
@ -268,28 +290,28 @@ irr::core::stringw GrandPrixData::getTrackName(const unsigned int track) const
|
||||
// ----------------------------------------------------------------------------
|
||||
const std::string& GrandPrixData::getTrackId(const unsigned int track) const
|
||||
{
|
||||
assert(track < getNumberOfTracks());
|
||||
assert(track < getNumberOfTracks(true));
|
||||
return m_tracks[track];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
unsigned int GrandPrixData::getLaps(const unsigned int track) const
|
||||
{
|
||||
assert(track < getNumberOfTracks());
|
||||
assert(track < getNumberOfTracks(true));
|
||||
return m_laps[track];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool GrandPrixData::getReverse(const unsigned int track) const
|
||||
{
|
||||
assert(track < getNumberOfTracks());
|
||||
assert(track < getNumberOfTracks(true));
|
||||
return m_reversed[track];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::moveUp(const unsigned int track)
|
||||
{
|
||||
assert (track > 0 && track < getNumberOfTracks());
|
||||
assert (track > 0 && track < getNumberOfTracks(true));
|
||||
|
||||
std::swap(m_tracks[track], m_tracks[track - 1]);
|
||||
std::swap(m_laps[track], m_laps[track - 1]);
|
||||
@ -301,7 +323,7 @@ void GrandPrixData::moveUp(const unsigned int track)
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::moveDown(const unsigned int track)
|
||||
{
|
||||
assert (track < (getNumberOfTracks() - 1));
|
||||
assert (track < (getNumberOfTracks(true) - 1));
|
||||
|
||||
std::swap(m_tracks[track], m_tracks[track + 1]);
|
||||
std::swap(m_laps[track], m_laps[track + 1]);
|
||||
@ -316,7 +338,7 @@ void GrandPrixData::addTrack(Track* track, unsigned int laps, bool reverse,
|
||||
{
|
||||
int n;
|
||||
|
||||
n = getNumberOfTracks();
|
||||
n = getNumberOfTracks(true);
|
||||
assert (track != NULL);
|
||||
assert (laps > 0);
|
||||
assert (position >= -1 && position < n);
|
||||
@ -342,7 +364,7 @@ void GrandPrixData::addTrack(Track* track, unsigned int laps, bool reverse,
|
||||
void GrandPrixData::editTrack(unsigned int t, Track* track,
|
||||
unsigned int laps, bool reverse)
|
||||
{
|
||||
assert (t < getNumberOfTracks());
|
||||
assert (t < getNumberOfTracks(true));
|
||||
assert (track != NULL);
|
||||
assert (laps > 0);
|
||||
|
||||
@ -354,23 +376,11 @@ void GrandPrixData::editTrack(unsigned int t, Track* track,
|
||||
// ----------------------------------------------------------------------------
|
||||
void GrandPrixData::remove(const unsigned int track)
|
||||
{
|
||||
assert (track < getNumberOfTracks());
|
||||
assert (track < getNumberOfTracks(true));
|
||||
|
||||
m_tracks.erase(m_tracks.begin() + track);
|
||||
m_laps.erase(m_laps.begin() + track);
|
||||
m_reversed.erase(m_reversed.begin() + track);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const std::vector<std::string>& GrandPrixData::getTrackNames() const
|
||||
{
|
||||
m_really_available_tracks.clear();
|
||||
for (unsigned int i = 0; i < m_tracks.size(); i++)
|
||||
{
|
||||
if(isTrackAvailable(m_tracks[i]))
|
||||
m_really_available_tracks.push_back(m_tracks[i]);
|
||||
} // for i
|
||||
return m_really_available_tracks;
|
||||
} // getTrackNames
|
||||
|
||||
/* EOF */
|
||||
|
@ -51,15 +51,6 @@ private:
|
||||
* (ie. 'volcano'). */
|
||||
std::vector<std::string> m_tracks;
|
||||
|
||||
/** This is the list of actually available tracks. In the last GP Fort
|
||||
* Magma can not be used untill the final challenge. In order to provide
|
||||
* still 5 tracks/GP, the last GP is only using 4 tracks in story mode,
|
||||
* but (once nolok is unlocked) Fort Magma is added after that. So this
|
||||
* list is always re-evaluated depending on the state of Nolok (i.e. if
|
||||
* nolok is unlocked, Fort Magma is available, otherwise not).
|
||||
* Mark this member mutable so that getTrackNames can be const. */
|
||||
mutable std::vector<std::string> m_really_available_tracks;
|
||||
|
||||
/** The number of laps that each track should be raced, in the right order */
|
||||
std::vector<int> m_laps;
|
||||
|
||||
@ -69,7 +60,13 @@ private:
|
||||
/** Wether the user can edit this grand prix or not */
|
||||
bool m_editable;
|
||||
|
||||
bool isTrackAvailable(const std::string &id) const;
|
||||
/** In the last GP Fort Magma can not be used untill the final challenge.
|
||||
* In order to provide still 5 tracks/GP, the last GP is only using 4
|
||||
* tracks in story mode, but once nolok is unlocked Fort Magma becomes
|
||||
* available (i.e. if nolok is unlocked, Fort Magma is available, otherwise
|
||||
* not).
|
||||
*/
|
||||
bool isTrackAvailable(const std::string &id, bool includeLocked) const;
|
||||
|
||||
public:
|
||||
|
||||
@ -87,23 +84,23 @@ public:
|
||||
void reload();
|
||||
bool writeToFile();
|
||||
|
||||
bool checkConsistency(bool chatty=true) const;
|
||||
const std::vector<std::string>& getTrackNames() const;
|
||||
void getLaps(std::vector<int> *laps) const;
|
||||
void getReverse(std::vector<bool> *reverse) const;
|
||||
bool isEditable() const;
|
||||
unsigned int getNumberOfTracks() const;
|
||||
const std::string& getTrackId(const unsigned int track) const;
|
||||
irr::core::stringw getTrackName(const unsigned int track) const;
|
||||
unsigned int getLaps(const unsigned int track) const;
|
||||
bool getReverse(const unsigned int track) const;
|
||||
void moveUp(const unsigned int track);
|
||||
void moveDown(const unsigned int track);
|
||||
void addTrack(Track* track, unsigned int laps,
|
||||
bool reverse, int position=-1);
|
||||
void editTrack(unsigned int t, Track* track,
|
||||
unsigned int laps, bool reverse);
|
||||
void remove(const unsigned int track);
|
||||
bool checkConsistency(bool chatty=true) const;
|
||||
std::vector<std::string> getTrackNames(const bool includeLocked=false) const;
|
||||
std::vector<int> getLaps(const bool includeLocked=false) const;
|
||||
std::vector<bool> getReverse(const bool includeLocked=false) const;
|
||||
bool isEditable() const;
|
||||
unsigned int getNumberOfTracks(const bool includeLocked=false) const;
|
||||
const std::string& getTrackId(const unsigned int track) const;
|
||||
irr::core::stringw getTrackName(const unsigned int track) const;
|
||||
unsigned int getLaps(const unsigned int track) const;
|
||||
bool getReverse(const unsigned int track) const;
|
||||
void moveUp(const unsigned int track);
|
||||
void moveDown(const unsigned int track);
|
||||
void addTrack(Track* track, unsigned int laps,
|
||||
bool reverse, int position=-1);
|
||||
void editTrack(unsigned int t, Track* track,
|
||||
unsigned int laps, bool reverse);
|
||||
void remove(const unsigned int track);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** @return the (potentially translated) user-visible name of the Grand
|
||||
|
@ -284,8 +284,8 @@ void RaceManager::startNew(bool from_overworld)
|
||||
{
|
||||
// GP: get tracks, laps and reverse info from grand prix
|
||||
m_tracks = m_grand_prix.getTrackNames();
|
||||
m_grand_prix.getLaps(&m_num_laps);
|
||||
m_grand_prix.getReverse(&m_reverse_track);
|
||||
m_num_laps = m_grand_prix.getLaps();
|
||||
m_reverse_track = m_grand_prix.getReverse();
|
||||
}
|
||||
//assert(m_player_karts.size() > 0);
|
||||
|
||||
|
@ -75,7 +75,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
|
||||
|
||||
|
||||
// ---- Track listings
|
||||
const std::vector<std::string>& tracks = gp->getTrackNames();
|
||||
const std::vector<std::string> tracks = gp->getTrackNames();
|
||||
const int trackAmount = tracks.size();
|
||||
|
||||
int height_of_one_line = (y2 - y1)/(trackAmount+1);
|
||||
@ -130,7 +130,7 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
|
||||
m_screenshot_widget->m_w = m_area.getWidth()/2;
|
||||
m_screenshot_widget->m_h = y2 - y1 - 10;
|
||||
|
||||
Track* track = track_manager->getTrack(tracks[0]);
|
||||
Track* track = (tracks.size() == 0 ? NULL : track_manager->getTrack(tracks[0]));
|
||||
|
||||
m_screenshot_widget->m_properties[PROP_ICON] = (track != NULL ?
|
||||
track->getScreenshotFile().c_str() :
|
||||
@ -152,7 +152,12 @@ GPInfoDialog::GPInfoDialog(const std::string& gpIdent, const float w, const floa
|
||||
race_manager->getNumberOfKarts(),
|
||||
race_manager->getNumLocalPlayers());
|
||||
|
||||
if (gp_ok)
|
||||
if (tracks.size() == 0)
|
||||
{
|
||||
okBtn->m_properties[PROP_ID] = "cannot_start";
|
||||
okBtn->setText(_("Sorry, no tracks available"));
|
||||
}
|
||||
else if (gp_ok)
|
||||
{
|
||||
okBtn->m_properties[PROP_ID] = "start";
|
||||
okBtn->setText(_("Start Grand Prix"));
|
||||
@ -265,14 +270,15 @@ void GPInfoDialog::onUpdate(float dt)
|
||||
|
||||
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(m_gp_ident);
|
||||
assert(gp != NULL);
|
||||
const std::vector<std::string>& tracks = gp->getTrackNames();
|
||||
const std::vector<std::string> tracks = gp->getTrackNames();
|
||||
if (frameAfter >= (int)tracks.size())
|
||||
{
|
||||
frameAfter = 0;
|
||||
m_curr_time = 0;
|
||||
}
|
||||
|
||||
Track* track = track_manager->getTrack(tracks[frameAfter]);
|
||||
Track* track = (tracks.size() == 0 ? NULL :
|
||||
track_manager->getTrack(tracks[frameAfter]));
|
||||
std::string fn = track ? track->getScreenshotFile()
|
||||
: file_manager->getAsset(FileManager::GUI, "main_help.png");
|
||||
m_screenshot_widget->setImage(fn.c_str(), IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
|
@ -199,8 +199,8 @@ void EditGPScreen::onConfirm()
|
||||
if (m_action == "remove")
|
||||
{
|
||||
m_gp->remove(m_selected);
|
||||
setSelected(m_selected >= (int)m_gp->getNumberOfTracks() ?
|
||||
m_gp->getNumberOfTracks() - 1 : m_selected);
|
||||
setSelected(m_selected >= (int)m_gp->getNumberOfTracks(true) ?
|
||||
m_gp->getNumberOfTracks(true) - 1 : m_selected);
|
||||
loadList(m_selected);
|
||||
setModified(true);
|
||||
}
|
||||
@ -228,7 +228,7 @@ void EditGPScreen::loadList(const int selected)
|
||||
m_icon_bank->scaleToHeight (64);
|
||||
m_list->setIcons(m_icon_bank, 64);
|
||||
|
||||
for (unsigned int i = 0; i < m_gp->getNumberOfTracks(); i++)
|
||||
for (unsigned int i = 0; i < m_gp->getNumberOfTracks(true); i++)
|
||||
{
|
||||
std::vector<GUIEngine::ListWidget::ListCell> row;
|
||||
|
||||
@ -290,8 +290,8 @@ void EditGPScreen::edit()
|
||||
{
|
||||
edit_screen->setSelection(track_manager->getTrack(
|
||||
m_gp->getTrackId(m_selected)),
|
||||
m_gp->getLaps(m_selected),
|
||||
m_gp->getReverse(m_selected));
|
||||
m_gp->getLaps((unsigned int)m_selected),
|
||||
m_gp->getReverse((unsigned int)m_selected));
|
||||
StateManager::get()->pushScreen(edit_screen);
|
||||
}
|
||||
}
|
||||
|
@ -625,7 +625,7 @@ void FeatureUnlockedCutScene::addUnlockedGP(const GrandPrixData* gp)
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::vector<std::string>& gptracks = gp->getTrackNames();
|
||||
const std::vector<std::string> gptracks = gp->getTrackNames();
|
||||
const int trackAmount = gptracks.size();
|
||||
|
||||
if (trackAmount == 0)
|
||||
|
@ -171,7 +171,7 @@ void GrandPrixEditorScreen::loadTrackList (const std::string& gpname)
|
||||
assert(tracks_widget != NULL);
|
||||
|
||||
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(gpname);
|
||||
const std::vector<std::string>& tracks = gp->getTrackNames();
|
||||
const std::vector<std::string> tracks = gp->getTrackNames(true);
|
||||
|
||||
tracks_widget->clearItems();
|
||||
tracks_widget->setItemCountHint(tracks.size());
|
||||
@ -209,7 +209,7 @@ void GrandPrixEditorScreen::loadGPList()
|
||||
for (unsigned int i = 0; i < grand_prix_manager->getNumberOfGrandPrix(); i++)
|
||||
{
|
||||
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(i);
|
||||
const std::vector<std::string>& tracks = gp->getTrackNames();
|
||||
const std::vector<std::string> tracks = gp->getTrackNames(true);
|
||||
|
||||
std::vector<std::string> sshot_files;
|
||||
for (unsigned int t=0; t<tracks.size(); t++)
|
||||
|
@ -91,7 +91,7 @@ void RaceResultGUI::init()
|
||||
(m_sshot_height + SSHOT_SEPARATION))); //Show at least one
|
||||
|
||||
// Calculate screenshot scrolling parameters
|
||||
const std::vector<std::string>& tracks =
|
||||
const std::vector<std::string> tracks =
|
||||
race_manager->getGrandPrix()->getTrackNames();
|
||||
int n_tracks = tracks.size();
|
||||
int currentTrack = race_manager->getTrackNumber();
|
||||
@ -103,7 +103,7 @@ void RaceResultGUI::init()
|
||||
}
|
||||
else
|
||||
{
|
||||
m_start_track = currentTrack;
|
||||
m_start_track = 0;
|
||||
m_end_track = tracks.size();
|
||||
}
|
||||
} // init
|
||||
@ -1295,7 +1295,7 @@ void RaceResultGUI::displayHighScores()
|
||||
// ----------------------------------------------------------------------------
|
||||
void RaceResultGUI::displayScreenShots()
|
||||
{
|
||||
const std::vector<std::string>& tracks =
|
||||
const std::vector<std::string> tracks =
|
||||
race_manager->getGrandPrix()->getTrackNames();
|
||||
int currentTrack = race_manager->getTrackNumber();
|
||||
|
||||
|
@ -215,7 +215,7 @@ void TracksScreen::init()
|
||||
{
|
||||
const GrandPrixData* gp = grand_prix_manager->getGrandPrix(n);
|
||||
|
||||
const std::vector<std::string> &tracks = gp->getTrackNames();
|
||||
const std::vector<std::string> tracks = gp->getTrackNames(true);
|
||||
|
||||
std::vector<std::string> sshot_files;
|
||||
for (unsigned int t=0; t<tracks.size(); t++)
|
||||
|
Loading…
Reference in New Issue
Block a user