Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix Zeitdehnung #1016

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,12 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u,
otype = SPP_TEMP;
}

spobj = *spobjp = malloc(sizeof(spllprm));
if (!spobj) abort();
spobj->flag = 0;
spobj->typ = otype;
spobj->data.i = atoi36((const char *)param[i]);

*spobjp = spobj = malloc(sizeof(spllprm));
if (spobj) {
spobj->flag = 0;
spobj->typ = otype;
spobj->data.i = atoi36((const char*)param[i]);
}
return i + 1;
}

Expand Down
11 changes: 3 additions & 8 deletions src/spells.c
Original file line number Diff line number Diff line change
Expand Up @@ -5916,13 +5916,11 @@ int sp_speed2(castorder * co)
int n, maxmen, used = 0, dur, men;
unit *u;
unit *mage = co_get_caster(co);
int cast_level = co->level;
double force = co->force;
spellparameter *pa = co->par;

maxmen = 2 * cast_level * cast_level;
dur = cast_level / 2;
if (dur < 1) dur = 1;
maxmen = 2 * (int)(force * force);
dur = (1 + co->level) / 2;

for (n = 0; n < pa->length; n++) {
double effect;
Expand All @@ -5944,10 +5942,7 @@ int sp_speed2(castorder * co)

ADDMSG(&mage->faction->msgs, msg_message("speed_time_effect",
"unit region amount", mage, mage->region, used));
/* Effektiv benoetigten cast_level (mindestens 1) zurueckgeben */
used = (int)sqrt(used / 2);
if (used < 1) used = 1;
return used;
return co->level;
}

/* ------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions src/spells.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern "C" {
int sp_gooddreams(struct castorder * co);
int sp_viewreality(struct castorder * co);
int sp_showastral(struct castorder * co);
int sp_speed2(struct castorder* co);
#define ACTION_RESET 0x01 /* reset the one-time-flag FFL_SELECT (on first pass) */
#define ACTION_CANSEE 0x02 /* to people who can see the actor */
#define ACTION_CANNOTSEE 0x04 /* to people who can not see the actor */
Expand Down
62 changes: 47 additions & 15 deletions src/spells.test.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "spells.h"

#include "magic.h" // for free_castorder, castorder
#include "magic.h"
#include "teleport.h"

#include <kernel/curse.h>
Expand All @@ -15,6 +15,7 @@
#include "util/variant.h" // for variant

#include <spells/regioncurse.h>
#include <spells/unitcurse.h>
#include <attributes/attributes.h>

#include <triggers/changerace.h>
Expand Down Expand Up @@ -53,7 +54,6 @@ static void test_good_dreams(CuTest *tc) {
a_age(&r->attribs, r);
CuAssertIntEquals_Msg(tc, "good dreams give +1 to allies", 1, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "good dreams have no effect on non-allies", 0, get_modifier(u2, SK_MELEE, 11, r, false));
free_castorder(&co);
test_teardown();
}

Expand All @@ -78,7 +78,50 @@ static void test_dreams(CuTest *tc) {
CuAssertIntEquals_Msg(tc, "good dreams in same region as bad dreams", 1, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "bad dreams in same region as good dreams", -1, get_modifier(u2, SK_MELEE, 11, r, false));

free_castorder(&co);
test_teardown();
}

static void test_speed2(CuTest *tc) {
struct region *r;
struct faction *f;
unit *u1, *u2;
castorder co;
curse* c;
spellparameter args;
spllprm param;
spllprm *params = &param;

test_setup();
r = test_create_plain(0, 0);
f = test_create_faction();
u1 = test_create_unit(f, r);
u2 = test_create_unit(f, r);
scale_number(u2, 30);

args.length = 1;
args.param = &params;
param.flag = 0;
param.typ = SPP_UNIT;
param.data.u = u2;

/* force 4, kann bis zu 32 Personen verzaubern */
test_create_castorder(&co, u1, 3, 4., 0, &args);
CuAssertIntEquals(tc, co.level, sp_speed2(&co));
CuAssertPtrNotNull(tc, c = get_curse(u2->attribs, &ct_speed));
CuAssertDblEquals(tc, 2.0, c->effect, 0.01);
CuAssertIntEquals(tc, (1 + co.level) / 2, c->duration);
CuAssertIntEquals(tc, u2->number, c->data.i);
CuAssertDblEquals(tc, co.force, c->vigour, 0.01);
a_removeall(&u2->attribs, NULL);

/* force 3, kann nur bis zu 18 Personen verzaubern */
test_create_castorder(&co, u1, 1, 3., 0, &args);
CuAssertIntEquals(tc, 1, sp_speed2(&co));
CuAssertPtrNotNull(tc, c = get_curse(u2->attribs, &ct_speed));
CuAssertDblEquals(tc, 2.0, c->effect, 0.01);
CuAssertIntEquals(tc, 1, c->duration);
CuAssertIntEquals(tc, 18, c->data.i);
CuAssertDblEquals(tc, co.force, c->vigour, 0.01);
test_teardown();
}

Expand Down Expand Up @@ -110,7 +153,6 @@ static void test_bad_dreams(CuTest *tc) {
CuAssertIntEquals_Msg(tc, "bad dreams have no effect on allies", 0, get_modifier(u1, SK_MELEE, 11, r, false));
CuAssertIntEquals_Msg(tc, "bad dreams give -1 to non-allies", -1, get_modifier(u2, SK_MELEE, 11, r, false));

free_castorder(&co);
test_teardown();
}

