| 85 | } |
| 86 | |
| 87 | command_result mode (color_ostream &out_, vector <string> & parameters) |
| 88 | { |
| 89 | if(!out_.is_console()) |
| 90 | return CR_FAILURE; |
| 91 | Console &out = static_cast<Console&>(out_); |
| 92 | |
| 93 | string command = ""; |
| 94 | bool set = false; |
| 95 | bool abuse = false; |
| 96 | int rv = 0; |
| 97 | t_gamemodes gm; |
| 98 | for(auto iter = parameters.begin(); iter != parameters.end(); iter++) |
| 99 | { |
| 100 | if((*iter) == "set") |
| 101 | { |
| 102 | set = true; |
| 103 | } |
| 104 | else if((*iter) == "abuse") |
| 105 | { |
| 106 | set = abuse = true; |
| 107 | } |
| 108 | else |
| 109 | return CR_WRONG_USAGE; |
| 110 | } |
| 111 | |
| 112 | World::ReadGameMode(gm); |
| 113 | |
| 114 | printCurrentModes(gm, out); |
| 115 | |
| 116 | if(set) |
| 117 | { |
| 118 | if(!abuse) |
| 119 | { |
| 120 | if( gm.g_mode == game_mode::NONE || gm.g_type == game_type::VIEW_LEGENDS) |
| 121 | { |
| 122 | out.printerr("It is not safe to set modes in menus.\n"); |
| 123 | return CR_FAILURE; |
| 124 | } |
| 125 | out << "\nPossible choices:" << endl |
| 126 | << "0 = Fortress Mode" << endl |
| 127 | << "1 = Adventurer Mode" << endl |
| 128 | << "2 = Arena Mode" << endl |
| 129 | << "3 = Arena, controlling creature" << endl |
| 130 | << "4 = Reclaim Fortress Mode" << endl |
| 131 | << "c = cancel/do nothing" << endl; |
| 132 | uint32_t select=99; |
| 133 | |
| 134 | string selected; |
| 135 | input_again: |
| 136 | CommandHistory hist; |
| 137 | while((rv = out.lineedit("Enter new mode: ",selected, hist)) |
| 138 | == Console::RETRY); |
| 139 | if(rv <= Console::FAILURE || selected == "c") |
| 140 | return rv == Console::FAILURE ? CR_FAILURE : CR_OK; |
| 141 | const char * start = selected.c_str(); |
| 142 | char * end = 0; |
| 143 | select = strtol(start, &end, 10); |
| 144 | if(!end || end==start || select > 4) |
nothing calls this directly
no test coverage detected