Merge pull request #840 from ennorehling/develop

develop updates
This commit is contained in:
Enno Rehling 2019-03-24 17:52:25 +01:00 committed by GitHub
commit 24a9d483e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 73 additions and 42 deletions

2
cJSON

@ -1 +1 @@
Subproject commit 26e64b8207b30bf9f8389b33f68d46d9dea6f9d8
Subproject commit 8df81fb497cc48b089a57fcdc3a9933540ebc7c9

View file

@ -32,7 +32,6 @@ function test_undead_reserve_other()
process_orders()
assert_equal(0, u1:get_item("log"))
assert_equal(2, u2:get_item("log"))
end

View file

@ -28,6 +28,7 @@ typedef struct allies {
static void block_insert(allies *al, struct faction *f, int status) {
int i = al->num++;
assert(status > 0);
al->status[i] = status;
al->factions[i] = f;
/* TODO: heapify */
@ -46,7 +47,7 @@ static int block_search(allies *al, const struct faction *f) {
int allies_walk(struct allies *all, cb_allies_walk callback, void *udata)
{
allies *al;
allies *al;
for (al = all; al; al = al->next) {
int i;
for (i = 0; i != al->num; ++i) {
@ -94,13 +95,17 @@ void ally_set(allies **p_al, struct faction *f, int status)
return;
}
if (al->num < BLOCKSIZE) {
block_insert(al, f, status);
if (status > 0) {
block_insert(al, f, status);
}
return;
}
p_al = &al->next;
}
*p_al = calloc(1, sizeof(allies));
block_insert(*p_al, f, status);
if (status > 0) {
*p_al = calloc(1, sizeof(allies));
block_insert(*p_al, f, status);
}
}
void write_allies(gamedata * data, const allies *alist)
@ -112,6 +117,7 @@ void write_allies(gamedata * data, const allies *alist)
const faction * f = al->factions[i];
if (f && f->_alive) {
write_faction_reference(f, data->store);
assert(al->status[i] > 0);
WRITE_INT(data->store, al->status[i]);
}
}
@ -132,7 +138,10 @@ void read_allies(gamedata * data, allies **p_al)
f = findfaction(aid);
if (!f) f = faction_create(aid);
READ_INT(data->store, &status);
ally_set(p_al, f, status);
/* NB: some data files have allies with status=0 */
if (status > 0) {
ally_set(p_al, f, status);
}
}
}

View file

@ -1,6 +1,7 @@
#include <platform.h>
#include "types.h"
#include "ally.h"
#include "faction.h"
#include <CuTest.h>
#include <tests.h>
@ -41,11 +42,36 @@ static void test_allies(CuTest *tc) {
test_teardown();
}
static void test_allies_set(CuTest *tc) {
struct faction *f1, *f2;
struct allies * al = NULL;
test_setup();
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
CuAssertPtrEquals(tc, NULL, al);
ally_set(&al, f1, HELP_ALL);
CuAssertPtrNotNull(tc, al);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, f1->allies);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, al);
ally_set(&al, f1, HELP_ALL);
ally_set(&al, f2, DONT_HELP);
ally_set(&al, f1, DONT_HELP);
CuAssertPtrEquals(tc, NULL, al);
test_teardown();
}
CuSuite *get_ally_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_allies);
SUITE_ADD_TEST(suite, test_allies_clone);
SUITE_ADD_TEST(suite, test_allies_set);
return suite;
}

View file

@ -27,26 +27,26 @@ static int age_chance(int a, int b, int p) {
return (r < 0) ? 0 : r;
}
#define DRAGONAGE 27
#define WYRMAGE 68
#define DRAGONAGE 27
#define WYRMAGE 68
static void evolve_dragon(unit * u, const struct race *rc) {
scale_number(u, 1);
u_setrace(u, rc);
u->irace = NULL;
u->hp = unit_max_hp(u);
}
void age_firedragon(unit * u)
{
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u_setrace(u, get_race(RC_DRAGON));
u->irace = NULL;
scale_number(u, 1);
u->hp = (int)(unit_max_hp(u) * u->number * q);
evolve_dragon(u, get_race(RC_DRAGON));
}
}
void age_dragon(unit * u)
{
if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
u_setrace(u, get_race(RC_WYRM));
u->irace = NULL;
u->hp = (int)(unit_max_hp(u) * u->number * q);
evolve_dragon(u, get_race(RC_WYRM));
}
}