Expand All @@ -137,7 +179,6 @@ static void test_view_reality(CuTest *tc) {
test_create_castorder(&co, u, 10, 10.0, 0, NULL);
CuAssertIntEquals(tc, 0, sp_viewreality(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "spell_astral_only"));
free_castorder(&co);

test_clear_messagelist(&f->msgs);
ra = test_create_region(real2tp(0), real2tp(0), NULL);
Expand All @@ -149,7 +190,6 @@ static void test_view_reality(CuTest *tc) {
CuAssertIntEquals(tc, 0, sp_viewreality(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error216"));
CuAssertIntEquals(tc, -1, get_observer(rx, f));
free_castorder(&co);

test_clear_messagelist(&f->msgs);
r = test_create_plain(0, 0);
Expand All @@ -162,7 +202,6 @@ static void test_view_reality(CuTest *tc) {
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "viewreality_effect"));
CuAssertIntEquals(tc, 5, get_observer(r, f));
CuAssertIntEquals(tc, -1, get_observer(rx, f));
free_castorder(&co);

set_observer(r, f, -1, 0);
CuAssertIntEquals(tc, -1, get_observer(r, f));
Expand All @@ -173,7 +212,6 @@ static void test_view_reality(CuTest *tc) {
CuAssertIntEquals(tc, 0, sp_viewreality(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error216"));
CuAssertIntEquals(tc, -1, get_observer(r, f));
free_castorder(&co);
remove_curse(&ra->attribs, c);

/* target region r exists, but astral interference is blocked */
Expand All @@ -182,7 +220,6 @@ static void test_view_reality(CuTest *tc) {
CuAssertIntEquals(tc, 0, sp_viewreality(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error216"));
CuAssertIntEquals(tc, -1, get_observer(r, f));
free_castorder(&co);

test_teardown();
}
Expand Down Expand Up @@ -212,7 +249,6 @@ static void test_show_astral(CuTest *tc) {
test_create_castorder(&co, u, 10, 10.0, 0, NULL);
CuAssertIntEquals(tc, 0, sp_showastral(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "spell_astral_forbidden"));
free_castorder(&co);

test_clear_messagelist(&f->msgs);
move_unit(u, r, NULL);
Expand All @@ -222,7 +258,6 @@ static void test_show_astral(CuTest *tc) {
CuAssertIntEquals(tc, 0, sp_showastral(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error216"));
CuAssertIntEquals(tc, -1, get_observer(ra, f));
free_castorder(&co);

rx = test_create_region(real2tp(r->x), real2tp(r->y), NULL);
rx->_plane = ra->_plane;
Expand All @@ -234,7 +269,6 @@ static void test_show_astral(CuTest *tc) {
CuAssertIntEquals(tc, -1, get_observer(ra, f));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error220"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "showastral_effect"));
free_castorder(&co);

test_create_unit(f, ra);
test_create_unit(f, rx);
Expand All @@ -244,22 +278,19 @@ static void test_show_astral(CuTest *tc) {
CuAssertIntEquals(tc, 5, get_observer(rx, f));
CuAssertIntEquals(tc, -1, get_observer(ra, f));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "showastral_effect"));
free_castorder(&co);

/* astral block on r */
c = create_curse(u, &r->attribs, &ct_astralblock, 50.0, 1, 50, 0);
test_create_castorder(&co, u, 9, 10.0, 0, NULL);
CuAssertIntEquals(tc, 0, sp_showastral(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error216"));
free_castorder(&co);
remove_curse(&r->attribs, c);

/* astral block on rx */
c = create_curse(u, &rx->attribs, &ct_astralblock, 50.0, 1, 50, 0);
test_create_castorder(&co, u, 9, 10.0, 0, NULL);
CuAssertIntEquals(tc, 0, sp_showastral(&co));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error220"));
free_castorder(&co);
remove_curse(&rx->attribs, c);

test_teardown();
Expand Down Expand Up @@ -342,6 +373,7 @@ CuSuite *get_spells_suite(void)
SUITE_ADD_TEST(suite, test_good_dreams);
SUITE_ADD_TEST(suite, test_bad_dreams);
SUITE_ADD_TEST(suite, test_dreams);
SUITE_ADD_TEST(suite, test_speed2);
SUITE_ADD_TEST(suite, test_change_race);
return suite;
}
2 changes: 0 additions & 2 deletions src/spells/flyingship.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ static void test_flyingship(CuTest * tc)
CuAssertIntEquals(tc, 10, sp_flying_ship(&co));
CuAssertTrue(tc, flying_ship(sh1));
co.par = 0;
free_castorder(&co);

sh2 = test_create_ship(r, shipType2);
par_data.data.sh = sh2;
Expand All @@ -64,7 +63,6 @@ static void test_flyingship(CuTest * tc)
CuAssertIntEquals(tc, 0, sp_flying_ship(&co));
CuAssertTrue(tc, !flying_ship(sh2));
co.par = 0;
free_castorder(&co);
test_teardown();
}

Expand Down
8 changes: 1 addition & 7 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdbool.h> // for true
#include <stdio.h> // for fprintf, stderr
#include <stdlib.h>
Expand Down Expand Up @@ -484,12 +483,7 @@ item_type * test_create_itemtype(const char * name) {
}

void test_create_castorder(castorder *co, unit *u, int level, float force, int range, spellparameter *par) {
struct locale * lang;
order *ord;

lang = test_create_locale();
create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), par);
free_order(ord);
create_castorder(co, u, NULL, NULL, u->region, level, force, range, NULL, par);
}

spell * test_create_spell(void)
Expand Down
2 changes: 1 addition & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.9)
cmake_minimum_required(VERSION 3.5)
project (tools C)

add_executable(inifile inifile.c)
Expand Down