Add a user-defined name to vehicle definitions.
This also adds partial support for a custom vehicle graphic.
This commit is contained in:
@@ -904,6 +904,23 @@ void readScenarioFromXml(ticpp::Document&& data, cScenario& scenario) {
|
||||
if(strnum >= scenario.journal_strs.size())
|
||||
scenario.journal_strs.resize(strnum + 1);
|
||||
game->GetText(&scenario.journal_strs[strnum], false);
|
||||
} else if(type == "vehicle") {
|
||||
std::string vtype = game->GetAttribute("type");
|
||||
if(vtype != "boat" && vtype != "horse")
|
||||
throw xBadVal(type, "type", vtype, game->Row(), game->Column(), fname);
|
||||
auto& list = (vtype == "boat" ? scenario.boats : scenario.horses);
|
||||
game->GetAttribute("id", &strnum);
|
||||
list.resize(strnum);
|
||||
int i = strnum - 1;
|
||||
Iterator<Element> vehicle;
|
||||
for(vehicle = vehicle.begin(game.Get()); vehicle != vehicle.end(); vehicle++) {
|
||||
vehicle->GetValue(&type);
|
||||
if(type == "name") {
|
||||
vehicle->GetText(&list[i].name);
|
||||
} else if(type == "pic") {
|
||||
vehicle->GetText(&list[i].pic);
|
||||
} else throw xBadNode(type, vehicle->Row(), vehicle->Column(), fname);
|
||||
}
|
||||
} else throw xBadNode(type, game->Row(), game->Column(), fname);
|
||||
}
|
||||
if(!reqs.empty())
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#define BOE_DATA_VEHICLE_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include "location.hpp"
|
||||
|
||||
namespace legacy {
|
||||
@@ -28,6 +29,8 @@ public:
|
||||
short which_town;
|
||||
bool exists;
|
||||
bool property;
|
||||
pic_num_t pic = 0;
|
||||
std::string name; // For designer use; not stored in save files
|
||||
|
||||
cVehicle();
|
||||
void import_legacy(legacy::horse_record_type& old);
|
||||
|
@@ -2633,6 +2633,7 @@ bool edit_vehicle(cVehicle& what, int num, bool is_boat) {
|
||||
dlg["loc"].setText(boost::lexical_cast<std::string>(what.loc));
|
||||
dlg["num"].setTextToNum(num);
|
||||
dlg["title"].setText(is_boat ? "Edit Boat" : "Edit Horse");
|
||||
dlg["name"].setText(what.name);
|
||||
|
||||
cLed& prop = dynamic_cast<cLed&>(dlg["owned"]);
|
||||
prop.setState(what.property ? led_red : led_off);
|
||||
@@ -2645,6 +2646,7 @@ bool edit_vehicle(cVehicle& what, int num, bool is_boat) {
|
||||
if(dlg.accepted()) {
|
||||
what.property = prop.getState() != led_off;
|
||||
what.exists = true;
|
||||
what.name = dlg["name"].getText();
|
||||
}
|
||||
return what.exists;
|
||||
}
|
||||
|
@@ -336,6 +336,24 @@ void writeScenarioToXml(ticpp::Printer&& data, cScenario& scenario) {
|
||||
data.PushAttribute("id", scenario.journal_strs.size() - 1);
|
||||
data.CloseElement("journal");
|
||||
}
|
||||
for(size_t i = 0; i < scenario.boats.size(); i++) {
|
||||
if(scenario.boats[i].name.empty() && scenario.boats[i].pic == 0) continue;
|
||||
data.OpenElement("vehicle");
|
||||
data.PushAttribute("type", "boat");
|
||||
data.PushAttribute("id", i + 1);
|
||||
if(!scenario.boats[i].name.empty()) data.PushElement("name", scenario.boats[i].name);
|
||||
if(scenario.boats[i].pic > 0) data.PushElement("pic", scenario.boats[i].pic);
|
||||
data.CloseElement("vehicle");
|
||||
}
|
||||
for(size_t i = 0; i < scenario.horses.size(); i++) {
|
||||
if(scenario.horses[i].name.empty() && scenario.horses[i].pic == 0) continue;
|
||||
data.OpenElement("vehicle");
|
||||
data.PushAttribute("type", "horse");
|
||||
data.PushAttribute("id", i + 1);
|
||||
if(!scenario.horses[i].name.empty()) data.PushElement("name", scenario.horses[i].name);
|
||||
if(scenario.horses[i].pic > 0) data.PushElement("pic", scenario.horses[i].pic);
|
||||
data.CloseElement("vehicle");
|
||||
}
|
||||
data.CloseElement("game");
|
||||
data.OpenElement("editor");
|
||||
data.PushElement("default-ground", scenario.default_ground);
|
||||
|
Reference in New Issue
Block a user