这是indexloc提供的服务,不要输入任何密码
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
29 changes: 29 additions & 0 deletions doc/reverse_engineering/repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Repair

Buildings, siege weapons and ships can be repaired by villagers.

## Speed

Buildings are repaired at the base repairing speed of **750 hp/min** which is not affected by the total hp of the building/unit.

Siege weapons and ships are repaired at **25%** of the base speed (188 hp/min).

After the first villager, each villager repairs at **50%** of the base speed (375 hp/min for building and 188 hp/min for siege weapons and ships).

## Cost

For each hp repaired, resources equal to the half of corresponding build cost are deducted.

```
(repair 1 hp cost) = 0.5 * (build cost) / (build max hp)
```

## Exceptions

* Town center repair costs no stone.

## Math

```
750 hp/min = 750/60000 hp/msec = 0.0125 hp/msec => 80 msec/hp
```
5 changes: 5 additions & 0 deletions libopenage/game_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ ActionMode::ActionMode(qtsdl::GuiItemLink *gui_link)
this->ability = ability_type::garrison;
emit this->gui_signals.ability_changed(std::to_string(this->ability));
});
this->bind(action.get("SET_ABILITY_REPAIR"), [this](const input::action_arg_t &) {
this->use_set_ability = true;
this->ability = ability_type::repair;
emit this->gui_signals.ability_changed(std::to_string(this->ability));
});
this->bind(action.get("SPAWN_VILLAGER"), [this](const input::action_arg_t &) {
Engine &engine = Engine::get();
auto player = this->game_control->get_current_player();
Expand Down
1 change: 1 addition & 0 deletions libopenage/gamestate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_sources(libopenage
generator.cpp
player.cpp
team.cpp
resource.cpp
)
3 changes: 2 additions & 1 deletion libopenage/gamestate/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ std::shared_ptr<GameSpec> Generator::get_spec() const {
std::vector<std::string> Generator::player_names() const {
auto result = this->get_csv("player_names");

result.push_back("gaia");
// gaia is player 0
result.insert(result.begin(), "gaia");

return result;
}
Expand Down
35 changes: 16 additions & 19 deletions libopenage/gamestate/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Player::Player(Civilisation *civ, unsigned int number, std::string name)
civ{civ},
name{name},
team{nullptr} {
// starting resources
this->resources[game_resource::food] = 1000;
this->resources[game_resource::wood] = 1000;
this->resources[game_resource::stone] = 1000;
this->resources[game_resource::gold] = 1000;
}

bool Player::operator ==(const Player &other) const {
Expand Down Expand Up @@ -46,36 +51,28 @@ bool Player::owns(Unit &unit) const {
return false;
}

void Player::receive(const ResourceBundle& amount) {
this->resources += amount;
}

void Player::receive(const game_resource resource, double amount) {
auto r = this->resources.find(resource);
if (r == this->resources.end()) {
this->resources[resource] = amount;
}
else {
this->resources[resource] += amount;
}
this->resources[resource] += amount;
}

bool Player::deduct(const ResourceBundle& amount) {
return this->resources.deduct(amount);
}

bool Player::deduct(const game_resource resource, double amount) {
auto r = this->resources.find(resource);
if (r == this->resources.end()) {
return false;
}
else if (this->resources[resource] >= amount) {
if (this->resources[resource] >= amount) {
this->resources[resource] -= amount;
return true;
}
return false;
}

double Player::amount(const game_resource resource) const {
auto r = this->resources.find(resource);
if (r == this->resources.end()) {
return 0.0;
}
else {
return this->resources.at(resource);
}
return this->resources.get(resource);
}

size_t Player::type_count() {
Expand Down
5 changes: 3 additions & 2 deletions libopenage/gamestate/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ class Player {
/**
* add to stockpile
*/
void receive(const ResourceBundle& amount);
void receive(const game_resource resource, double amount);

/**
* remove from stockpile if available
* TODO parameter uses set of resources
*/
bool deduct(const ResourceBundle& amount);
bool deduct(const game_resource resource, double amount);

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ class Player {
/**
* resources this player currently has
*/
std::unordered_map<game_resource, double> resources;
ResourceBundle resources;

/**
* unit types which can be produced by this player.
Expand Down
63 changes: 63 additions & 0 deletions libopenage/gamestate/resource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2015-2016 the openage authors. See copying.md for legal info.

#include "resource.h"

namespace openage {

ResourceBundle::ResourceBundle()
:
value{0} {
}

bool ResourceBundle::operator> (const ResourceBundle& other) const {
for (int i=0; i<(int) game_resource::RESOURCE_TYPE_COUNT; i++) {
if (!(this->get(i) > other.get(i))) {
return false;
}
}
return true;
}

bool ResourceBundle::operator>= (const ResourceBundle& other) const {
for (int i=0; i<(int) game_resource::RESOURCE_TYPE_COUNT; i++) {
if (!(this->get(i) >= other.get(i))) {
return false;
}
}
return true;
}

ResourceBundle& ResourceBundle::operator+= (const ResourceBundle& other) {
for (int i=0; i<(int) game_resource::RESOURCE_TYPE_COUNT; i++) {
(*this)[i] += other.get(i);
}
return *this;
}

ResourceBundle& ResourceBundle::operator-= (const ResourceBundle& other) {
for (int i=0; i<(int) game_resource::RESOURCE_TYPE_COUNT; i++) {
(*this)[i] -= other.get(i);
}
return *this;
}

ResourceBundle& ResourceBundle::operator*= (double a) {
for (int i=0; i<(int) game_resource::RESOURCE_TYPE_COUNT; i++) {
(*this)[i] *= a;
}
return *this;
}

bool ResourceBundle::has(const ResourceBundle& amount) const {
return *this >= amount;
}

bool ResourceBundle::deduct(const ResourceBundle& amount) {
if(*this >= amount) {
*this -= amount;
return true;
}
return false;
}

} // openage
32 changes: 32 additions & 0 deletions libopenage/gamestate/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,38 @@ enum class game_resource {
RESOURCE_TYPE_COUNT
};

/**
* a set of amounts of game resources
*/
class ResourceBundle {
public:

ResourceBundle();

bool operator> (const ResourceBundle& other) const;
bool operator>= (const ResourceBundle& other) const;

ResourceBundle& operator+= (const ResourceBundle& other);
ResourceBundle& operator-= (const ResourceBundle& other);

ResourceBundle& operator*= (double a);

bool has(const ResourceBundle& amount) const;

bool deduct(const ResourceBundle& amount);

double& operator[] (game_resource res) { return value[(int) res]; }
double& operator[] (int index) { return value[index]; }

// Getters

double get(game_resource res) const { return value[(int) res]; }
double get(int index) const { return value[index]; }

private:
double value[(int) game_resource::RESOURCE_TYPE_COUNT];
};

} // namespace openage

namespace std {
Expand Down
2 changes: 1 addition & 1 deletion libopenage/gui/actions_list_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void ActionsListModel::set_active_buttons(const ActionButtonsType &active_button
this->beginResetModel();
this->add_button(30, -1, static_cast<int>(GroupIDs::NoGroup), "BUILD_MENU");
this->add_button(31, -1, static_cast<int>(GroupIDs::NoGroup), "BUILD_MENU_MIL");
this->add_button(28, -1, static_cast<int>(GroupIDs::NoGroup), "REPAIR");
this->add_button(28, -1, static_cast<int>(GroupIDs::NoGroup), "SET_ABILITY_REPAIR");
this->add_button(59, -1, static_cast<int>(GroupIDs::NoGroup), "KILL_UNIT");
this->add_button(2, -1, static_cast<int>(GroupIDs::NoGroup), "SET_ABILITY_GARRISON");

Expand Down
Loading