-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgridmap.cpp
56 lines (41 loc) · 1.37 KB
/
gridmap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2015 FMAW
#include <iostream>
#include <fstream>
#include <string>
#include "./FMAW.h"
#include "./grid.h"
#include "./gridmap.h"
#include "./unit.h"
namespace GridMap {
void loadDefaultGridMap(Grid *g) {
loadGridMap("defaultMap", g);
}
void loadGridMap(std::string mapName, Grid *g) {
FILE *test = FMAW::IO::fopen(("./maps/" + mapName).c_str(), "r");
if (test != NULL) {
int rows, cols, aux;
FMAW::IO::fscanf(test, "%d %d\n", &rows, &cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
if (col < cols - 1) {
FMAW::IO::fscanf(test, "%d ", &aux);
} else {
FMAW::IO::fscanf(test, "%d\n", &aux);
}
IndexPath path {row, col};
g->cellAtIndexPath(path)->setBackgroundType(
static_cast<CellBackgroundType>(aux));
g->cellAtIndexPath(path)->renderBackground();
}
}
FMAW::IO::fscanf(test, "\n");
int owner, unitType, posx, posy;
while (fscanf(test, "%d %d (%d, %d)", &owner, &unitType, &posx, &posy) != EOF) {
Unit *u = Unit::UnitWithType(unitType, owner-1);
g->cellAtIndexPath({posx-1, posy-1})->setCharacter(u);
}
g->resetUnitMovements();
FMAW::IO::fclose(test);
}
}
} // namespace GridMap