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
6cde609a
Commit
6cde609a
authored
5 months ago
by
Frederik
Browse files
Options
Downloads
Patches
Plain Diff
Fill recuitable units with the right values for relevant building types
parent
c21b1165
No related branches found
No related tags found
1 merge request
!22
Implement check_spawn function
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game/Building.cpp
+44
-20
44 additions, 20 deletions
src/game/Building.cpp
src/game/Building.hpp
+7
-7
7 additions, 7 deletions
src/game/Building.hpp
with
51 additions
and
27 deletions
src/game/Building.cpp
+
44
−
20
View file @
6cde609a
...
...
@@ -29,26 +29,30 @@ void Building::render(Engine& engine, int scale)
&
dst
,
0
,
NULL
,
SDL_FLIP_NONE
);
}
void
Building
::
switch_faction
(
BuildingFaction
faction
)
{
void
Building
::
switch_faction
(
BuildingFaction
faction
)
{
this
->
m_faction
=
faction
;
if
(
this
->
m_id
==
BuildingId
::
HEADQUARTER
)
{
if
(
this
->
m_id
==
BuildingId
::
HEADQUARTER
)
{
std
::
cout
<<
"The game is over!"
<<
std
::
endl
;
}
}
// implement call to UI to show available units
void
Building
::
on_click
()
{
void
Building
::
on_click
()
{
std
::
cout
<<
"A building is selected!"
<<
std
::
endl
;
};
bool
Building
::
check_spawn
(
std
::
unordered_map
<
int
,
advanced_wars
::
Unit
>&
units
)
{
bool
Building
::
check_spawn
(
std
::
unordered_map
<
int
,
advanced_wars
::
Unit
>&
units
)
{
for
(
auto
&
[
id
,
unit
]
:
units
)
{
if
(
unit
.
m_x
==
this
->
m_x
&&
unit
.
m_y
==
this
->
m_y
)
{
for
(
auto
&
[
id
,
unit
]
:
units
)
{
if
(
unit
.
m_x
==
this
->
m_x
&&
unit
.
m_y
==
this
->
m_y
)
{
return
false
;
}
}
...
...
@@ -56,28 +60,48 @@ bool Building::check_spawn(std::unordered_map<int, advanced_wars::Unit>& units)
return
true
;
}
// can be added as soon as the playerobject is available
bool
Building
::
check_money
(
int
price
)
{
bool
Building
::
check_money
(
int
price
)
{
// replace 400 with player.money and replace price with chosenUnit.price
if
(
400
>
price
)
{
if
(
400
>
price
)
{
return
false
;
}
return
true
;
}
std
::
vector
<
int
>
Building
::
recruitableUnits
()
{
std
::
vector
<
UnitId
>
Building
::
recruitableUnits
()
{
if
(
this
->
m_id
==
BuildingId
::
FACTORY
)
{
return
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
if
(
this
->
m_id
==
BuildingId
::
FACTORY
)
{
return
{
UnitId
::
INFANTERY
,
UnitId
::
MECHANIZED_INFANTERY
,
UnitId
::
RECON
,
UnitId
::
APC
,
UnitId
::
ARTILLERY
,
UnitId
::
ANTI_AIR_TANK
,
UnitId
::
ANTI_AIR_MISSILE_LAUNCHER
,
UnitId
::
ROCKET_ARTILLERY
,
UnitId
::
MEDIUM_TANK
,
UnitId
::
NEO_TANK
,
UnitId
::
HEAVY_TANK
};
}
if
(
this
->
m_id
==
BuildingId
::
PORT
)
{
return
{};
if
(
this
->
m_id
==
BuildingId
::
PORT
)
{
return
{
UnitId
::
LANDER
,
UnitId
::
CRUISER
,
UnitId
::
SUBMARINE
,
UnitId
::
BATTLESHIP
};
}
if
(
this
->
m_id
==
BuildingId
::
SATELLITE
)
{
return
{};
if
(
this
->
m_id
==
BuildingId
::
AIRPORT
)
{
return
{
UnitId
::
TRANSPORT_HELICOPTER
,
UnitId
::
BATTLE_HELICOPTER
,
UnitId
::
FIGHTER
,
UnitId
::
BOMBER
};
}
return
{};
}
}
// namespace advanced_wars
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/game/Building.hpp
+
7
−
7
View file @
6cde609a
#pragma once
#include
<unordered_map>
#include
"Engine.hpp"
#include
"Scene.hpp"
#include
"Unit.hpp"
#include
<unordered_map>
namespace
advanced_wars
{
...
...
@@ -45,7 +45,6 @@ class Building
*/
void
switch_faction
(
BuildingFaction
faction
);
/*
checks if the tile ontop of the building is free
*/
...
...
@@ -57,13 +56,14 @@ class Building
bool
check_money
(
int
price
);
/*
When the building is selected, the player should have the ability to recruit a selection of
units
They should be displayed by the UI On_click();
When the building is selected, the player should have the ability to recruit a selection of
units
They should be displayed by the UI On_click();
*/
void
recruit_unit
();
/**
If the building is clicked, it shows information to the player, here it will be a list of all available units
If the building is clicked, it shows information to the player, here it will be a list of
all available units
*/
void
on_click
();
...
...
@@ -71,7 +71,7 @@ class Building
* Provides a vector of recruitable units, depending on the building id
*
*/
std
::
vector
<
int
>
recruitableUnits
();
std
::
vector
<
UnitId
>
recruitableUnits
();
};
}
// namespace advanced_wars
\ No newline at end of file
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