Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cpp-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Maul
cpp-project
Commits
674c64d3
Commit
674c64d3
authored
5 months ago
by
TheUltimateOptimist
Browse files
Options
Downloads
Patches
Plain Diff
small refactor in loadLevel function
parent
b5f1013e
No related branches found
No related tags found
1 merge request
!43
Command Line Application for launching advanced_wars
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/game/level/Level.cpp
+13
-14
13 additions, 14 deletions
src/game/level/Level.cpp
with
13 additions
and
14 deletions
src/game/level/Level.cpp
+
13
−
14
View file @
674c64d3
...
...
@@ -82,22 +82,22 @@ std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
// if level is smaler than 20x20 surround with water tiles
if
(
width
<
20
||
height
<
20
)
{
int
w
_start
=
(
20
-
width
)
/
2
;
int
h
_start
=
(
20
-
height
)
/
2
;
int
x
_start
=
(
20
-
width
)
/
2
;
int
y
_start
=
(
20
-
height
)
/
2
;
std
::
vector
<
uint8_t
>
transformed_tiles_array
;
transformed_tiles_array
.
reserve
(
20
*
20
);
for
(
int
y
=
0
;
y
<
20
;
y
++
)
{
for
(
int
x
=
0
;
x
<
20
;
x
++
)
{
if
(
x
<
w
_start
||
y
<
h
_start
||
x
>=
w
_start
+
width
||
y
>=
h
_start
+
height
)
if
(
x
<
x
_start
||
y
<
y
_start
||
x
>=
x
_start
+
width
||
y
>=
y
_start
+
height
)
{
transformed_tiles_array
.
push_back
(
1
);
}
else
{
transformed_tiles_array
.
push_back
(
level_tilesarray
[
x
-
w
_start
+
(
y
-
h
_start
)
*
width
]);
level_tilesarray
[
x
-
x
_start
+
(
y
-
y
_start
)
*
width
]);
}
}
}
...
...
@@ -112,31 +112,31 @@ std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
std
::
vector
<
Unit
>
units
;
tiles
.
reserve
(
width
*
height
);
bool
has_factions
[]
=
{
false
,
false
,
false
,
false
,
false
};
for
(
in
t
i
=
0
;
i
<
level_tilesarray
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
level_tilesarray
.
size
();
i
++
)
{
int
x
=
i
%
width
;
int
y
=
i
/
width
;
if
(
level_tilesarray
[
i
]
>=
50
)
{
// tile id >= 50 -> building -> have to add Plain Tile and Building
tiles
.
push_back
(
Tile
(
TileId
(
TileId
::
PLAIN
),
x
,
y
));
BuildingId
building_id
=
static_cast
<
BuildingId
>
((
level_tilesarray
[
i
]
-
50
)
%
5
);
BuildingFaction
faction_id
=
static_cast
<
BuildingFaction
>
((
level_tilesarray
[
i
]
-
50
)
/
5
);
if
(
building_id
==
BuildingId
::
HEADQUARTER
)
{
int
index
=
static_cast
<
int
>
(
faction_id
);
if
(
!
has_factions
[
index
])
{
// an infantery unit should be added onto every HQ
units
.
push_back
(
Unit
(
x
,
y
,
static_cast
<
UnitFaction
>
(
faction_id
),
UnitId
::
INFANTERY
,
UnitState
::
UNAVAILABLE
,
engine
.
getUnitConfig
()));
}
has_factions
[
static_cast
<
int
>
(
faction_id
)]
=
true
;
has_factions
[
static_cast
<
int
>
(
faction_id
)]
=
true
;
// collect existing factions
// for later building turnQ
}
buildings
.
push_back
(
Building
(
x
,
y
,
building_id
,
faction_id
));
}
else
{
// if tile id belongs to terrain tile, just a tile needs to added
TileId
tile_id
=
static_cast
<
TileId
>
(
level_tilesarray
[
i
]);
tiles
.
push_back
(
Tile
(
tile_id
,
x
,
y
));
}
...
...
@@ -155,7 +155,6 @@ std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
Level
level
(
name
,
width
,
height
,
tiles
,
buildings
,
units
,
std
::
vector
<
Effect
>
{},
turnQ
);
level
.
m_turnQ
.
front
().
startTurn
(
level
.
m_units
,
level
.
m_buildings
);
std
::
cout
<<
"exiting"
<<
std
::
endl
;
return
std
::
make_shared
<
Level
>
(
level
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment