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
16f9795d
Commit
16f9795d
authored
6 months ago
by
Lorenz Martin Diel
Browse files
Options
Downloads
Patches
Plain Diff
UNAVAILABLE Units now can't move
parent
ad8c46f8
Branches
Branches containing commit
No related tags found
2 merge requests
!31
Updated unit contextmenu
,
!29
Merge main into box2d to implement physics
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game/Level.cpp
+16
-8
16 additions, 8 deletions
src/game/Level.cpp
src/game/Unit.hpp
+2
-0
2 additions, 0 deletions
src/game/Unit.hpp
with
18 additions
and
8 deletions
src/game/Level.cpp
+
16
−
8
View file @
16f9795d
...
...
@@ -593,7 +593,8 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
m_attackableUnitIds
.
clear
();
// Set Fallback_position if movement will be canceled
unit_fallback_position
=
std
::
make_pair
(
m_units
.
at
(
m_selectedUnit
).
m_x
,
m_units
.
at
(
m_selectedUnit
).
m_y
);
unit_fallback_position
=
std
::
make_pair
(
m_units
.
at
(
m_selectedUnit
).
m_x
,
m_units
.
at
(
m_selectedUnit
).
m_y
);
for
(
Unit
*
target
:
attackableTargets
)
{
...
...
@@ -613,13 +614,13 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
// Show according menu options if unit has same/different faction than current
// player
if
(
m_units
.
at
(
m_selectedUnit
).
getFaction
()
==
m_turnQ
.
front
().
getFaction
())
if
(
m_units
.
at
(
m_selectedUnit
).
getFaction
()
==
m_turnQ
.
front
().
getFaction
()
&&
m_units
.
at
(
m_selectedUnit
).
getState
()
!=
UnitState
::
UNAVAILABLE
)
{
m_contextMenu
.
setOptions
({
"Move"
,
"Attack"
,
"Info"
,
"Wait"
,
"End Turn"
});
}
else
{
m_contextMenu
.
setOptions
({
"Info"
,
"Wait"
,
"End Turn"
});
m_contextMenu
.
setOptions
({
"Info"
,
"End Turn"
});
}
}
else
...
...
@@ -629,11 +630,11 @@ void Level::handleSelectingEvents(Engine& engine, SDL_Event& event)
if
(
m_buildings
.
at
(
m_selectedBuilding
).
getFaction
()
==
static_cast
<
BuildingFaction
>
(
m_turnQ
.
front
().
getFaction
()))
{
m_contextMenu
.
setOptions
({
"Train"
,
"Info"
,
"Wait"
,
"End Turn"
});
m_contextMenu
.
setOptions
({
"Train"
,
"Info"
,
"End Turn"
});
}
else
{
m_contextMenu
.
setOptions
({
"Info"
,
"Wait"
,
"End Turn"
});
m_contextMenu
.
setOptions
({
"Info"
,
"End Turn"
});
}
}
m_state
=
LevelState
::
MENUACTIVE_STATE
;
...
...
@@ -680,9 +681,12 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
case
SDL_KEYDOWN
:
if
(
event
.
key
.
keysym
.
sym
==
SDLK_ESCAPE
)
{
if
(
m_selectedUnit
>
-
1
&&
unit_fallback_position
!=
std
::
make_pair
(
m_units
.
at
(
m_selectedUnit
).
m_x
,
m_units
.
at
(
m_selectedUnit
).
m_y
))
if
(
m_selectedUnit
>
-
1
&&
unit_fallback_position
!=
std
::
make_pair
(
m_units
.
at
(
m_selectedUnit
).
m_x
,
m_units
.
at
(
m_selectedUnit
).
m_y
))
{
m_units
.
at
(
m_selectedUnit
).
updatePosition
(
unit_fallback_position
.
first
,
unit_fallback_position
.
second
);
m_units
.
at
(
m_selectedUnit
)
.
updatePosition
(
unit_fallback_position
.
first
,
unit_fallback_position
.
second
);
}
m_selectedUnit
=
-
1
;
m_selectedBuilding
=
-
1
;
...
...
@@ -705,6 +709,10 @@ void Level::handleMenuActiveEvents(Engine& engine, SDL_Event& event)
it
->
second
.
setState
(
UnitState
::
UNAVAILABLE
);
std
::
cout
<<
"Unit state set to UNAVAILABLE."
<<
std
::
endl
;
m_state
=
LevelState
::
SELECTING_STATE
;
m_selectedUnit
=
-
1
;
m_selectedBuilding
=
-
1
;
m_showAttackableTiles
=
false
;
m_showReachableTiles
=
false
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
src/game/Unit.hpp
+
2
−
0
View file @
16f9795d
...
...
@@ -125,6 +125,8 @@ class Unit
void
setState
(
UnitState
state
);
inline
UnitState
getState
()
const
{
return
m_state
;
}
/**
* Retrieves units within range that this unit can deal damage to.
* Considers all units provided in 'allUnits', excluding itself, and checks movement and
...
...
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