Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
batajelo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
batajelo
Commits
f8eac096
Commit
f8eac096
authored
Dec 11, 2014
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement the concept of entity team
parent
b50535a3
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
141 additions
and
23 deletions
+141
-23
src/game/game.cpp
src/game/game.cpp
+3
-3
src/game/game.hpp
src/game/game.hpp
+2
-1
src/game/game_client.cpp
src/game/game_client.cpp
+8
-2
src/game/game_client.hpp
src/game/game_client.hpp
+3
-1
src/game/game_server.cpp
src/game/game_server.cpp
+24
-6
src/game/game_server.hpp
src/game/game_server.hpp
+1
-1
src/game/occupant.cpp
src/game/occupant.cpp
+13
-1
src/game/occupant.hpp
src/game/occupant.hpp
+4
-1
src/gui/sprites/pic_sprite.cpp
src/gui/sprites/pic_sprite.cpp
+4
-1
src/gui/sprites/unit_sprite.cpp
src/gui/sprites/unit_sprite.cpp
+4
-2
src/gui/sprites/unit_sprite.hpp
src/gui/sprites/unit_sprite.hpp
+5
-2
src/world/components.hpp
src/world/components.hpp
+1
-0
src/world/entity_factory.cpp
src/world/entity_factory.cpp
+4
-0
src/world/team.cpp
src/world/team.cpp
+27
-0
src/world/team.hpp
src/world/team.hpp
+31
-0
src/world/world.cpp
src/world/world.cpp
+6
-1
src/world/world.hpp
src/world/world.hpp
+1
-1
No files found.
src/game/game.cpp
View file @
f8eac096
...
...
@@ -26,7 +26,7 @@ void Game::new_unit_callback(Message* message)
Position
pos
;
pos
.
x
.
raw
()
=
srl
.
pos
().
x
();
pos
.
y
.
raw
()
=
srl
.
pos
().
y
();
this
->
turn_handler
.
insert_action
(
std
::
bind
(
&
Game
::
do_new_unit
,
this
,
srl
.
type_id
(),
pos
),
this
->
turn_handler
.
insert_action
(
std
::
bind
(
&
Game
::
do_new_unit
,
this
,
srl
.
type_id
(),
pos
,
srl
.
team
()
),
srl
.
turn
());
}
...
...
@@ -52,8 +52,8 @@ void Game::move_callback(Message* message)
srl
.
turn
());
}
void
Game
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
)
void
Game
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
)
{
log_debug
(
"Game::do_new_unit"
);
this
->
world
.
do_new_unit
(
type
,
pos
);
this
->
world
.
do_new_unit
(
type
,
pos
,
team
);
}
src/game/game.hpp
View file @
f8eac096
...
...
@@ -18,7 +18,8 @@ public:
void
new_unit_callback
(
Message
*
msg
);
void
move_callback
(
Message
*
msg
);
virtual
void
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
);
virtual
void
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
);
protected:
World
world
;
...
...
src/game/game_client.cpp
View file @
f8eac096
...
...
@@ -211,6 +211,12 @@ void GameClient::handle_start_message(Message* message)
// this->world.start();
}
void
GameClient
::
set_self_team
(
const
uint16_t
team
)
{
log_debug
(
"Our team is number: "
<<
team
);
this
->
team
=
team
;
}
void
GameClient
::
turn_callback
(
Message
*
)
{
log_debug
(
"GameClient::turn_callback"
);
...
...
@@ -279,9 +285,9 @@ void GameClient::spawn_callback(Message* message)
{
}
void
GameClient
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
)
void
GameClient
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
)
{
Unit
*
unit
=
this
->
world
.
do_new_unit
(
type
,
pos
);
Unit
*
unit
=
this
->
world
.
do_new_unit
(
type
,
pos
,
team
);
this
->
camera
.
on_new_unit
(
unit
);
}
...
...
src/game/game_client.hpp
View file @
f8eac096
...
...
@@ -29,7 +29,7 @@ public:
void
add_new_occupant
(
std
::
unique_ptr
<
Occupant
>&&
occupant
);
void
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
)
override
final
;
void
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
)
override
final
;
void
send_message
(
const
char
*
name
,
const
google
::
protobuf
::
Message
&
msg
);
void
send_message
(
const
char
*
name
,
const
std
::
string
&
archive
);
...
...
@@ -122,6 +122,7 @@ public:
return
&
this
->
current_selection
;
}
void
add_selection_change_callback
(
const
t_selection_changed_callback
);
void
set_self_team
(
const
uint16_t
team
);
private:
/**
...
...
@@ -138,6 +139,7 @@ private:
Camera
camera
;
Hud
hud
;
DebugHud
debug_hud
;
uint16_t
team
;
GameClient
(
const
GameClient
&
)
=
delete
;
GameClient
(
GameClient
&&
)
=
delete
;
...
...
src/game/game_server.cpp
View file @
f8eac096
...
...
@@ -32,6 +32,22 @@ void GameServer::on_new_client(RemoteGameClient* new_client)
message
->
set_name
(
"NEW_OCCUPANT"
);
auto
new_occupant
=
std
::
make_unique
<
Occupant
>
(
new_client
->
get_id
(),
"coucou"
);
// Get the first team not already taken by an other occupant
uint16_t
team
;
for
(
team
=
1
;;
team
++
)
{
bool
res
=
std
::
none_of
(
this
->
occupants_handler
.
begin
(),
this
->
occupants_handler
.
end
(),
[
team
](
const
auto
&
occupant
)
{
return
occupant
->
get_team
()
==
team
;
});
if
(
res
)
break
;
}
new_occupant
->
set_team
(
team
);
message
->
set_body
(
new_occupant
->
serialize
());
this
->
send_to_all_clients
(
message
);
...
...
@@ -135,10 +151,10 @@ void GameServer::tick()
void
GameServer
::
start_game
()
{
this
->
send_new_unit_order
(
0
,
{
300
,
300
});
this
->
send_new_unit_order
(
0
,
{
400
,
800.12
});
this
->
send_new_unit_order
(
0
,
{
500
,
500
});
this
->
send_new_unit_order
(
0
,
{
320
,
610
});
this
->
send_new_unit_order
(
0
,
{
300
,
300
}
,
1
);
this
->
send_new_unit_order
(
0
,
{
400
,
800.12
}
,
1
);
this
->
send_new_unit_order
(
0
,
{
500
,
500
}
,
2
);
this
->
send_new_unit_order
(
0
,
{
320
,
610
}
,
2
);
this
->
turn_handler
.
mark_turn_as_ready
();
}
...
...
@@ -217,15 +233,17 @@ void GameServer::on_move_request(Message* message)
this
->
send_move_order
(
ids
,
pos
,
srl
.
queue
());
}
void
GameServer
::
send_new_unit_order
(
const
EntityType
type
,
const
Position
&
pos
)
void
GameServer
::
send_new_unit_order
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
)
{
ser
::
order
::
NewUnit
srl
;
srl
.
set_turn
(
this
->
turn_handler
.
get_current_turn
()
+
2
);
srl
.
set_type_id
(
type
);
srl
.
mutable_pos
()
->
set_x
(
pos
.
x
.
raw
());
srl
.
mutable_pos
()
->
set_y
(
pos
.
y
.
raw
());
srl
.
set_team
(
team
);
this
->
send_order_to_all
(
"NEW_UNIT"
,
srl
);
this
->
turn_handler
.
insert_action
(
std
::
bind
(
&
World
::
do_new_unit
,
&
this
->
world
,
type
,
pos
),
this
->
turn_handler
.
insert_action
(
std
::
bind
(
&
World
::
do_new_unit
,
&
this
->
world
,
type
,
pos
,
team
),
srl
.
turn
());
}
...
...
src/game/game_server.hpp
View file @
f8eac096
...
...
@@ -67,7 +67,7 @@ public:
*/
void
on_next_turn
(
const
TurnNb
nb
);
void
send_new_unit_order
(
const
EntityType
type
,
const
Position
&
pos
);
void
send_new_unit_order
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
);
void
send_move_order
(
const
std
::
vector
<
EntityId
>
ids
,
const
Position
&
pos
,
const
bool
queue
);
/**
* This will create the initial game
...
...
src/game/occupant.cpp
View file @
f8eac096
...
...
@@ -8,7 +8,8 @@ Occupant::Occupant(uint32_t id, const std::string& name):
Occupant
::
Occupant
(
const
ser
::
game
::
Occupant
&
srl
)
:
id
(
srl
.
id
()),
name
(
srl
.
name
())
name
(
srl
.
name
()),
team
(
srl
.
team
())
{
}
...
...
@@ -16,11 +17,22 @@ Occupant::~Occupant()
{
}
void
Occupant
::
set_team
(
const
uint16_t
team
)
{
this
->
team
=
team
;
}
uint16_t
Occupant
::
get_team
()
const
{
return
this
->
team
;
}
ser
::
game
::
Occupant
Occupant
::
serialize
()
const
{
ser
::
game
::
Occupant
srlzed
;
srlzed
.
set_id
(
this
->
id
);
srlzed
.
set_name
(
this
->
name
);
srlzed
.
set_team
(
this
->
team
);
return
srlzed
;
}
src/game/occupant.hpp
View file @
f8eac096
...
...
@@ -18,10 +18,13 @@ public:
Occupant
(
const
ser
::
game
::
Occupant
&
srl
);
~
Occupant
();
void
set_team
(
const
uint16_t
team
);
uint16_t
get_team
()
const
;
ser
::
game
::
Occupant
serialize
()
const
;
uint32_t
id
;
in
t
team
;
uint16_
t
team
;
std
::
string
name
;
private:
...
...
src/gui/sprites/pic_sprite.cpp
View file @
f8eac096
...
...
@@ -5,6 +5,7 @@
#include <world/unit.hpp>
#include <world/health.hpp>
#include <world/mana.hpp>
#include <world/team.hpp>
PicpicSprite
::
PicpicSprite
(
const
Unit
*
const
unit
)
:
UnitSprite
(
unit
),
...
...
@@ -23,7 +24,9 @@ PicpicSprite::PicpicSprite(const Unit* const unit):
void
PicpicSprite
::
draw
(
GameClient
*
game
)
const
{
this
->
draw_shadow
(
game
->
get_camera
());
Team
*
team
=
this
->
unit
->
get
<
Team
>
();
assert
(
team
);
this
->
draw_shadow
(
game
->
get_camera
(),
this
->
team_colors
[
team
->
get
()]);
const
auto
entpos
=
game
->
get_camera
().
world_to_camera_position
(
this
->
unit
->
pos
);
const
int
x
=
entpos
.
x
-
game
->
get_camera
().
x
;
...
...
src/gui/sprites/unit_sprite.cpp
View file @
f8eac096
...
...
@@ -3,6 +3,9 @@
sf
::
Texture
UnitSprite
::
shadow_texture
;
bool
UnitSprite
::
init
=
false
;
const
std
::
vector
<
sf
::
Color
>
UnitSprite
::
team_colors
=
{
sf
::
Color
::
White
,
sf
::
Color
::
Red
,
sf
::
Color
::
Blue
};
UnitSprite
::
UnitSprite
(
const
Unit
*
const
unit
)
:
unit
(
unit
)
...
...
@@ -15,7 +18,7 @@ UnitSprite::UnitSprite(const Unit* const unit):
}
}
void
UnitSprite
::
draw_shadow
(
Camera
&
camera
)
const
void
UnitSprite
::
draw_shadow
(
Camera
&
camera
,
const
sf
::
Color
color
)
const
{
const
auto
entpos
=
camera
.
world_to_camera_position
(
this
->
unit
->
pos
);
const
int
x
=
entpos
.
x
-
camera
.
x
;
...
...
@@ -24,7 +27,6 @@ void UnitSprite::draw_shadow(Camera& camera) const
sf
::
Sprite
sprite
(
UnitSprite
::
shadow_texture
);
sprite
.
setPosition
(
x
-
size
.
x
/
2
,
y
-
size
.
y
/
2
);
const
sf
::
Color
color
(
255
,
255
,
255
,
122
);
sprite
.
setColor
(
color
);
camera
.
draw
(
sprite
);
}
...
...
src/gui/sprites/unit_sprite.hpp
View file @
f8eac096
...
...
@@ -4,6 +4,8 @@
#include <gui/sprites/world_sprite.hpp>
#include <gui/camera/camera.hpp>
#include <vector>
class
Unit
;
class
UnitSprite
:
public
WorldSprite
...
...
@@ -16,11 +18,12 @@ public:
protected:
const
Unit
*
const
unit
;
void
draw_shadow
(
Camera
&
camera
)
const
;
void
draw_shadow
(
Camera
&
camera
,
const
sf
::
Color
color
)
const
;
static
const
std
::
vector
<
sf
::
Color
>
team_colors
;
private:
static
sf
::
Texture
shadow_texture
;
static
bool
init
;
static
sf
::
Texture
shadow_texture
;
UnitSprite
(
const
UnitSprite
&
);
UnitSprite
&
operator
=
(
const
UnitSprite
&
);
...
...
src/world/components.hpp
View file @
f8eac096
...
...
@@ -11,6 +11,7 @@ enum class ComponentType
Health
,
Mana
,
Vision
,
Team
,
};
class
Component
...
...
src/world/entity_factory.cpp
View file @
f8eac096
...
...
@@ -2,6 +2,7 @@
#include <world/health.hpp>
#include <world/mana.hpp>
#include <world/vision.hpp>
#include <world/team.hpp>
EntityFactory
::
EntityFactory
()
{
...
...
@@ -26,6 +27,9 @@ std::unique_ptr<Unit> EntityFactory::make_unit(const EntityType type)
res
->
add_component
(
std
::
make_unique
<
Health
>
(
100
));
res
->
add_component
(
std
::
make_unique
<
Mana
>
(
300
));
res
->
add_component
(
std
::
make_unique
<
Vision
>
(
700
,
false
));
res
->
add_component
(
std
::
make_unique
<
Team
>
());
// return std::make_unique<Unit>(this->unit_models[type]);
return
res
;
}
src/world/team.cpp
0 → 100644
View file @
f8eac096
#include <world/team.hpp>
const
ComponentType
Team
::
component_type
;
Team
::
Team
(
const
Team
::
type
number
)
:
number
(
number
)
{
}
Team
::
Team
()
:
number
(
0
)
{
}
Team
::
type
Team
::
get
()
const
{
return
this
->
number
;
}
void
Team
::
set
(
const
Team
::
type
number
)
{
this
->
number
=
number
;
}
void
Team
::
tick
(
Entity
*
entity
,
World
*
world
)
{
}
src/world/team.hpp
0 → 100644
View file @
f8eac096
#ifndef TEAM_COMPONENT_HPP_INCLUDED
#define TEAM_COMPONENT_HPP_INCLUDED
#include <cstdint>
#include <world/components.hpp>
class
Team
:
public
Component
{
public:
static
const
ComponentType
component_type
=
ComponentType
::
Team
;
using
type
=
uint8_t
;
Team
(
const
type
number
);
Team
();
~
Team
()
=
default
;
type
get
()
const
;
void
set
(
const
type
number
);
void
tick
(
Entity
*
entity
,
World
*
world
)
override
final
;
private:
type
number
;
Team
(
const
Team
&
)
=
delete
;
Team
(
Team
&&
)
=
delete
;
Team
&
operator
=
(
const
Team
&
)
=
delete
;
Team
&
operator
=
(
Team
&&
)
=
delete
;
};
#endif
/* TEAM_COMPONENT_HPP_INCLUDED */
src/world/world.cpp
View file @
f8eac096
...
...
@@ -3,6 +3,7 @@
#include <world/path.hpp>
#include <world/work.hpp>
#include <world/health.hpp>
#include <world/team.hpp>
World
::
World
()
{
...
...
@@ -57,10 +58,14 @@ Path World::calculate_path(Position endpos, Unit* unit)
return
{};
}
Unit
*
World
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
)
Unit
*
World
::
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team_value
)
{
auto
entity
=
this
->
entity_factory
.
make_unit
(
type
);
entity
->
pos
=
pos
;
Team
*
team
=
entity
->
get
<
Team
>
();
assert
(
team
);
team
->
set
(
team_value
);
auto
res
=
entity
.
get
();
this
->
insert_unit
(
std
::
move
(
entity
));
return
res
;
...
...
src/world/world.hpp
View file @
f8eac096
...
...
@@ -69,7 +69,7 @@ public:
void
pause
();
void
unpause
();
Path
calculate_path
(
Position
,
Unit
*
);
Unit
*
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
);
Unit
*
do_new_unit
(
const
EntityType
type
,
const
Position
&
pos
,
const
uint16_t
team
);
void
do_move
(
const
std
::
vector
<
EntityId
>
ids
,
const
Position
&
pos
,
const
bool
queue
);
// void do_path(ActionEvent*);
// void do_new_unit(ActionEvent*);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment