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
a7dc2126
Commit
a7dc2126
authored
6 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Add building capture feature
parent
71bdbd13
Branches
Branches containing commit
No related tags found
2 merge requests
!34
Building features
,
!29
Merge main into box2d to implement physics
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/game/Level.cpp
+24
-2
24 additions, 2 deletions
src/game/Level.cpp
src/game/Level.hpp
+1
-0
1 addition, 0 deletions
src/game/Level.hpp
src/game/Unit.cpp
+8
-0
8 additions, 0 deletions
src/game/Unit.cpp
src/game/Unit.hpp
+3
-0
3 additions, 0 deletions
src/game/Unit.hpp
with
36 additions
and
2 deletions
src/game/Level.cpp
+
24
−
2
View file @
a7dc2126
...
...
@@ -596,7 +596,21 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
}
}
m_contextMenu
.
setOptions
({
"Move"
,
"Attack"
,
"Info"
,
"Wait"
});
Unit
&
u
=
m_units
.
at
(
m_selectedUnit
);
if
(
u
.
hasMoved
())
{
m_contextMenu
.
setOptions
({
"Attack"
,
"Info"
,
"Wait"
});
}
else
{
for
(
auto
&
[
id
,
building
]
:
m_buildings
)
{
if
(
building
.
m_x
==
u
.
m_x
&&
building
.
m_y
==
u
.
m_y
)
{
m_contextMenu
.
setOptions
({
"Capture"
,
"Move"
,
"Attack"
,
"Info"
,
"Wait"
});
m_captureBuilding
=
id
;
break
;
}
}
}
}
else
{
...
...
@@ -703,6 +717,14 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
m_recruitingMenu
.
setOptions
(
m_buildings
.
at
(
m_selectedBuilding
).
recruitableUnits
());
std
::
cout
<<
"no training here"
<<
std
::
endl
;
}
if
(
cmd
==
"Capture"
)
{
Building
&
b
=
m_buildings
.
at
(
m_captureBuilding
);
UnitFaction
u_f
=
m_units
.
at
(
m_selectedUnit
).
getFaction
();
BuildingFaction
b_f
=
static_cast
<
BuildingFaction
>
(
static_cast
<
int
>
(
u_f
));
b
.
switch_faction
(
b_f
);
}
}
break
;
...
...
This diff is collapsed.
Click to expand it.
src/game/Level.hpp
+
1
−
0
View file @
a7dc2126
...
...
@@ -133,6 +133,7 @@ class Level : public Scene
int
m_selectedUnit
;
int
m_selectedBuilding
;
int
m_captureBuilding
;
ContextMenu
m_contextMenu
;
RecruitingMenu
m_recruitingMenu
;
int
m_id
;
...
...
This diff is collapsed.
Click to expand it.
src/game/Unit.cpp
+
8
−
0
View file @
a7dc2126
...
...
@@ -324,4 +324,12 @@ void Unit::setState(UnitState state)
this
->
m_state
=
state
;
}
bool
Unit
::
hasAttacked
()
{
return
this
->
m_hasAttacked
;
}
bool
Unit
::
hasMoved
()
{
return
this
->
m_hasMoved
;
}
}
// namespace advanced_wars
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/game/Unit.hpp
+
3
−
0
View file @
a7dc2126
...
...
@@ -135,6 +135,9 @@ class Unit
*/
std
::
vector
<
Unit
*>
getUnitsInRangeWithDamagePotential
(
const
std
::
vector
<
Unit
*>&
allUnits
);
bool
hasMoved
();
bool
hasAttacked
();
private
:
UnitFaction
m_faction
;
// The faction to which this unit belongs.
UnitId
m_id
;
// The identifier for the unit type.
...
...
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