Merge remote-tracking branch 'q-github/master'

develop
Alexander Gavrilov 2012-01-28 12:14:30 +04:00
commit f6b19045dd
12 changed files with 100 additions and 72 deletions

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -1,4 +1,4 @@
/*
/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)

@ -38,15 +38,18 @@ using namespace std;
using namespace DFHack;
using namespace DFHack::Simple;
using namespace df::enums;
#include "DataDefs.h"
#include "df/world.h"
#include "df/d_init.h"
using df::global::world;
using df::global::d_init;
bool Translation::IsValid ()
{
return (world->raws.language.words.size() > 0) && (world->raws.language.translations.size() > 0);
return (world && (world->raws.language.words.size() > 0) && (world->raws.language.translations.size() > 0));
}
bool Translation::readName(t_name & name, df::language_name * source)
@ -78,50 +81,78 @@ bool Translation::copyName(df::language_name * source, df::language_name * targe
return true;
}
void addNameWord (string &out, const string &word)
{
if (word.empty())
return;
string upper = word;
upper[0] = toupper(upper[0]);
if (out.length() > 0)
out.append(" ");
out.append(upper);
}
string Translation::TranslateName(const df::language_name * name, bool inEnglish)
{
string out;
string word;
if (!name->first_name.empty())
addNameWord(out, name->first_name);
if (!name->nickname.empty())
{
word = "`" + name->nickname + "'";
switch (d_init ? d_init->nickname_dwarf : d_init_nickname::CENTRALIZE)
{
case d_init_nickname::REPLACE_ALL:
out = word;
return out;
case d_init_nickname::REPLACE_FIRST:
out = "";
break;
case d_init_nickname::CENTRALIZE:
break;
}
addNameWord(out, word);
}
if(!inEnglish)
if (!inEnglish)
{
if (name->words[0] >= 0 || name->words[1] >= 0)
{
word.clear();
if (name->words[0] >= 0)
out.append(*world->raws.language.translations[name->language]->words[name->words[0]]);
word.append(*world->raws.language.translations[name->language]->words[name->words[0]]);
if (name->words[1] >= 0)
out.append(*world->raws.language.translations[name->language]->words[name->words[1]]);
out[0] = toupper(out[0]);
word.append(*world->raws.language.translations[name->language]->words[name->words[1]]);
addNameWord(out, word);
}
if (name->words[5] >= 0)
{
string word;
word.clear();
for (int i = 2; i <= 5; i++)
if (name->words[i] >= 0)
word.append(*world->raws.language.translations[name->language]->words[name->words[i]]);
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
addNameWord(out, word);
}
if (name->words[6] >= 0)
{
string word = *world->raws.language.translations[name->language]->words[name->words[6]];
word[0] = toupper(word[0]);
if (out.length() > 0)
out.append(" ");
out.append(word);
word.clear();
word.append(*world->raws.language.translations[name->language]->words[name->words[6]]);
addNameWord(out, word);
}
}
else
{
if (name->words[0] >= 0 || name->words[1] >= 0)
{
word.clear();
if (name->words[0] >= 0)
out.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]);
word.append(world->raws.language.words[name->words[0]]->forms[name->parts_of_speech[0].value]);
if (name->words[1] >= 0)
out.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]);
out[0] = toupper(out[0]);
word.append(world->raws.language.words[name->words[1]]->forms[name->parts_of_speech[1].value]);
addNameWord(out, word);
}
if (name->words[5] >= 0)
{
@ -129,14 +160,11 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
out.append(" the");
else
out.append("The");
for (int i = 2; i <= 5; i++)
{
if (name->words[i] >= 0)
{
string word = world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value];
word[0] = toupper(word[0]);
out.append(" " + word);
}
addNameWord(out, world->raws.language.words[name->words[i]]->forms[name->parts_of_speech[i].value]);
}
}
if (name->words[6] >= 0)
@ -146,10 +174,9 @@ string Translation::TranslateName(const df::language_name * name, bool inEnglish
else
out.append("Of");
string word = world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value];
word[0] = toupper(word[0]);
out.append(" " + word);
addNameWord(out, world->raws.language.words[name->words[6]]->forms[name->parts_of_speech[6].value]);
}
}
return out;
}

@ -16,7 +16,6 @@ using namespace std;
#include <string>
#include "modules/Items.h"
#include "modules/Units.h"
#include "modules/Materials.h"
#include "modules/Translation.h"
#include "DataDefs.h"
#include "df/world.h"
@ -96,9 +95,11 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
CoreSuspender suspend(c);
DFHack::Materials *Materials = c->getMaterials();
bool ok = Materials->ReadAllMaterials();
if (!Translation::IsValid())
{
c->con.printerr("Translation data unavailable!\n");
return CR_FAILURE;
}
c->con.print("Found total %d items.\n", world->items.all.size());
@ -181,17 +182,9 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
);
df::unit *owner = Items::getItemOwner(item);
std::string info;
if (owner)
{
info = owner->name.first_name;
if (!owner->name.nickname.empty())
info += std::string(" '") + owner->name.nickname + "'";
info += " ";
info += Translation::TranslateName(&owner->name,false);
c->con.print(", owner %s", info.c_str());
}
c->con.print(", owner %s", Translation::TranslateName(&owner->name,false).c_str());
if (!dry_run)
{

@ -22,6 +22,19 @@ using namespace df::enums;
using df::global::world;
bool setTileMaterial(int16_t &tile, const TileMaterial mat)
{
int16_t newTile = findTileType(tileShape(tile), mat, tileVariant(tile), tileSpecial(tile), tileDirection(tile));
if (newTile == -1)
return false;
if (newTile != tile)
{
tile = newTile;
return true;
}
return false;
}
DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters)
{
if (parameters.size())
@ -35,8 +48,8 @@ DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters
return CR_FAILURE;
}
int removed = 0;
int added = 0;
int mineral_removed = 0, feature_removed = 0;
int mineral_added = 0, feature_added = 0;
int num_blocks = 0, blocks_total = world->map.map_blocks.size();
for (int i = 0; i < blocks_total; i++)
@ -57,33 +70,22 @@ DFhackCExport command_result df_fixveins (Core * c, vector <string> & parameters
for (int y = 0; y < 16; y++)
{
int16_t oldT = block->tiletype[x][y];
int16_t newT = oldT;
TileMaterial mat = tileMaterial(oldT);
if ((mat == VEIN) && !(has_mineral[y] & (1 << x)))
{
newT = findTileType(tileShape(oldT), STONE, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT));
if ((newT != -1) && (newT != oldT))
{
block->tiletype[x][y] = newT;
removed++;
}
}
mineral_removed += setTileMaterial(block->tiletype[x][y], STONE);
if ((mat == STONE) && (has_mineral[y] & (1 << x)))
{
newT = findTileType(tileShape(oldT), VEIN, tileVariant(oldT), tileSpecial(oldT), tileDirection(oldT));
if ((newT != -1) && (newT != oldT))
{
block->tiletype[x][y] = newT;
added++;
}
}
mineral_added += setTileMaterial(block->tiletype[x][y], VEIN);
if ((mat == FEATSTONE) && !(block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global))
feature_removed += setTileMaterial(block->tiletype[x][y], STONE);
if ((mat == STONE) && (block->designation[x][y].bits.feature_local || block->designation[x][y].bits.feature_global))
feature_added += setTileMaterial(block->tiletype[x][y], FEATSTONE);
}
}
}
if (removed)
c->con.print("Removed %i invalid references to mineral inclusions.\n", removed);
if (added)
c->con.print("Restored %i missing references to mineral inclusions.\n", added);
if (mineral_removed || feature_removed)
c->con.print("Removed invalid references from %i mineral inclusion and %i map feature tiles.\n", mineral_removed, feature_removed);
if (mineral_added || feature_added)
c->con.print("Restored missing references to %i mineral inclusion and %i map feature tiles.\n", mineral_added, feature_added);
return CR_OK;
}

@ -32,6 +32,12 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
if (!parameters.empty())
return CR_WRONG_USAGE;
if (!Translation::IsValid())
{
c->con.printerr("Translation data unavailable!\n");
return CR_FAILURE;
}
CoreSuspender suspend(c);
bool found = false;
@ -61,7 +67,7 @@ DFhackCExport command_result df_showmood (Core * c, vector <string> & parameters
c->con.printerr("Dwarf with strange mood does not have a mood type!\n");
continue;
}
c->con.print("%s %s is currently ", unit->name.first_name.c_str(), Translation::TranslateName(&unit->name, false).c_str());
c->con.print("%s is currently ", Translation::TranslateName(&unit->name, false).c_str());
switch (unit->mood)
{
case mood_type::Macabre: