* Get the minimal and maximal values of a historic graph. * @param historyType Type of history information. @see HistoryType * @param historyScale Scale of history data. @see HistoryScale * @param minValResult Pointer to variable to write minimal value to. * @param maxValResult Pointer to variable to write maximal value to. */
| 205 | * @param maxValResult Pointer to variable to write maximal value to. |
| 206 | */ |
| 207 | void Micropolis::getHistoryRange(int historyType, int historyScale, |
| 208 | short *minValResult, short *maxValResult) |
| 209 | { |
| 210 | if (historyType < 0 || historyType >= HISTORY_TYPE_COUNT |
| 211 | || historyScale < 0 || historyScale >= HISTORY_SCALE_COUNT) { |
| 212 | *minValResult = 0; |
| 213 | *maxValResult = 0; |
| 214 | return; |
| 215 | } |
| 216 | |
| 217 | short *history = NULL; |
| 218 | switch (historyType) { |
| 219 | case HISTORY_TYPE_RES: |
| 220 | history = resHist; |
| 221 | break; |
| 222 | case HISTORY_TYPE_COM: |
| 223 | history = comHist; |
| 224 | break; |
| 225 | case HISTORY_TYPE_IND: |
| 226 | history = indHist; |
| 227 | break; |
| 228 | case HISTORY_TYPE_MONEY: |
| 229 | history = moneyHist; |
| 230 | break; |
| 231 | case HISTORY_TYPE_CRIME: |
| 232 | history = crimeHist; |
| 233 | break; |
| 234 | case HISTORY_TYPE_POLLUTION: |
| 235 | history = pollutionHist; |
| 236 | break; |
| 237 | default: |
| 238 | NOT_REACHED(); |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | int offset = 0; |
| 243 | switch (historyScale) { |
| 244 | case HISTORY_SCALE_SHORT: |
| 245 | offset = 0; |
| 246 | break; |
| 247 | case HISTORY_SCALE_LONG: |
| 248 | offset = 120; |
| 249 | break; |
| 250 | default: |
| 251 | NOT_REACHED(); |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | short minVal = 32000; |
| 256 | short maxVal = -32000; |
| 257 | |
| 258 | for (int i = 0; i < HISTORY_COUNT; i++) { |
| 259 | short val = history[i + offset]; |
| 260 | |
| 261 | minVal = min(val, minVal); |
| 262 | maxVal = max(val, maxVal); |
| 263 | } |
| 264 |