Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ target_sources(taller_server
# game
game/game.cpp
game/game_phase.cpp
# shop
shop/shop.cpp
# items
items/gun.cpp
items/bomb.cpp
Expand Down Expand Up @@ -53,18 +55,18 @@ target_sources(taller_server
clock/clock.h
clock/real_clock.h
# game
game/shop.h
game/game.h
game/game_phase.h
game/game_config.h
# shop
shop/shop.h
# items
items/gun.h
items/bomb.h
items/knife.h
items/weapon.h
items/effects/effect.h
items/effects/attack_effect.h
items/items_config.h
# physics
physics/physics_system.h
physics/target_type.h
Expand All @@ -75,7 +77,6 @@ target_sources(taller_server
map/map_builder.h
# player
player/player.h
player/player_config.h
player/inventory.h
player/statuses/player_status.h
player/statuses/idle_status.h
Expand Down
100 changes: 100 additions & 0 deletions server/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
GameConfig:
max_rounds: 10
Scores:
kill: 1
win: 5
loss: 0
Bonifications:
kill: 300
win: 3000
loss: 1500

PhaseTimes:
buying_duration: 30
round_duration: 120
round_end_duration: 5

Player:
speed: 4.5
full_health: 100
initial_money: 800

ShopPrices:
Guns:
Ak47: 2700
M3: 1700
Awp: 4750
Mag:
Ak47: 80
M3: 8
Awp: 125
Glock: 20

ItemsConfig:
Glock:
bullets_per_mag: 20
init_mag_ammo: 20
init_reserve_ammo: 20
attack_rate: 6.6
dir_variation_angle: 0
bullets_per_attack: 1
burst_interval: 0
min_damage: 40
max_damage: 50
max_range: 10
precision: 0.85
falloff: 0.5
Ak47:
bullets_per_mag: 30
init_mag_ammo: 30
init_reserve_ammo: 30
attack_rate: 10
dir_variation_angle: 0
bullets_per_attack: 3
burst_interval: 0.4
min_damage: 30
max_damage: 40
max_range: 20
precision: 0.7
falloff: 0.3
M3:
bullets_per_mag: 8
init_mag_ammo: 8
init_reserve_ammo: 8
attack_rate: 1.1
dir_variation_angle: 30
bullets_per_attack: 8
burst_interval: 0
min_damage: 8
max_damage: 12
max_range: 5
precision: 0.3
falloff: 0
Awp:
bullets_per_mag: 10
init_mag_ammo: 10
init_reserve_ammo: 10
attack_rate: 0.68
dir_variation_angle: 0
bullets_per_attack: 1
burst_interval: 0
min_damage: 100
max_damage: 100
max_range: 100
precision: 1
falloff: 0
Knife:
min_damage: 10
max_damage: 20
attack_rate: 5.0
max_range: 1
precision: 1
falloff: 0
Bomb:
secs_to_plant: 3
secs_to_explode: 40
secs_to_defuse: 5
damage: 100
max_range: 15
precision: 1
falloff: 0.5
5 changes: 0 additions & 5 deletions server/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class JoinGameError: public GameError {
JoinGameError(): GameError("could not join game") {}
};

class SetReadyError: public GameError {
public:
SetReadyError(): GameError("try to set ready when playing an already started game") {}
};

class SelectTeamError: public GameError {
public:
SelectTeamError(): GameError("error at select team") {}
Expand Down
34 changes: 21 additions & 13 deletions server/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

#include "game_config.h"

Game::Game(const std::string& name, std::shared_ptr<Clock>&& game_clock, Map&& map):
Logic<GameState, GameUpdate>(
GameState(std::move(game_clock), map.get_max_players(), map.get_guns())),
Game::Game(const std::string& name, std::shared_ptr<Clock>&& game_clock, Map&& map,
GameConfig&& config):
Logic<GameState, GameUpdate>(GameState(std::move(game_clock), map.get_max_players(),
map.get_guns(), std::move(config))),
name(name),
shop(state.get_config().shop_prices),
physics_system(std::move(map), state.get_players(), state.get_dropped_guns(),
state.get_bomb()) {}

Expand Down Expand Up @@ -68,7 +70,7 @@ void Game::advance_round_logic() {
}
}

if (!phase.is_game_end() && state.get_num_rounds() == GameConfig::max_rounds) {
if (!phase.is_game_end() && state.get_num_rounds() == state.get_config().max_rounds) {
phase.end_game();
broadcast(Message(ScoreboardResponse(state.get_scoreboard())));
}
Expand Down Expand Up @@ -102,10 +104,14 @@ void Game::advance_bomb_logic() {
}

auto& bomb = state.get_bomb().value();
bool bomb_was_defused = bomb.item.is_defused();
bomb.item.advance(state.get_phase().get_time_now());

if (bomb.item.is_defused())
if (!bomb_was_defused && bomb.item.is_defused()) {
for (const auto& [_, player]: state.get_players())
player->handle_stop_defusing(bomb.item, state.get_phase().get_time_now());
return;
}

if (!bomb.item.should_explode())
return;
Expand Down Expand Up @@ -157,7 +163,8 @@ bool Game::apply_attack_effect(const std::unique_ptr<Player>& attacker, const Ef
bool is_hit = effect.apply(target_player);
if (target_player->is_dead()) {
attacker->add_kill();
attacker->add_rewards(Scores::kill, Bonifications::kill);
attacker->add_rewards(state.get_config().scores.kill,
state.get_config().bonifications.kill);
auto gun = target_player->drop_primary_weapon();
if (gun.has_value())
state.add_dropped_gun(std::move(gun.value()), target_player->get_hitbox().center);
Expand Down Expand Up @@ -229,11 +236,11 @@ template <>
void Game::handle<SetReadyCommand>(const std::string& player_name,
[[maybe_unused]] const SetReadyCommand& msg) {
if (state.get_phase().is_playing())
throw SetReadyError();
return;

state.get_player(player_name)->set_ready();
if (state.all_players_ready()) {
give_bomb_to_random_tt(Bomb());
give_bomb_to_random_tt(Bomb(state.get_config().items_config.bomb));
state.get_phase().start_game();
for (const auto& [_, player]: state.get_players()) // cppcheck-suppress[unusedVariable]
move_player_to_spawn(player);
Expand All @@ -259,7 +266,8 @@ void Game::handle<BuyGunCommand>(const std::string& player_name, const BuyGunCom
auto gun = player->drop_primary_weapon();
if (gun.has_value())
state.add_dropped_gun(std::move(gun.value()), player->get_hitbox().center);
shop.buy_gun(msg.get_gun(), player->get_inventory());
shop.buy_gun(msg.get_gun(), player->get_inventory(),
state.get_config().items_config.get_gun_config(msg.get_gun()));
}

template <>
Expand Down Expand Up @@ -408,12 +416,12 @@ void Game::handle_msg(const Message& msg, const std::string& player_name) {
float Game::get_tick_duration() {
TimePoint now = state.get_phase().get_time_now();
if (last_tick == TimePoint()) {
return 1.0f / GameConfig::tickrate;
return 1.0f / TICKRATE;
} else {
if (now < last_tick)
last_tick = now;
if (last_tick == now) {
return 1.0f / GameConfig::tickrate;
return 1.0f / TICKRATE;
} else {
float elapsed = std::chrono::duration<float>(now - last_tick).count();
return elapsed;
Expand Down Expand Up @@ -446,7 +454,7 @@ void Game::prepare_new_round() {
if (bomb.has_value())
state.add_bomb(std::move(bomb.value()), player->get_hitbox().center);
}
if (state.get_num_rounds() == GameConfig::max_rounds / 2) {
if (state.get_num_rounds() == state.get_config().max_rounds / 2) {
state.swap_players_teams();
broadcast(Message(SwapTeamsResponse()));
}
Expand All @@ -455,7 +463,7 @@ void Game::prepare_new_round() {
state.get_bomb().value().item.reset();
give_bomb_to_random_tt(std::move(state.remove_bomb()));
} else {
give_bomb_to_random_tt(Bomb());
give_bomb_to_random_tt(Bomb(state.get_config().items_config.bomb));
}
state.get_dropped_guns().clear();
}
Expand Down
5 changes: 3 additions & 2 deletions server/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "server/physics/physics_system.h"
#include "server/player/player.h"
#include "server/player_message.h"
#include "server/shop/shop.h"
#include "server/states/game_state.h"

#include "game_phase.h"
#include "shop.h"

class Game: public Logic<GameState, GameUpdate> {
private:
Expand All @@ -29,7 +29,8 @@ class Game: public Logic<GameState, GameUpdate> {
std::vector<PlayerMessage> output_messages;

public:
Game(const std::string& name, std::shared_ptr<Clock>&& game_clock, Map&& map);
Game(const std::string& name, std::shared_ptr<Clock>&& game_clock, Map&& map,
GameConfig&& config);

Game(const Game&) = delete;
Game& operator=(const Game&) = delete;
Expand Down
Loading