Merge pull request #148 from wjrogers/feature-protobuf-api

Add SetUnitLabors and additional optional data to ListUnits
develop
Petr Mrázek 2012-04-14 14:56:19 -07:00
commit 5f1c933b0f
3 changed files with 51 additions and 1 deletions

@ -61,6 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "df/world.h"
#include "df/world_data.h"
#include "df/unit.h"
#include "df/unit_misc_trait.h"
#include "df/unit_soul.h"
#include "df/unit_skill.h"
#include "df/material.h"
@ -316,6 +317,19 @@ void DFHack::describeUnit(BasicUnitInfo *info, df::unit *unit,
}
}
if (mask && mask->misc_traits())
{
auto &vec = unit -> status.misc_traits;
for (size_t i = 0; i < vec.size(); i++)
{
auto trait = vec[i];
auto item = info->add_misc_traits();
item->set_id(trait->id);
item->set_value(trait->value);
}
}
if (unit->curse.add_tags1.whole ||
unit->curse.add_tags2.whole ||
unit->curse.rem_tags1.whole ||
@ -614,6 +628,20 @@ static command_result ListSquads(color_ostream &stream,
return CR_OK;
}
static command_result SetUnitLabors(color_ostream &stream, const SetUnitLaborsIn *in)
{
for (size_t i = 0; i < in->change_size(); i++)
{
auto change = in->change(i);
auto unit = df::unit::find(change.unit_id());
if (unit)
unit->status.labors[change.labor()] = change.value();
}
return CR_OK;
}
CoreService::CoreService() {
suspend_depth = 0;
@ -637,6 +665,8 @@ CoreService::CoreService() {
addFunction("ListMaterials", ListMaterials, SF_CALLED_ONCE);
addFunction("ListUnits", ListUnits);
addFunction("ListSquads", ListSquads);
addFunction("SetUnitLabors", SetUnitLabors);
}
CoreService::~CoreService()

@ -130,6 +130,11 @@ message SkillInfo {
required int32 experience = 3;
};
message UnitMiscTrait {
required int32 id = 1;
required int32 value = 2;
};
message BasicUnitInfo {
required int32 unit_id = 1;
@ -166,6 +171,9 @@ message BasicUnitInfo {
// IF mask.skills:
repeated SkillInfo skills = 12;
// IF mask.misc_traits:
repeated UnitMiscTrait misc_traits = 24;
optional UnitCurseInfo curse = 16;
repeated int32 burrows = 21;
@ -175,6 +183,7 @@ message BasicUnitInfoMask {
optional bool labors = 1 [default = false];
optional bool skills = 2 [default = false];
optional bool profession = 3 [default = false];
optional bool misc_traits = 4 [default = false];
};
message BasicSquadInfo {
@ -188,3 +197,9 @@ message BasicSquadInfo {
// Member histfig ids:
repeated sint32 members = 4;
};
message UnitLaborState {
required int32 unit_id = 1;
required int32 labor = 2;
required bool value = 3;
};

@ -99,4 +99,9 @@ message ListUnitsOut {
message ListSquadsIn {}
message ListSquadsOut {
repeated BasicSquadInfo value = 1;
}
};
// RPC SetUnitLabors : SetUnitLaborsIn -> EmptyMessage
message SetUnitLaborsIn {
repeated UnitLaborState change = 1;
};