View file

@ -1509,7 +1509,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda
if ((mode & HELP_ALL) == HELP_ALL) {
sbs_strcat(sbp, LOC(f->locale, parameters[P_ANY]));
}
else {
else if (mode > 0) {
int h, hh = 0;
for (h = 1; h <= HELP_TRAVEL; h *= 2) {
int p = MAXPARAMS;
@ -1545,7 +1545,7 @@ static int show_allies_cb(struct allies *all, faction *af, int status, void *uda
}
}
if (show->num_allies == show->num_listed) {
sbs_strcat(sbp, ").");
sbs_strcat(sbp, ").\n");
pump_paragraph(sbp, show->out, show->maxlen, true);
}
else {
@ -1577,11 +1577,24 @@ void report_allies(struct stream *out, size_t maxlen, const struct faction * f,
}
}
static void rpline(struct stream *out)
{
static char line[REPORTWIDTH + 1];
if (line[0] != '-') {
memset(line, '-', sizeof(line));
line[REPORTWIDTH] = '\n';
}
swrite(line, sizeof(line), 1, out);
}
static void allies(struct stream *out, const faction * f)
{
const group *g = f->groups;
char prefix[64];
centre(out, LOC(f->locale, "nr_alliances"), false);
newline(out);
if (f->allies) {
snprintf(prefix, sizeof(prefix), "%s ", LOC(f->locale, "faction_help"));
report_allies(out, REPORTWIDTH, f, f->allies, prefix);
@ -1594,6 +1607,7 @@ static void allies(struct stream *out, const faction * f)
}
g = g->next;
}
rpline(out);
}
static void guards(struct stream *out, const region * r, const faction * see)
@ -1660,16 +1674,6 @@ static void guards(struct stream *out, const region * r, const faction * see)
}
}
static void rpline(struct stream *out)
{
static char line[REPORTWIDTH + 1];
if (line[0] != '-') {
memset(line, '-', sizeof(line));
line[REPORTWIDTH] = '\n';
}
swrite(line, sizeof(line), 1, out);
}
static void list_address(struct stream *out, const faction * uf, selist * seenfactions)
{
int qi = 0;
@ -2114,14 +2118,6 @@ report_plaintext(const char *filename, report_context * ctx,
}
}
newline(out);
ERRNO_CHECK();
centre(out, LOC(f->locale, "nr_alliances"), false);
newline(out);
allies(out, f);
rpline(out);
ERRNO_CHECK();
anyunits = 0;
@ -2177,8 +2173,8 @@ report_plaintext(const char *filename, report_context * ctx,
if (wants_stats && r->seen.mode >= seen_travel) {
if (r->land || r->seen.mode >= seen_unit) {
newline(out);
statistics(out, r, f);
newline(out);
}
}
@ -2249,6 +2245,7 @@ report_plaintext(const char *filename, report_context * ctx,
paragraph(out, LOC(f->locale, "nr_youaredead"), 0, 2, 0);
}
else {
allies(out, f);
list_address(out, f, ctx->addresses);
}
}

View file

@ -192,7 +192,7 @@ static void test_report_allies(CuTest *tc) {
f1 = test_create_faction(NULL);
f2 = test_create_faction(NULL);
f3 = test_create_faction(NULL);
snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n",
snprintf(exp, sizeof(exp), "Wir helfen %s (%s).\n\n",
factionname(f1),
LOC(lang, parameters[P_GUARD]));
ally_set(&f->allies, f1, HELP_GUARD);
@ -211,7 +211,7 @@ static void test_report_allies(CuTest *tc) {
factionname(f2),
LOC(lang, parameters[P_GIVE]));
linebreak = strlen(exp);
snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n",
snprintf(exp, sizeof(exp), "Wir helfen %s (%s), %s (%s)\nund %s (%s).\n\n",
factionname(f1),
LOC(lang, parameters[P_GUARD]),
factionname(f2),

View file

@ -88,7 +88,7 @@ const char *itoab_r(int i, int base, char *s, size_t len)
}
}
else {
log_error("static buffer exhauset, itoab(%d, %d)", i, base);
log_error("static buffer exhausted, itoab(%d, %d)", i, base);
assert(i == 0 || !"itoab: static buffer exhausted");
}
}