2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file cheat.cpp Handling (loading/saving/initializing) of cheats. */
|
2008-04-17 21:21:01 +00:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "cheat_type.h"
|
|
|
|
|
2020-04-18 09:51:02 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2011-05-02 20:59:54 +00:00
|
|
|
/** All the cheats. */
|
2008-04-17 21:21:01 +00:00
|
|
|
Cheats _cheats;
|
2020-04-18 09:51:02 +00:00
|
|
|
ExtraCheats _extra_cheats;
|
|
|
|
|
|
|
|
std::map<std::string, Cheat> _unknown_cheats;
|
2008-04-17 21:21:01 +00:00
|
|
|
|
2011-05-02 20:59:54 +00:00
|
|
|
/** Reinitialise all the cheats. */
|
2008-04-17 21:21:01 +00:00
|
|
|
void InitializeCheats()
|
|
|
|
{
|
|
|
|
memset(&_cheats, 0, sizeof(Cheats));
|
2020-04-18 09:51:02 +00:00
|
|
|
memset(&_extra_cheats, 0, sizeof(ExtraCheats));
|
|
|
|
_unknown_cheats.clear();
|
2008-04-17 21:21:01 +00:00
|
|
|
}
|
|
|
|
|
2011-01-18 22:17:15 +00:00
|
|
|
/**
|
|
|
|
* Return true if any cheat has been used, false otherwise
|
|
|
|
* @return has a cheat been used?
|
|
|
|
*/
|
2008-04-17 21:21:01 +00:00
|
|
|
bool CheatHasBeenUsed()
|
|
|
|
{
|
|
|
|
/* Cannot use lengthof because _cheats is of type Cheats, not Cheat */
|
2009-01-10 00:31:47 +00:00
|
|
|
const Cheat *cht = (Cheat*)&_cheats;
|
|
|
|
const Cheat *cht_last = &cht[sizeof(_cheats) / sizeof(Cheat)];
|
2008-04-17 21:21:01 +00:00
|
|
|
|
|
|
|
for (; cht != cht_last; cht++) {
|
|
|
|
if (cht->been_used) return true;
|
|
|
|
}
|
|
|
|
|
2020-04-18 09:51:02 +00:00
|
|
|
cht = (Cheat*)&_extra_cheats;
|
|
|
|
cht_last = &cht[sizeof(_extra_cheats) / sizeof(Cheat)];
|
|
|
|
|
|
|
|
for (; cht != cht_last; cht++) {
|
|
|
|
if (cht->been_used) return true;
|
|
|
|
}
|
|
|
|
|
2008-04-17 21:21:01 +00:00
|
|
|
return false;
|
|
|
|
}
|