From 779921a53f6d02bd546a085b53119b35b307cd24 Mon Sep 17 00:00:00 2001 From: Psyyringe Date: Mon, 2 Nov 2009 04:27:14 +0000 Subject: [PATCH] Psyringe - This revision adds "cheat mode", as suggested and pre-reviewed here: http://wololo.net/forum/viewtopic.php?f=15&t=730 Although the feature is named "cheat mode", its main purpose is to provide a toolbox for content creators. Currently this means to help AI deck creators, but the cheat mode is easily extensible. Features: - To enable cheat mode, create a new profile with the super secret cheat name (shouldn't be hard to find - or just mail me if you don't want to look). Then, leave and re-enter the Options menu. You can now enable cheat mode on the first tab. Note: The secret profile name is *not* my original suggestion from the forum, I went with Jeck's alternative suggestion so that he won't have to cringe over bad puns everytime he's using it. ;) - Complete collection: In cheat mode, there's a new option in the deck viewer, which makes sure that you have at least 4 of any card available. - Deck integrity: When in cheat mode, and you load a deck with cards that are not present in your collection, then these cards won't be stripped from your deck any more. Instead, they are added to your collection. - Money cheat: In cheat mode, when you click on an item in the shop, you get the option to steal 1,000 credits from the shopkeeper. Please review my code - I just started with C++, I may make very obvious mistakes or use inelegant style. The sooner you point this out, the sooner I'll improve. thanks to wololo and jeck for comments and suggestions. Jeck: Do the setVisible and setHidden methods currently work? I tried to use them to hide a menu item, but they all seem to lead to empty methods - Perhaps placeholders for a not yet implemented functionality? --- projects/mtg/include/GameOptions.h | 2 ++ projects/mtg/include/MTGDeck.h | 1 + projects/mtg/src/GameOptions.cpp | 10 ++++++++++ projects/mtg/src/GameStateDeckViewer.cpp | 20 +++++++++++++++++--- projects/mtg/src/GameStateOptions.cpp | 2 ++ projects/mtg/src/MTGDeck.cpp | 21 +++++++++++++++++++++ projects/mtg/src/ShopItem.cpp | 6 ++++++ 7 files changed, 59 insertions(+), 3 deletions(-) diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 5a3f60013..84e612cb4 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -13,6 +13,7 @@ using std::string; #define PLAYER_SAVEFILE "data.dat" #define PLAYER_SETTINGS "options.txt" #define PLAYER_COLLECTION "collection.dat" +#define SECRET_PROFILE "Gleemax" #define INVALID_OPTION -1 @@ -34,6 +35,7 @@ public: MUSICVOLUME, SFXVOLUME, DIFFICULTY, + CHEATMODE, OSD, CLOSEDHAND, HANDDIRECTION, diff --git a/projects/mtg/include/MTGDeck.h b/projects/mtg/include/MTGDeck.h index f061ff9c0..899ea1c41 100644 --- a/projects/mtg/include/MTGDeck.h +++ b/projects/mtg/include/MTGDeck.h @@ -90,6 +90,7 @@ class MTGDeck{ int addRandomCards(int howmany, int * setIds = NULL, int nbSets = 0, int rarity = -1, const char * subtype = NULL, int * colors = NULL, int nbcolors = 0); int add(int cardid); int add(MTGDeck * deck); // adds the contents of "deck" into myself + int complete(); int remove(int cardid); int removeAll(); int add(MTGCard * card); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index 1f87f3cb4..1a84e369b 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -22,6 +22,7 @@ const char * Options::optionNames[] = { "musicVolume", "sfxVolume", "difficulty", + "cheatmode", "displayOSD", "closed_hand", "hand_direction", @@ -282,9 +283,18 @@ int GameOptions::load(){ } file.close(); } + // (PSY) Make sure that cheatmode is switched off for ineligible profiles: + if(options[Options::ACTIVE_PROFILE].str != SECRET_PROFILE) { + (*this)[Options::CHEATMODE].number = 0; + } return 1; } int GameOptions::save(){ + // (PSY) Make sure that cheatmode is switched off for ineligible profiles: + if(options[Options::ACTIVE_PROFILE].str != SECRET_PROFILE) { + (*this)[Options::CHEATMODE].number = 0; + } + std::ofstream file(mFilename.c_str()); if (file){ for ( int x=0; x < (int) values.size(); x++ ){ diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index 3f20e6b79..cf652fae0 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -95,10 +95,12 @@ void GameStateDeckViewer::Start() stw.pageCount = 5; stw.needUpdate = true; - menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-100,20); + menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-150,20); menu->Add(0,"Save"); menu->Add(1,"Save & Rename"); menu->Add(2,"Switch decks without saving"); + if(options[Options::CHEATMODE].number) + menu->Add(-1,"Complete collection & reset (cheat)"); menu->Add(3,"Back to main menu"); menu->Add(4,"Cancel"); @@ -1096,13 +1098,20 @@ int GameStateDeckViewer::loadDeck(int deckid){ sprintf(deckname,"deck%i.txt",deckid); SAFE_DELETE(myDeck); myDeck = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(deckname,"",false,false).c_str(), mParent->collection)); + + // Check whether the cards in the deck are actually available in the player's collection: MTGCard * current = myDeck->getNext(); + int cheatmode = options[Options::CHEATMODE].number; while (current){ int howmanyinDeck = myDeck->cards[current]; for (int i = 0; i < howmanyinDeck; i++){ int deleted = myCollection->Remove(current); - if (!deleted){ - myDeck->Remove(current); + if (!deleted){ // Card was not present in the collection + if (cheatmode) { // (PSY) Are we in cheatmode? + playerdata->collection->add(current); // (PSY) Yes - add the card to the collection + } else { + myDeck->Remove(current); // No - remove the card from the deck + } } } current = myDeck->getNext(current); @@ -1173,6 +1182,11 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId) case 11: //Save / exit menu switch (controlId) { + case -1: // (PSY) Cheatmode: Complete the collection + playerdata->collection->complete(); // Add the cards + playerdata->collection->save(); // Save the new collection + mStage = STAGE_WELCOME; // Reset the deck viewer, so that the new collection gets loaded + break; case 0: myDeck->save(); playerdata->save(); diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index de6e40eb9..ab1aec470 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -36,6 +36,8 @@ void GameStateOptions::Start() optionsList->Add(NEW OptionInteger(Options::OSD, "Display InGame extra information")); if (options[Options::DIFFICULTY_MODE_UNLOCKED].number) optionsList->Add(NEW WDecoEnum(NEW OptionInteger(Options::DIFFICULTY,"Difficulty",3,1,0),OptionDifficulty::getInstance())); + if(options[Options::ACTIVE_PROFILE].str == SECRET_PROFILE) + optionsList->Add(NEW OptionInteger(Options::CHEATMODE, "Enable cheat mode")); optionsList->Add(NEW OptionInteger(Options::INTERRUPT_SECONDS, "Seconds to pause for an Interrupt", 20, 1)); optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYSPELLS, "Interrupt my spells")); optionsList->Add(NEW OptionInteger(Options::INTERRUPTMYABILITIES, "Interrupt my abilities")); diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index 4d4101c03..12fa9ee62 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -545,6 +545,27 @@ int MTGDeck::add(MTGCard * card){ return (add(card->getId())); } +int MTGDeck::complete() { + /* (PSY) adds cards to the deck/collection. Makes sure that the deck + or collection has at least 4 of every implemented card. Does not + change the number of cards of which already 4 or more are present. */ + int id, n; + size_t databaseSize = database->ids.size(); + for (size_t it = 0 ; it < databaseSize ; it++) { + id = database->ids[it]; + if(cards.find(id) == cards.end()){ + cards[id] = 4; + total_cards += 4; + } else { + n = cards[id]; + if (n < 4) { + total_cards += 4 - n; + cards[id] = 4; + } + } + } + return 1; +} int MTGDeck::removeAll(){ total_cards = 0; diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index 4cd69f109..66ff786b4 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -257,6 +257,9 @@ void ShopItems::Update(float dt){ dialog = NEW SimpleMenu(1,this,resources.GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); dialog->Add(1,"Yes"); dialog->Add(2,"No"); + if(options[Options::CHEATMODE].number) { + dialog->Add(3,"Steal 1,000 credits (cheat)"); + } } else{ dialog->Update(dt); @@ -433,6 +436,9 @@ void ShopItems::ButtonPressed(int controllerId, int controlId){ } showPriceDialog = -1; break; + case 3: // (PSY) Cheatmode: get free money + playerdata->credits += 1000; + break; } }