MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / loadGamesFromFile

Function loadGamesFromFile

plugins/mapchange/mapchange.cpp:138–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136}
137
138bool loadGamesFromFile(const char* config) {
139 endCond = eTimedGame;
140 timeLimit = 30.0 * 60.0;
141 scoreCapLimit = 10;
142
143 startTime = -1;
144 currentIndex = -1;
145 cycleMode = eLoopInf;
146
147 std::vector<std::string> lines = getFileTextLines(config);
148 if (!lines.size()) {
149 return false;
150 }
151
152 for (unsigned int i = 0; i < (unsigned int)lines.size(); i++) {
153 std::string line = lines[i];
154
155 std::vector<std::string> params = tokenize(line, std::string(","), 0, true);
156
157 if (params.size()) {
158 if (compare_nocase(params[0], "mode") == 0) {
159 if (params.size() > 1) {
160 endCond = condFromString(params[1]);
161 }
162 if (params.size() > 2) {
163 if (endCond == eTimedGame) {
164 timeLimit = fabs(atof(params[2].c_str())) * 60.0;
165 }
166 else {
167 scoreCapLimit = atoi(params[2].c_str());
168 }
169
170 if (timeLimit == 0.0) {
171 timeLimit = 30;
172 }
173
174 if (scoreCapLimit <= 0) {
175 scoreCapLimit = 10;
176 }
177 }
178
179 if (params.size() > 3) {
180 cycleMode = cycleFromString(params[3]);
181 }
182 }
183 else {
184 Game game;
185 game.mapFile = params[0];
186 if (params.size() > 1) {
187 game.publicText = params[1];
188 }
189
190 gameList.push_back(game);
191 }
192 }
193 }
194 return gameList.size() > 0;
195}

Callers 1

bz_LoadFunction · 0.85

Calls 8

condFromStringFunction · 0.85
cycleFromStringFunction · 0.85
c_strMethod · 0.80
getFileTextLinesFunction · 0.50
tokenizeFunction · 0.50
compare_nocaseFunction · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected