Skip to content

Commit

Permalink
Merge branch 'dev' into gd-client-demands
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalig committed Dec 25, 2024
2 parents ad7d34f + cad5190 commit 74a6996
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/rts/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ rts::field* rts::field::spawnResource(unsigned int hp) {
return this;
}

rts::field* rts::field::mine(int dmg) {
resourceHp -= dmg;
rts::field* rts::field::mine(unsigned int dmg) {
if (dmg >= resourceHp) resourceHp = 0;
else resourceHp -= dmg;
return this;
}

int rts::field::getHp() const {
unsigned int rts::field::getHp() const {
return resourceHp;
}

Expand Down
6 changes: 3 additions & 3 deletions src/rts/field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace rts {
class unit;

class field {
int resourceHp = 0;
unsigned int resourceHp = 0;

public:
field(const unsigned int& xpos, const unsigned int& ypos);
Expand All @@ -16,9 +16,9 @@ namespace rts {
rts::field* spawnResource(unsigned int hp);

// @returns this field
rts::field* mine(int dmg);
rts::field* mine(unsigned int dmg);

int getHp() const;
unsigned int getHp() const;

unsigned int distance(const field& other) const;

Expand Down
3 changes: 2 additions & 1 deletion src/rts/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void rts::unit::attack(unit* target){
}

void rts::unit::recvDamage(unsigned int dmg){
hp -= dmg;
if (dmg >= hp) hp = 0;
else hp -= dmg;
if (hp <= 0) {
owner->units.erase(this);
if (owner->units.empty()) {
Expand Down

0 comments on commit 74a6996

Please sign in to comment.