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
952853aa
Commit
952853aa
authored
5 months ago
by
Max Cherris
Browse files
Options
Downloads
Patches
Plain Diff
Add function to check for Range from allied to enemy unit(s)
parent
2d37a5c8
No related branches found
No related tags found
1 merge request
!15
Merge units into main
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/unit.cpp
+16
-2
16 additions, 2 deletions
src/unit.cpp
src/unit.hpp
+8
-0
8 additions, 0 deletions
src/unit.hpp
with
24 additions
and
2 deletions
src/unit.cpp
+
16
−
2
View file @
952853aa
...
...
@@ -70,9 +70,14 @@ MatchupTabel damageMatrix = {
void
Unit
::
attack
(
Unit
&
enemy
)
{
//checks to be run:
//is unit in range?
//has unit not attacked this turn?
if
(
!
inRange
(
Unit
&
enemy
))
{
//Render enemies as not in Range
}
if
(
this
->
has_attacked
)
{
//display the unit as not able to attack (maybe greyscale?)
}
//Start Attack: choose the appropriate weapon:
int
offDamage
=
damageMatrix
[
this
->
id
][
enemy
->
id
]
*
((
this
->
health
)
/
(
this
->
max_health
));
...
...
@@ -89,4 +94,13 @@ void Unit::attack(Unit &enemy) {
}
}
void
Unit
::
inRange
(
Unit
&
enemy
)
{
if
(
this
->
x
==
enemy
.
x
)
{
return
abs
(
this
->
y
-
enemy
.
y
)
<=
this
->
range
;
}
else
if
(
this
->
y
==
enemy
.
y
)
{
return
abs
(
this
->
x
-
enemy
.
x
)
<=
this
->
range
;
}
return
false
;
}
}
// namespace advanced_wars
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/unit.hpp
+
8
−
0
View file @
952853aa
...
...
@@ -66,6 +66,14 @@ public:
void
render
(
Engine
&
engine
,
int
scale
);
/*
Check if attacker is in Range to initiate combat
TODO: This should probably tie back into rendering the units differently
If a unit is selected, it should call inRange on all other enemy units on the field
*/
bool
inRange
(
Unit
&
enemy
);
/*
The attacker will move towards the defender and thus initiate combat
@params Takes a reference to the defender
...
...
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