From ad7d34f2cf7cc96341c82b01b068afeaf88f485c Mon Sep 17 00:00:00 2001 From: pwalig Date: Wed, 25 Dec 2024 10:08:43 +0100 Subject: [PATCH 1/3] Add requested information to messages --- README.md | 8 ++++---- src/rts/game.cpp | 7 +++++-- src/rts/unit.cpp | 8 +++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 38fc801..78e43f0 100644 --- a/README.md +++ b/README.md @@ -80,16 +80,16 @@ Some messages consist of only type character others contain more data. - `j` `` `\n` - new player has joined the game room - `l` `` `\n` - player `` has either left or lost the game - `m` `` ` ` `` ` ` `` `\n` - unit of id `` has moved to `;` -- `a` `` ` ` `` `\n` - unit of id `` attacked unit of id `` -- `d` `` `\n` - unit of id `` mined a resource +- `a` `` ` ` `` ` ` `` `\n` - unit of id `` attacked unit of id `` and target unit has now `` hp left +- `d` `` ` ` `` `\n` - unit of id `` mined a resource and resource has now `` hp left - `u` `` ` ` `` ` ` `` ` ` `` - player `` has aquired unit of id `` on field `;` - `f` `` ` ` `` ` ` `` `\n` - new resource spawned on field `;` - `t` `\n` - sent to all players in game room in regular time intervals, marks the and of each tick and a start of the next one - `q` `\n` - player was sent to queue (in response to: `j`) - `y` `\n` - client request accepted (in response to: `n`) - `n` `\n` - client request denied (in response to: `j` or `n`) -- `L` `\n` - client lost the game (and was moved out of game room) -- `W` `\n` - client won the game (and was moved out of game room) +- `L` `` `\n` - client lost the game (and was moved out of game room), `` is the name of the player who won +- `W` `` `\n` - client won the game (and was moved out of game room), `` is the name of the player who won ### Board state message diff --git a/src/rts/game.cpp b/src/rts/game.cpp index ac29ac2..99591d3 100644 --- a/src/rts/game.cpp +++ b/src/rts/game.cpp @@ -237,9 +237,12 @@ void rts::game::playerLostAllUnits(player* pl) { void rts::game::tryWin(player* pl){ if (pl->units.size() >= unitsToWin) { - pl->getClient()->sendToClient({'W','\n'}); + std::vector buff = {'W'}; + message::appendStringWDelim(buff, pl->getName(), '\n'); + pl->getClient()->sendToClient(buff); + buff[0] = 'L'; for (player* p : activePlayers){ - if (p != pl) p->getClient()->sendToClient({'L','\n'}); + if (p != pl) p->getClient()->sendToClient(buff); } clearRoom(); diff --git a/src/rts/unit.cpp b/src/rts/unit.cpp index a47f08d..5ed561a 100644 --- a/src/rts/unit.cpp +++ b/src/rts/unit.cpp @@ -21,12 +21,13 @@ rts::unit::unit(player* owner_, field* field_, unsigned int id_) : void rts::unit::mine(){ if (!movedThisRound && f->hasResource()) { + f->mine(owner->getGame()->getUnitDamage()); std::vector buff = {'d'}; - message::appendNumberWDelim(buff, id, '\n'); + message::appendNumberWDelim(buff, id, ' '); + message::appendNumberWDelim(buff, std::max(f->getHp(), 0), '\n'); owner->getGame()->sendToPlayers(buff); - f->mine(owner->getGame()->getUnitDamage()); if (f->getHp() <= 0) { field* nf = owner->getGame()->_board.closestEmptyField(f); if (nf) owner->newUnit(nf); @@ -56,7 +57,8 @@ void rts::unit::attack(unit* target){ std::vector buff = {'a'}; message::appendNumberWDelim(buff, id, ' '); - message::appendNumberWDelim(buff, target->id, '\n'); + message::appendNumberWDelim(buff, target->id, ' '); + message::appendNumberWDelim(buff, target->hp - owner->getGame()->getUnitDamage(), '\n'); owner->getGame()->sendToPlayers(buff); target->recvDamage(owner->getGame()->getUnitDamage()); From 30701ad0a7f2289e1dc19bf88eeb7da0baa5916d Mon Sep 17 00:00:00 2001 From: pwalig Date: Wed, 25 Dec 2024 10:30:02 +0100 Subject: [PATCH 2/3] Fix hp in d message --- src/rts/unit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rts/unit.cpp b/src/rts/unit.cpp index 7eda17b..83c9283 100644 --- a/src/rts/unit.cpp +++ b/src/rts/unit.cpp @@ -25,7 +25,7 @@ void rts::unit::mine(){ std::vector buff = {'d'}; message::appendNumberWDelim(buff, id, ' '); - message::appendNumberWDelim(buff, std::max(f->getHp(), 0), '\n'); + message::appendNumberWDelim(buff, f->getHp(), '\n'); owner->getGame()->sendToPlayers(buff); if (f->getHp() <= 0) { From c9f3fbaa5b4de853e4fe5bde0787910e82928124 Mon Sep 17 00:00:00 2001 From: pwalig Date: Tue, 7 Jan 2025 15:27:49 +0100 Subject: [PATCH 3/3] Change message sent to player that lost all units --- src/rts/game.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rts/game.cpp b/src/rts/game.cpp index 99591d3..6d6eca9 100644 --- a/src/rts/game.cpp +++ b/src/rts/game.cpp @@ -231,7 +231,9 @@ void rts::game::deletePlayer(player* pl){ void rts::game::playerLostAllUnits(player* pl) { assert(pl); assert(activePlayers.find(pl) != activePlayers.end()); - pl->getClient()->sendToClient({'L','\n'}); + std::vector buff = {'l'}; + message::appendStringWDelim(buff, pl->getName(), '\n'); + pl->getClient()->sendToClient(buff); removePlayerFromRoomOrQueue(pl); }