forked from github/server
Merge pull request #754 from ennorehling/develop
fix the preview report for 1057
This commit is contained in:
commit
564390a762
15 changed files with 218 additions and 155 deletions
|
@ -46,7 +46,7 @@
|
||||||
</resource>
|
</resource>
|
||||||
|
|
||||||
<resource name="magicbag">
|
<resource name="magicbag">
|
||||||
<item big="yes" weight="100" score="6000"/>
|
<item notlost="yes" big="yes" weight="100" score="6000"/>
|
||||||
</resource>
|
</resource>
|
||||||
|
|
||||||
<resource name="magicherbbag" appearance="">
|
<resource name="magicherbbag" appearance="">
|
||||||
|
|
|
@ -7331,7 +7331,7 @@
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="a_road_percent">
|
<string name="a_road_percent">
|
||||||
<text locale="de">eine zu $percent%% vollendete Straße</text>
|
<text locale="de">eine zu $percent% vollendete Straße</text>
|
||||||
<text locale="en">a road that is $percent% complete</text>
|
<text locale="en">a road that is $percent% complete</text>
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,18 @@
|
||||||
pulled by 8 young dragons flies through the stary night and presents
|
pulled by 8 young dragons flies through the stary night and presents
|
||||||
your faction with a $resource($item,1).</text>
|
your faction with a $resource($item,1).</text>
|
||||||
</message>
|
</message>
|
||||||
|
<message name="santa_m" section="events">
|
||||||
|
<type>
|
||||||
|
<arg name="item" type="resource"/>
|
||||||
|
</type>
|
||||||
|
<text locale="de">'Ho ho ho!' Ein dicker Gnom fliegt auf einem von
|
||||||
|
8 Jungdrachen gezogenen Schlitten durch die Nacht und vermacht Deiner
|
||||||
|
Partei einen $resource($item,1). (Um diesen Gegenstand einer Einheit zu geben, gib
|
||||||
|
ihr den Befehl 'BEANSPRUCHE 1 $resource($item,1)').</text>
|
||||||
|
<text locale="en">'Ho ho ho!' A fat little gnome Gnom on a sled
|
||||||
|
pulled by 8 young dragons flies through the stary night and presents
|
||||||
|
your faction with a $resource($item,1).</text>
|
||||||
|
</message>
|
||||||
|
|
||||||
<message name="target_region_invalid">
|
<message name="target_region_invalid">
|
||||||
<type>
|
<type>
|
||||||
|
|
|
@ -16,11 +16,23 @@ cd tests
|
||||||
./run-turn.sh
|
./run-turn.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cppcheck_tests() {
|
||||||
|
cppcheck --version
|
||||||
|
DIRS="util kernel modules races attributes triggers items tools spells"
|
||||||
|
IGNORE=""
|
||||||
|
for DIR in $DIRS ; do
|
||||||
|
IGNORE="$IGNORE -i src/$DIR"
|
||||||
|
echo "cppcheck src/$DIR"
|
||||||
|
cppcheck --quiet -Isrc -Iclibs -Istorage -IcJSON --error-exitcode=1 "src/$DIR"
|
||||||
|
done
|
||||||
|
echo "cppcheck src"
|
||||||
|
cppcheck --quiet -Isrc -Iclibs -Istorage -IcJSON --error-exitcode=1 $IGNORE src
|
||||||
|
}
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -z $BUILD ] && BUILD=Debug ; export BUILD
|
[ -z $BUILD ] && BUILD=Debug ; export BUILD
|
||||||
s/cmake-init
|
s/cmake-init
|
||||||
cppcheck --version
|
# cppcheck_tests
|
||||||
cppcheck --quiet -Isrc -Iclibs -Istorage -IcJSON --error-exitcode=1 src
|
|
||||||
s/build
|
s/build
|
||||||
cd process
|
cd process
|
||||||
make
|
make
|
||||||
|
|
|
@ -2,16 +2,15 @@ if not config.xmas or config.xmas==0 then return nil end
|
||||||
|
|
||||||
local gifts = {
|
local gifts = {
|
||||||
e2 = {
|
e2 = {
|
||||||
{ year = 2017, turn = 1057, item = 'snowglobe', msg='santa_f' },
|
[1057] = { year = 2017, item = 'snowglobe', msg='santa_f' },
|
||||||
{ year = 2015, turn = 959, item = 'snowglobe', msg='santa_f' },
|
[959] = { year = 2015, item = 'snowglobe', msg='santa_f' },
|
||||||
{ year = 2009, turn = 624, item = 'xmastree' },
|
[624] = { year = 2009, item = 'xmastree', msg='santa_m' },
|
||||||
{ year = 2006, turn = 468, key = 'xm06', item = 'snowman' },
|
[468] = { year = 2006, item = 'snowman', msg='santa_m' },
|
||||||
{ year = 2005, turn = 416, key = 'xm05', item = 'stardust' },
|
[416] = { year = 2005, item = 'stardust' },
|
||||||
{ year = 2004, turn = 364, key = 'xm04', item = 'speedsail' }
|
[364] = { year = 2004, item = 'speedsail' }
|
||||||
},
|
},
|
||||||
e3 = {
|
e3 = {
|
||||||
-- { year = 2015, turn = 338, item = 'snowglobe' },
|
[26] = { year = 2009, item = 'xmastree' }
|
||||||
{ year = 2009, turn = 26, key = 'xm09', item = 'xmastree' }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +37,9 @@ function self.init()
|
||||||
local turn = get_turn()
|
local turn = get_turn()
|
||||||
local tbl = gifts[config.rules]
|
local tbl = gifts[config.rules]
|
||||||
if tbl then
|
if tbl then
|
||||||
for _, gift in ipairs(tbl) do
|
gift = tbl[turn]
|
||||||
if turn == gift.turn then
|
if gift then
|
||||||
give_gifts(gift)
|
give_gifts(gift)
|
||||||
elseif gift.key and not get_key(gift.key) then
|
|
||||||
give_gifts(gift)
|
|
||||||
set_key(gift.key)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
76
src/battle.c
76
src/battle.c
|
@ -185,7 +185,7 @@ static int army_index(side * s)
|
||||||
return s->index;
|
return s->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *sidename(side * s)
|
const char *sidename(const side * s)
|
||||||
{
|
{
|
||||||
#define SIDENAMEBUFLEN 256
|
#define SIDENAMEBUFLEN 256
|
||||||
static int bufno; /* STATIC_XCALL: used across calls */
|
static int bufno; /* STATIC_XCALL: used across calls */
|
||||||
|
@ -206,7 +206,7 @@ static const char *sideabkz(side * s, bool truename)
|
||||||
return sideabkz_buf;
|
return sideabkz_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void message_faction(battle * b, faction * f, struct message *m)
|
void battle_message_faction(battle * b, faction * f, struct message *m)
|
||||||
{
|
{
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
|
|
||||||
|
@ -227,14 +227,14 @@ void message_all(battle * b, message * m)
|
||||||
|
|
||||||
for (bf = b->factions; bf; bf = bf->next) {
|
for (bf = b->factions; bf; bf = bf->next) {
|
||||||
assert(bf->faction);
|
assert(bf->faction);
|
||||||
message_faction(b, bf->faction, m);
|
battle_message_faction(b, bf->faction, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fbattlerecord(battle * b, faction * f, const char *s)
|
static void fbattlerecord(battle * b, faction * f, const char *s)
|
||||||
{
|
{
|
||||||
message *m = msg_message("battle_msg", "string", s);
|
message *m = msg_message("battle_msg", "string", s);
|
||||||
message_faction(b, f, m);
|
battle_message_faction(b, f, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1302,7 +1302,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
|
||||||
if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) {
|
if (oldpotiontype[P_HEAL] && !fval(&df->person[dt.index], FL_HEALING_USED)) {
|
||||||
if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) {
|
if (i_get(du->items, oldpotiontype[P_HEAL]->itype) > 0) {
|
||||||
message *m = msg_message("potionsave", "unit", du);
|
message *m = msg_message("potionsave", "unit", du);
|
||||||
message_faction(b, du->faction, m);
|
battle_message_faction(b, du->faction, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1);
|
i_change(&du->items, oldpotiontype[P_HEAL]->itype, -1);
|
||||||
fset(&df->person[dt.index], FL_HEALING_USED);
|
fset(&df->person[dt.index], FL_HEALING_USED);
|
||||||
|
@ -2531,7 +2531,7 @@ static void loot_items(fighter * corpse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool seematrix(const faction * f, const side * s)
|
bool seematrix(const faction * f, const side * s)
|
||||||
{
|
{
|
||||||
if (f == s->faction)
|
if (f == s->faction)
|
||||||
return true;
|
return true;
|
||||||
|
@ -2615,7 +2615,7 @@ static void aftermath(battle * b)
|
||||||
struct message *m =
|
struct message *m =
|
||||||
msg_message("killsandhits", "unit hits kills", du, df->hits,
|
msg_message("killsandhits", "unit hits kills", du, df->hits,
|
||||||
df->kills);
|
df->kills);
|
||||||
message_faction(b, du->faction, m);
|
battle_message_faction(b, du->faction, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2755,7 +2755,7 @@ static void aftermath(battle * b)
|
||||||
faction *f = bf->faction;
|
faction *f = bf->faction;
|
||||||
message *m = seematrix(f, s) ? seen : unseen;
|
message *m = seematrix(f, s) ? seen : unseen;
|
||||||
|
|
||||||
message_faction(b, f, m);
|
battle_message_faction(b, f, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_release(seen);
|
msg_release(seen);
|
||||||
|
@ -2779,7 +2779,7 @@ static void aftermath(battle * b)
|
||||||
message *m =
|
message *m =
|
||||||
msg_message("battle_loot", "unit amount item", du, l->number,
|
msg_message("battle_loot", "unit amount item", du, l->number,
|
||||||
itype->rtype);
|
itype->rtype);
|
||||||
message_faction(b, du->faction, m);
|
battle_message_faction(b, du->faction, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
i_change(&du->items, itype, l->number);
|
i_change(&du->items, itype, l->number);
|
||||||
}
|
}
|
||||||
|
@ -2877,54 +2877,6 @@ static void set_attacker(fighter * fig)
|
||||||
fset(fig, FIG_ATTACKER);
|
fset(fig, FIG_ATTACKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_header(battle * b)
|
|
||||||
{
|
|
||||||
bfaction *bf;
|
|
||||||
char zText[32 * MAXSIDES];
|
|
||||||
|
|
||||||
for (bf = b->factions; bf; bf = bf->next) {
|
|
||||||
message *m;
|
|
||||||
faction *f = bf->faction;
|
|
||||||
const char *lastf = NULL;
|
|
||||||
bool first = false;
|
|
||||||
side *s;
|
|
||||||
char *bufp = zText;
|
|
||||||
size_t size = sizeof(zText) - 1;
|
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
|
||||||
fighter *df;
|
|
||||||
for (df = s->fighters; df; df = df->next) {
|
|
||||||
if (is_attacker(df)) {
|
|
||||||
if (first) {
|
|
||||||
str_strlcpy(bufp, ", ", size);
|
|
||||||
}
|
|
||||||
if (lastf) {
|
|
||||||
str_strlcpy(bufp, lastf, size);
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
if (seematrix(f, s))
|
|
||||||
lastf = sidename(s);
|
|
||||||
else
|
|
||||||
lastf = LOC(f->locale, "unknown_faction_dative");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (first) {
|
|
||||||
bufp = STRLCPY(bufp, " ", size);
|
|
||||||
bufp = STRLCPY(bufp, LOC(f->locale, "and"), size);
|
|
||||||
bufp = STRLCPY(bufp, " ", size);
|
|
||||||
}
|
|
||||||
if (lastf) {
|
|
||||||
bufp = STRLCPY(bufp, lastf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
m = msg_message("start_battle", "factions", zText);
|
|
||||||
message_faction(b, f, m);
|
|
||||||
msg_release(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_stats(battle * b)
|
static void print_stats(battle * b)
|
||||||
{
|
{
|
||||||
side *s2;
|
side *s2;
|
||||||
|
@ -2947,10 +2899,10 @@ static void print_stats(battle * b)
|
||||||
message *msg;
|
message *msg;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
message_faction(b, f, msg_separator);
|
battle_message_faction(b, f, msg_separator);
|
||||||
|
|
||||||
msg = msg_message("battle_army", "index name", army_index(s), sname);
|
msg = msg_message("battle_army", "index name", army_index(s), sname);
|
||||||
message_faction(b, f, msg);
|
battle_message_faction(b, f, msg);
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
|
||||||
bufp = buf;
|
bufp = buf;
|
||||||
|
@ -3569,13 +3521,13 @@ static int battle_report(battle * b)
|
||||||
size_t size = sizeof(buf) - 1;
|
size_t size = sizeof(buf) - 1;
|
||||||
message *m;
|
message *m;
|
||||||
|
|
||||||
message_faction(b, fac, msg_separator);
|
battle_message_faction(b, fac, msg_separator);
|
||||||
|
|
||||||
if (cont)
|
if (cont)
|
||||||
m = msg_message("lineup_battle", "turn", b->turn);
|
m = msg_message("lineup_battle", "turn", b->turn);
|
||||||
else
|
else
|
||||||
m = msg_message("after_battle", "");
|
m = msg_message("after_battle", "");
|
||||||
message_faction(b, fac, m);
|
battle_message_faction(b, fac, m);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
|
|
||||||
komma = false;
|
komma = false;
|
||||||
|
@ -4078,7 +4030,7 @@ void do_battle(region * r)
|
||||||
/* Bevor wir die alliierten hineinziehen, sollten wir schauen, *
|
/* Bevor wir die alliierten hineinziehen, sollten wir schauen, *
|
||||||
* Ob jemand fliehen kann. Dann er<EFBFBD>brigt sich das ganze ja
|
* Ob jemand fliehen kann. Dann er<EFBFBD>brigt sich das ganze ja
|
||||||
* vielleicht schon. */
|
* vielleicht schon. */
|
||||||
print_header(b);
|
report_battle_start(b);
|
||||||
if (!fighting) {
|
if (!fighting) {
|
||||||
/* Niemand mehr da, Kampf kann nicht stattfinden. */
|
/* Niemand mehr da, Kampf kann nicht stattfinden. */
|
||||||
message *m = msg_message("aborted_battle", "");
|
message *m = msg_message("aborted_battle", "");
|
||||||
|
|
|
@ -47,7 +47,6 @@ extern "C" {
|
||||||
#define LAST_ROW FLEE_ROW
|
#define LAST_ROW FLEE_ROW
|
||||||
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
||||||
|
|
||||||
|
|
||||||
typedef struct bfaction {
|
typedef struct bfaction {
|
||||||
struct bfaction *next;
|
struct bfaction *next;
|
||||||
struct side *sides;
|
struct side *sides;
|
||||||
|
@ -266,6 +265,9 @@ extern "C" {
|
||||||
const struct faction * stealthfaction);
|
const struct faction * stealthfaction);
|
||||||
int skilldiff(troop at, troop dt, int dist);
|
int skilldiff(troop at, troop dt, int dist);
|
||||||
void force_leave(struct region *r, struct battle *b);
|
void force_leave(struct region *r, struct battle *b);
|
||||||
|
bool seematrix(const struct faction * f, const struct side * s);
|
||||||
|
const char *sidename(const struct side * s);
|
||||||
|
void battle_message_faction(struct battle * b, struct faction * f, struct message *m);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,7 +316,7 @@ bool checkpasswd(const faction * f, const char *passwd)
|
||||||
if (!passwd) return false;
|
if (!passwd) return false;
|
||||||
|
|
||||||
if (f->_password && password_verify(f->_password, passwd) == VERIFY_FAIL) {
|
if (f->_password && password_verify(f->_password, passwd) == VERIFY_FAIL) {
|
||||||
log_warning("password check failed: %s", factionname(f));
|
log_info("password check failed: %s", factionname(f));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -408,13 +408,9 @@ void save_special_items(unit *usrc)
|
||||||
static int cache;
|
static int cache;
|
||||||
static const char *name = NULL;
|
static const char *name = NULL;
|
||||||
if (rc_changed(&cache)) {
|
if (rc_changed(&cache)) {
|
||||||
rc_ghost = rc_find("ghost");
|
|
||||||
if (!rc_ghost) {
|
|
||||||
rc_ghost = get_race(RC_TEMPLATE);
|
rc_ghost = get_race(RC_TEMPLATE);
|
||||||
name = "ghost";
|
name = "ghost";
|
||||||
}
|
}
|
||||||
assert(rc_ghost);
|
|
||||||
}
|
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
if (u->faction == fm) {
|
if (u->faction == fm) {
|
||||||
give_special_items(u, &usrc->items);
|
give_special_items(u, &usrc->items);
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
|
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/bsdstring.h>
|
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
|
@ -68,29 +67,17 @@ keyword_t getkeyword(const order * ord)
|
||||||
* keywords are expanded to their full length.
|
* keywords are expanded to their full length.
|
||||||
*/
|
*/
|
||||||
char* get_command(const order *ord, const struct locale *lang, char *sbuffer, size_t size) {
|
char* get_command(const order *ord, const struct locale *lang, char *sbuffer, size_t size) {
|
||||||
char *bufp = sbuffer;
|
|
||||||
order_data *od = NULL;
|
order_data *od = NULL;
|
||||||
const char * text;
|
const char * text;
|
||||||
keyword_t kwd = ORD_KEYWORD(ord);
|
keyword_t kwd = ORD_KEYWORD(ord);
|
||||||
int bytes;
|
sbstring sbs;
|
||||||
|
|
||||||
|
sbs_init(&sbs, sbuffer, size);
|
||||||
if (ord->command & CMD_QUIET) {
|
if (ord->command & CMD_QUIET) {
|
||||||
if (size > 0) {
|
sbs_strcpy(&sbs, "!");
|
||||||
*bufp++ = '!';
|
|
||||||
--size;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (ord->command & CMD_PERSIST) {
|
if (ord->command & CMD_PERSIST) {
|
||||||
if (size > 0) {
|
sbs_strcat(&sbs, "@");
|
||||||
*bufp++ = '@';
|
|
||||||
--size;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ord->id < 0) {
|
if (ord->id < 0) {
|
||||||
|
@ -102,39 +89,19 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si
|
||||||
text = OD_STRING(od);
|
text = OD_STRING(od);
|
||||||
}
|
}
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD) {
|
||||||
if (size > 0) {
|
|
||||||
const char *str = (const char *)LOC(lang, keyword(kwd));
|
const char *str = (const char *)LOC(lang, keyword(kwd));
|
||||||
assert(str);
|
assert(str);
|
||||||
if (text) --size;
|
sbs_strcat(&sbs, str);
|
||||||
bytes = (int)str_strlcpy(bufp, str, size);
|
if (text) {
|
||||||
if (wrptr(&bufp, &size, bytes) != 0) {
|
sbs_strcat(&sbs, " ");
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
|
||||||
if (text) *bufp++ = ' ';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (text) {
|
if (text) {
|
||||||
bytes = (int)str_strlcpy(bufp, (const char *)text, size);
|
sbs_strcat(&sbs, text);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0) {
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
if (bufp - sbuffer >= 6) {
|
|
||||||
bufp -= 6;
|
|
||||||
while (bufp > sbuffer && (*bufp & 0x80) != 0) {
|
|
||||||
++size;
|
|
||||||
--bufp;
|
|
||||||
}
|
|
||||||
memcpy(bufp, "[...]", 6); /* TODO: make sure this only happens in eval_command */
|
|
||||||
bufp += 6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (od) {
|
if (od) {
|
||||||
odata_release(od);
|
odata_release(od);
|
||||||
}
|
}
|
||||||
if (size > 0) *bufp = 0;
|
|
||||||
return sbuffer;
|
return sbuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,50 +234,46 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
||||||
order *ord;
|
order *ord;
|
||||||
char zBuffer[DISPLAYSIZE];
|
char zBuffer[DISPLAYSIZE];
|
||||||
if (params) {
|
if (params) {
|
||||||
char *bufp = zBuffer;
|
sbstring sbs;
|
||||||
int bytes;
|
|
||||||
size_t size = sizeof(zBuffer) - 1;
|
|
||||||
va_list marker;
|
va_list marker;
|
||||||
|
char *tok;
|
||||||
|
|
||||||
assert(lang);
|
assert(lang);
|
||||||
va_start(marker, params);
|
va_start(marker, params);
|
||||||
|
sbs_init(&sbs, zBuffer, sizeof(zBuffer));
|
||||||
while (*params) {
|
while (*params) {
|
||||||
if (*params == '%') {
|
|
||||||
int i;
|
int i;
|
||||||
const char *s;
|
const char *s;
|
||||||
++params;
|
tok = strchr(params, '%');
|
||||||
switch (*params) {
|
if (tok) {
|
||||||
|
if (tok != params) {
|
||||||
|
sbs_strncat(&sbs, params, tok - params);
|
||||||
|
}
|
||||||
|
switch (tok[1]) {
|
||||||
case 's':
|
case 's':
|
||||||
s = va_arg(marker, const char *);
|
s = va_arg(marker, const char *);
|
||||||
assert(s);
|
assert(s);
|
||||||
bytes = (int)str_strlcpy(bufp, s, size);
|
sbs_strcat(&sbs, s);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
i = va_arg(marker, int);
|
i = va_arg(marker, int);
|
||||||
bytes = (int)str_strlcpy(bufp, itoa10(i), size);
|
sbs_strcat(&sbs, itoa10(i));
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
i = va_arg(marker, int);
|
i = va_arg(marker, int);
|
||||||
bytes = (int)str_strlcpy(bufp, itoa36(i), size);
|
sbs_strcat(&sbs, itoa36(i));
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
|
||||||
WARN_STATIC_BUFFER();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"unknown format-character in create_order");
|
assert(!"unknown format-character in create_order");
|
||||||
}
|
}
|
||||||
|
params = tok + 2;
|
||||||
}
|
}
|
||||||
else if (size > 0) {
|
else {
|
||||||
*bufp++ = *params;
|
sbs_strcat(&sbs, params);
|
||||||
--size;
|
break;
|
||||||
}
|
}
|
||||||
++params;
|
|
||||||
}
|
}
|
||||||
va_end(marker);
|
va_end(marker);
|
||||||
*bufp = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
zBuffer[0] = 0;
|
zBuffer[0] = 0;
|
||||||
|
|
|
@ -2230,7 +2230,7 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
(int)str_strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size);
|
(int)str_strlcpy(bufp, LOC(f->locale, resourcename(rm->rtype, 0)), size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
++m;
|
++rm;
|
||||||
if (rm->number)
|
if (rm->number)
|
||||||
bytes = (int)str_strlcpy(bufp, ", ", size);
|
bytes = (int)str_strlcpy(bufp, ", ", size);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
|
|
|
@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
|
|
||||||
|
#include "battle.h"
|
||||||
#include "calendar.h"
|
#include "calendar.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
|
@ -2030,6 +2031,54 @@ static void eval_order(struct opstack **stack, const void *userdata)
|
||||||
opush(stack, var);
|
opush(stack, var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void report_battle_start(battle * b)
|
||||||
|
{
|
||||||
|
bfaction *bf;
|
||||||
|
char zText[32 * MAXSIDES];
|
||||||
|
sbstring sbs;
|
||||||
|
|
||||||
|
for (bf = b->factions; bf; bf = bf->next) {
|
||||||
|
message *m;
|
||||||
|
faction *f = bf->faction;
|
||||||
|
const char *lastf = NULL;
|
||||||
|
bool first = false;
|
||||||
|
side *s;
|
||||||
|
|
||||||
|
sbs_init(&sbs, zText, sizeof(zText));
|
||||||
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
|
fighter *df;
|
||||||
|
for (df = s->fighters; df; df = df->next) {
|
||||||
|
if (is_attacker(df)) {
|
||||||
|
if (first) {
|
||||||
|
sbs_strcpy(&sbs, ", ");
|
||||||
|
}
|
||||||
|
if (lastf) {
|
||||||
|
sbs_strcpy(&sbs, lastf);
|
||||||
|
first = true;
|
||||||
|
}
|
||||||
|
if (seematrix(f, s))
|
||||||
|
lastf = sidename(s);
|
||||||
|
else
|
||||||
|
lastf = LOC(f->locale, "unknown_faction_dative");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
sbs_strcpy(&sbs, " ");
|
||||||
|
sbs_strcpy(&sbs, LOC(f->locale, "and"));
|
||||||
|
sbs_strcpy(&sbs, " ");
|
||||||
|
}
|
||||||
|
if (lastf) {
|
||||||
|
sbs_strcpy(&sbs, lastf);
|
||||||
|
}
|
||||||
|
|
||||||
|
m = msg_message("start_battle", "factions", zText);
|
||||||
|
battle_message_faction(b, f, m);
|
||||||
|
msg_release(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void eval_resources(struct opstack **stack, const void *userdata)
|
static void eval_resources(struct opstack **stack, const void *userdata)
|
||||||
{ /* order -> string */
|
{ /* order -> string */
|
||||||
const faction *f = (const faction *)userdata;
|
const faction *f = (const faction *)userdata;
|
||||||
|
|
|
@ -29,6 +29,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct battle;
|
||||||
struct gamedate;
|
struct gamedate;
|
||||||
struct selist;
|
struct selist;
|
||||||
struct stream;
|
struct stream;
|
||||||
|
@ -97,6 +98,7 @@ extern "C" {
|
||||||
const struct locale *lang);
|
const struct locale *lang);
|
||||||
size_t report_status(const struct unit *u,
|
size_t report_status(const struct unit *u,
|
||||||
const struct locale *lang, char *buf, size_t siz);
|
const struct locale *lang, char *buf, size_t siz);
|
||||||
|
void report_battle_start(struct battle * b);
|
||||||
|
|
||||||
void register_reports(void);
|
void register_reports(void);
|
||||||
|
|
||||||
|
|
|
@ -238,3 +238,44 @@ char *str_strdup(const char *s) {
|
||||||
return strdup(s);
|
return strdup(s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sbs_init(struct sbstring *sbs, char *buffer, size_t size)
|
||||||
|
{
|
||||||
|
assert(sbs);
|
||||||
|
assert(size>0);
|
||||||
|
sbs->begin = buffer;
|
||||||
|
sbs->size = size;
|
||||||
|
sbs->end = buffer;
|
||||||
|
buffer[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
assert(sbs);
|
||||||
|
len = sbs->size - (sbs->end - sbs->begin) - 1;
|
||||||
|
if (len < size) {
|
||||||
|
size = len;
|
||||||
|
}
|
||||||
|
memcpy(sbs->end, str, size);
|
||||||
|
sbs->end[size] = '\0';
|
||||||
|
sbs->end += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbs_strcat(struct sbstring *sbs, const char *str)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
assert(sbs);
|
||||||
|
len = sbs->size - (sbs->end - sbs->begin);
|
||||||
|
len = str_strlcpy(sbs->end, str, len);
|
||||||
|
sbs->end += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sbs_strcpy(struct sbstring *sbs, const char *str)
|
||||||
|
{
|
||||||
|
size_t len = str_strlcpy(sbs->begin, str, sbs->size);
|
||||||
|
if (len >= sbs->size) {
|
||||||
|
len = sbs->size - 1;
|
||||||
|
}
|
||||||
|
sbs->end = sbs->begin + len;
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,18 @@ extern "C" {
|
||||||
unsigned int jenkins_hash(unsigned int a);
|
unsigned int jenkins_hash(unsigned int a);
|
||||||
unsigned int wang_hash(unsigned int a);
|
unsigned int wang_hash(unsigned int a);
|
||||||
|
|
||||||
|
/* static buffered string */
|
||||||
|
typedef struct sbstring {
|
||||||
|
size_t size;
|
||||||
|
char *begin;
|
||||||
|
char *end;
|
||||||
|
} sbstring;
|
||||||
|
|
||||||
|
void sbs_init(struct sbstring *sbs, char *buffer, size_t size);
|
||||||
|
void sbs_strcat(struct sbstring *sbs, const char *str);
|
||||||
|
void sbs_strncat(struct sbstring *sbs, const char *str, size_t size);
|
||||||
|
void sbs_strcpy(struct sbstring *sbs, const char *str);
|
||||||
|
|
||||||
/* benchmark for units:
|
/* benchmark for units:
|
||||||
* JENKINS_HASH: 5.25 misses/hit (with good cache behavior)
|
* JENKINS_HASH: 5.25 misses/hit (with good cache behavior)
|
||||||
* WANG_HASH: 5.33 misses/hit (with good cache behavior)
|
* WANG_HASH: 5.33 misses/hit (with good cache behavior)
|
||||||
|
|
|
@ -91,6 +91,32 @@ static void test_str_strlcpy(CuTest * tc)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_sbstring(CuTest * tc)
|
||||||
|
{
|
||||||
|
char buffer[16];
|
||||||
|
sbstring sbs;
|
||||||
|
sbs_init(&sbs, buffer, sizeof(buffer));
|
||||||
|
CuAssertStrEquals(tc, "", sbs.begin);
|
||||||
|
sbs_strcpy(&sbs, "Hodor");
|
||||||
|
CuAssertStrEquals(tc, "Hodor", sbs.begin);
|
||||||
|
sbs_strcat(&sbs, "Hodor");
|
||||||
|
CuAssertStrEquals(tc, "HodorHodor", sbs.begin);
|
||||||
|
sbs_strcpy(&sbs, "Hodor");
|
||||||
|
CuAssertStrEquals(tc, "Hodor", sbs.begin);
|
||||||
|
sbs_strcpy(&sbs, "12345678901234567890");
|
||||||
|
CuAssertStrEquals(tc, "123456789012345", sbs.begin);
|
||||||
|
CuAssertPtrEquals(tc, sbs.begin + sbs.size - 1, sbs.end);
|
||||||
|
sbs_strcat(&sbs, "12345678901234567890");
|
||||||
|
CuAssertStrEquals(tc, "123456789012345", sbs.begin);
|
||||||
|
CuAssertPtrEquals(tc, buffer, sbs.begin);
|
||||||
|
sbs_strcpy(&sbs, "1234567890");
|
||||||
|
CuAssertStrEquals(tc, "1234567890", sbs.begin);
|
||||||
|
sbs_strncat(&sbs, "1234567890", 4);
|
||||||
|
CuAssertStrEquals(tc, "12345678901234", sbs.begin);
|
||||||
|
sbs_strncat(&sbs, "567890", 6);
|
||||||
|
CuAssertStrEquals(tc, "123456789012345", sbs.begin);
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_strings_suite(void)
|
CuSuite *get_strings_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -100,5 +126,6 @@ CuSuite *get_strings_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_str_slprintf);
|
SUITE_ADD_TEST(suite, test_str_slprintf);
|
||||||
SUITE_ADD_TEST(suite, test_str_strlcat);
|
SUITE_ADD_TEST(suite, test_str_strlcat);
|
||||||
SUITE_ADD_TEST(suite, test_str_strlcpy);
|
SUITE_ADD_TEST(suite, test_str_strlcpy);
|
||||||
|
SUITE_ADD_TEST(suite, test_sbstring);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue