forked from github/server
Merge branch 'kill-rcspell' into feature/refactor-rcspell
Conflicts: src/kernel/config.h src/main.c src/report.c src/reports.c src/reports.test.c src/spells.c
This commit is contained in:
commit
abb7c9fb17
31
src/battle.c
31
src/battle.c
|
@ -1636,18 +1636,11 @@ static castorder * create_castorder_combat(castorder *co, fighter *fig, const sp
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_combatmagic(battle * b, combatmagic_t was)
|
|
||||||
{
|
|
||||||
side *s;
|
|
||||||
region *r = b->region;
|
|
||||||
castorder *co;
|
|
||||||
int level, rank, sl;
|
|
||||||
spellrank spellranks[MAX_SPELLRANK];
|
|
||||||
|
|
||||||
memset(spellranks, 0, sizeof(spellranks));
|
|
||||||
|
|
||||||
#ifdef FFL_CURSED
|
#ifdef FFL_CURSED
|
||||||
if (was == DO_PRECOMBATSPELL) {
|
static void summon_igjarjuk(battle *b, spellrank spellranks[]) {
|
||||||
|
side *s;
|
||||||
|
castorder *co;
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
fighter *fig = 0;
|
fighter *fig = 0;
|
||||||
if (s->bf->attacker && fval(s->faction, FFL_CURSED)) {
|
if (s->bf->attacker && fval(s->faction, FFL_CURSED)) {
|
||||||
|
@ -1681,6 +1674,22 @@ void do_combatmagic(battle * b, combatmagic_t was)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void do_combatmagic(battle * b, combatmagic_t was)
|
||||||
|
{
|
||||||
|
side *s;
|
||||||
|
castorder *co;
|
||||||
|
region *r = b->region;
|
||||||
|
int level, rank, sl;
|
||||||
|
spellrank spellranks[MAX_SPELLRANK];
|
||||||
|
|
||||||
|
memset(spellranks, 0, sizeof(spellranks));
|
||||||
|
|
||||||
|
#ifdef FFL_CURSED
|
||||||
|
if (was == DO_PRECOMBATSPELL) {
|
||||||
|
summon_igjarjuk(b, spellranks);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
||||||
fighter *fig;
|
fighter *fig;
|
||||||
|
|
|
@ -1418,7 +1418,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
|
||||||
}
|
}
|
||||||
cr_output_curses_compat(F, f, r, TYP_REGION);
|
cr_output_curses_compat(F, f, r, TYP_REGION);
|
||||||
cr_borders(r, f, r->seen.mode, F);
|
cr_borders(r, f, r->seen.mode, F);
|
||||||
if (r->seen.mode == seen_unit && is_astral(r)
|
if (r->seen.mode >= seen_unit && is_astral(r)
|
||||||
&& !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
|
&& !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
|
||||||
/* Sonderbehandlung Teleport-Ebene */
|
/* Sonderbehandlung Teleport-Ebene */
|
||||||
region_list *rl = astralregions(r, inhabitable);
|
region_list *rl = astralregions(r, inhabitable);
|
||||||
|
@ -1441,7 +1441,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r)
|
||||||
}
|
}
|
||||||
|
|
||||||
cr_output_travelthru(F, r, f);
|
cr_output_travelthru(F, r, f);
|
||||||
if (r->seen.mode == seen_unit || r->seen.mode == seen_travel) {
|
if (r->seen.mode >= seen_travel) {
|
||||||
message_list *mlist = r_getmessages(r, f);
|
message_list *mlist = r_getmessages(r, f);
|
||||||
cr_output_messages(F, r->msgs, f);
|
cr_output_messages(F, r->msgs, f);
|
||||||
if (mlist) {
|
if (mlist) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#define RF_MALLORN (1<<1) /* persistent */
|
#define RF_MALLORN (1<<1) /* persistent */
|
||||||
#define RF_BLOCKED (1<<2) /* persistent */
|
#define RF_BLOCKED (1<<2) /* persistent */
|
||||||
|
|
||||||
#define RF_UNUSED_3 (1<<3)
|
#define RF_OBSERVER (1<<3) /* persistent */
|
||||||
#define RF_UNUSED_4 (1<<4)
|
#define RF_UNUSED_4 (1<<4)
|
||||||
#define RF_UNUSED_5 (1<<5)
|
#define RF_UNUSED_5 (1<<5)
|
||||||
#define RF_UNUSED_6 (1<<6)
|
#define RF_UNUSED_6 (1<<6)
|
||||||
|
|
|
@ -71,8 +71,8 @@ typedef enum {
|
||||||
seen_neighbour,
|
seen_neighbour,
|
||||||
seen_lighthouse,
|
seen_lighthouse,
|
||||||
seen_travel,
|
seen_travel,
|
||||||
seen_far,
|
|
||||||
seen_unit,
|
seen_unit,
|
||||||
|
seen_spell,
|
||||||
seen_battle
|
seen_battle
|
||||||
} seen_mode;
|
} seen_mode;
|
||||||
|
|
||||||
|
|
|
@ -63,42 +63,21 @@ void update_lighthouse(building * lh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lighthouse_range(const building * b, const faction * f)
|
int lighthouse_range(const building * b, const faction * f, const unit *u)
|
||||||
{
|
{
|
||||||
int d = 0;
|
|
||||||
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
|
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
|
||||||
int maxd = (int)log10(b->size) + 1;
|
int maxd = (int)log10(b->size) + 1;
|
||||||
|
|
||||||
if (skill_enabled(SK_PERCEPTION)) {
|
if (u && skill_enabled(SK_PERCEPTION)) {
|
||||||
region *r = b->region;
|
|
||||||
int c = 0;
|
|
||||||
int cap = buildingcapacity(b);
|
|
||||||
unit *u, *uown = building_owner(b);
|
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
|
||||||
if (u->building == b || u == uown) {
|
|
||||||
c += u->number;
|
|
||||||
if (c > cap) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (f == NULL || u->faction == f) {
|
|
||||||
int sk = effskill(u, SK_PERCEPTION, 0) / 3;
|
int sk = effskill(u, SK_PERCEPTION, 0) / 3;
|
||||||
d = MAX(d, sk);
|
assert(u->building == b);
|
||||||
d = MIN(maxd, d);
|
assert(u->faction == f);
|
||||||
if (d == maxd)
|
maxd = MIN(maxd, sk);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (c)
|
|
||||||
break; /* first unit that's no longer in the house ends the search */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* E3A rule: no perception req'd */
|
/* E3A rule: no perception req'd */
|
||||||
return maxd;
|
return maxd;
|
||||||
}
|
}
|
||||||
}
|
return 0;
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_leuchtturm(region * r, faction * f)
|
bool check_leuchtturm(region * r, faction * f)
|
||||||
|
|
|
@ -29,14 +29,15 @@ extern "C" {
|
||||||
struct faction;
|
struct faction;
|
||||||
struct region;
|
struct region;
|
||||||
struct building;
|
struct building;
|
||||||
|
struct unit;
|
||||||
struct attrib;
|
struct attrib;
|
||||||
|
|
||||||
extern struct attrib_type at_lighthouse;
|
extern struct attrib_type at_lighthouse;
|
||||||
/* leuchtturm */
|
/* leuchtturm */
|
||||||
bool check_leuchtturm(struct region *r, struct faction *f);
|
bool check_leuchtturm(struct region *r, struct faction *f);
|
||||||
void update_lighthouse(struct building *lh);
|
void update_lighthouse(struct building *b);
|
||||||
int lighthouse_range(const struct building *b,
|
int lighthouse_range(const struct building *b, const struct faction *f,
|
||||||
const struct faction *f);
|
const struct unit *u);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -26,29 +26,29 @@ static void test_lighthouse_range(CuTest * tc)
|
||||||
u1 = test_create_unit(test_create_faction(0), r);
|
u1 = test_create_unit(test_create_faction(0), r);
|
||||||
u2 = test_create_unit(test_create_faction(0), r);
|
u2 = test_create_unit(test_create_faction(0), r);
|
||||||
b = test_create_building(r, test_create_buildingtype("lighthouse"));
|
b = test_create_building(r, test_create_buildingtype("lighthouse"));
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, u1->faction));
|
CuAssertIntEquals(tc, 0, lighthouse_range(b, u1->faction, NULL));
|
||||||
b->size = 10;
|
b->size = 10;
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
|
||||||
u1->building = b;
|
u1->building = b;
|
||||||
u2->building = b;
|
u2->building = b;
|
||||||
u1->number = 10;
|
u1->number = 10;
|
||||||
set_level(u1, SK_PERCEPTION, 3);
|
set_level(u1, SK_PERCEPTION, 3);
|
||||||
set_level(u2, SK_PERCEPTION, 3);
|
set_level(u2, SK_PERCEPTION, 3);
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 0, lighthouse_range(b, NULL, NULL));
|
||||||
b->flags |= BLD_MAINTAINED;
|
b->flags |= BLD_MAINTAINED;
|
||||||
CuAssertIntEquals(tc, 1, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 1, lighthouse_range(b, u1->faction, u1));
|
||||||
set_level(u1, SK_PERCEPTION, 6);
|
set_level(u1, SK_PERCEPTION, 6);
|
||||||
CuAssertIntEquals(tc, 2, lighthouse_range(b, u1->faction));
|
CuAssertIntEquals(tc, 2, lighthouse_range(b, u1->faction, u1));
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, u2->faction));
|
/* lighthouse_range does not check inside_building */
|
||||||
|
CuAssertIntEquals(tc, 1, lighthouse_range(b, u2->faction, u2));
|
||||||
b->size = 100;
|
b->size = 100;
|
||||||
update_lighthouse(b);
|
update_lighthouse(b);
|
||||||
CuAssertIntEquals(tc, 2, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 3, lighthouse_range(b, NULL, NULL));
|
||||||
|
CuAssertIntEquals(tc, 2, lighthouse_range(b, u1->faction, u1));
|
||||||
set_level(u1, SK_PERCEPTION, 9);
|
set_level(u1, SK_PERCEPTION, 9);
|
||||||
CuAssertIntEquals(tc, 3, lighthouse_range(b, NULL));
|
CuAssertIntEquals(tc, 3, lighthouse_range(b, u1->faction, u1));
|
||||||
CuAssertIntEquals(tc, 3, lighthouse_range(b, u1->faction));
|
CuAssertIntEquals(tc, 1, lighthouse_range(b, u2->faction, u2));
|
||||||
CuAssertIntEquals(tc, 1, lighthouse_range(b, u2->faction));
|
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, test_create_faction(0)));
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/report.c
19
src/report.c
|
@ -997,7 +997,7 @@ void report_region(struct stream *out, const region * r, faction * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* iron & stone */
|
/* iron & stone */
|
||||||
if (r->seen.mode == seen_unit) {
|
if (r->seen.mode >= seen_unit) {
|
||||||
resource_report result[MAX_RAWMATERIALS];
|
resource_report result[MAX_RAWMATERIALS];
|
||||||
int n, numresults = report_resources(r, result, MAX_RAWMATERIALS, f, true);
|
int n, numresults = report_resources(r, result, MAX_RAWMATERIALS, f, true);
|
||||||
|
|
||||||
|
@ -1184,7 +1184,7 @@ void report_region(struct stream *out, const region * r, faction * f)
|
||||||
*bufp = 0;
|
*bufp = 0;
|
||||||
paragraph(out, buf, 0, 0, 0);
|
paragraph(out, buf, 0, 0, 0);
|
||||||
|
|
||||||
if (r->seen.mode == seen_unit && is_astral(r) &&
|
if (r->seen.mode >= seen_unit && is_astral(r) &&
|
||||||
!is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
|
!is_cursed(r->attribs, C_ASTRALBLOCK, 0)) {
|
||||||
/* Sonderbehandlung Teleport-Ebene */
|
/* Sonderbehandlung Teleport-Ebene */
|
||||||
region_list *rl = astralregions(r, inhabitable);
|
region_list *rl = astralregions(r, inhabitable);
|
||||||
|
@ -2272,7 +2272,7 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
continue;
|
continue;
|
||||||
/* Beschreibung */
|
/* Beschreibung */
|
||||||
|
|
||||||
if (r->seen.mode == seen_unit) {
|
if (r->seen.mode >= seen_unit) {
|
||||||
anyunits = 1;
|
anyunits = 1;
|
||||||
newline(out);
|
newline(out);
|
||||||
report_region(out, r, f);
|
report_region(out, r, f);
|
||||||
|
@ -2305,24 +2305,13 @@ report_plaintext(const char *filename, report_context * ctx,
|
||||||
report_travelthru(out, r, f);
|
report_travelthru(out, r, f);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (r->seen.mode == seen_far) {
|
|
||||||
newline(out);
|
|
||||||
report_region(out, r, f);
|
|
||||||
newline(out);
|
|
||||||
guards(out, r, f);
|
|
||||||
newline(out);
|
|
||||||
report_travelthru(out, r, f);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newline(out);
|
|
||||||
report_region(out, r, f);
|
report_region(out, r, f);
|
||||||
newline(out);
|
newline(out);
|
||||||
report_travelthru(out, r, f);
|
report_travelthru(out, r, f);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/* Statistik */
|
/* Statistik */
|
||||||
|
|
||||||
if (wants_stats && r->seen.mode == seen_unit)
|
if (wants_stats && r->seen.mode >= seen_unit)
|
||||||
statistics(out, r, f);
|
statistics(out, r, f);
|
||||||
|
|
||||||
/* Nachrichten an REGION in der Region */
|
/* Nachrichten an REGION in der Region */
|
||||||
|
|
|
@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "guard.h"
|
#include "guard.h"
|
||||||
#include "laws.h"
|
#include "laws.h"
|
||||||
|
#include "spells.h"
|
||||||
#include "travelthru.h"
|
#include "travelthru.h"
|
||||||
#include "lighthouse.h"
|
#include "lighthouse.h"
|
||||||
#include "donations.h"
|
#include "donations.h"
|
||||||
|
@ -93,6 +94,7 @@ const char *visibility[] = {
|
||||||
"travel",
|
"travel",
|
||||||
"far",
|
"far",
|
||||||
"unit",
|
"unit",
|
||||||
|
"spell",
|
||||||
"battle"
|
"battle"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -966,9 +968,9 @@ const struct unit *ucansee(const struct faction *f, const struct unit *u,
|
||||||
int stealth_modifier(seen_mode mode)
|
int stealth_modifier(seen_mode mode)
|
||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
case seen_spell:
|
||||||
case seen_unit:
|
case seen_unit:
|
||||||
return 0;
|
return 0;
|
||||||
case seen_far:
|
|
||||||
case seen_lighthouse:
|
case seen_lighthouse:
|
||||||
return -2;
|
return -2;
|
||||||
case seen_travel:
|
case seen_travel:
|
||||||
|
@ -1422,29 +1424,42 @@ void prepare_report(report_context *ctx, faction *f)
|
||||||
ctx->last = lastregion(f);
|
ctx->last = lastregion(f);
|
||||||
|
|
||||||
for (r = ctx->first; r!=ctx->last; r = r->next) {
|
for (r = ctx->first; r!=ctx->last; r = r->next) {
|
||||||
int range = 0;
|
|
||||||
unit *u;
|
unit *u;
|
||||||
if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) {
|
int range = 0;
|
||||||
if (rule_region_owners && f == region_get_owner(r)) {
|
if (fval(r, RF_OBSERVER)) {
|
||||||
|
int skill = get_observer(r, f);
|
||||||
|
if (skill >= 0) {
|
||||||
|
add_seen_nb(f, r, seen_spell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fval(r, RF_LIGHTHOUSE)) {
|
||||||
/* region owners get the report from lighthouses */
|
/* region owners get the report from lighthouses */
|
||||||
|
if (rule_region_owners && f == region_get_owner(r)) {
|
||||||
building *b;
|
building *b;
|
||||||
|
for (b = rbuildings(r); b; b = b->next) {
|
||||||
for (b = r->buildings; b; b = b->next) {
|
if (b && b->type == bt_lighthouse) {
|
||||||
if (b->type == bt_lighthouse) {
|
/* region owners get maximm range */
|
||||||
int br = lighthouse_range(b, NULL);
|
int br = lighthouse_range(b, NULL, NULL);
|
||||||
if (br > range) range = br;
|
if (br > range) range = br;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (u = r->units; u; u = u->next) {
|
for (u = r->units; u; u = u->next) {
|
||||||
|
/* if we have any unit in this region, then we get seen_unit access */
|
||||||
if (u->faction == f) {
|
if (u->faction == f) {
|
||||||
add_seen_nb(f, r, seen_unit);
|
add_seen_nb(f, r, seen_unit);
|
||||||
if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) {
|
/* units inside the lighthouse get range based on their perception
|
||||||
if (u->building && u->building->type == bt_lighthouse && inside_building(u)) {
|
* or the size, if perception is not a skill
|
||||||
int br = lighthouse_range(u->building, f);
|
*/
|
||||||
if (br > range) range = br;
|
if (!fval(r, RF_LIGHTHOUSE)) {
|
||||||
|
/* it's enough to mark the region once, and if there are
|
||||||
|
* no lighthouses, there is no need to look at more units */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (range == 0 && u->building && u->building->type == bt_lighthouse && inside_building(u)) {
|
||||||
|
int br = lighthouse_range(u->building, f, u);
|
||||||
|
if (br > range) range = br;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "lighthouse.h"
|
#include "lighthouse.h"
|
||||||
#include "travelthru.h"
|
#include "travelthru.h"
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
|
#include "spells.h"
|
||||||
|
|
||||||
#include <kernel/ally.h>
|
#include <kernel/ally.h>
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
|
@ -474,12 +475,11 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
|
||||||
u1->number = 4;
|
u1->number = 4;
|
||||||
u1->building = b;
|
u1->building = b;
|
||||||
set_level(u1, SK_PERCEPTION, 3);
|
set_level(u1, SK_PERCEPTION, 3);
|
||||||
CuAssertIntEquals(tc, 1, lighthouse_range(b, u1->faction));
|
CuAssertIntEquals(tc, 1, lighthouse_range(b, u1->faction, u1));
|
||||||
CuAssertPtrEquals(tc, b, inside_building(u1));
|
CuAssertPtrEquals(tc, b, inside_building(u1));
|
||||||
u2 = test_create_unit(f, r1);
|
u2 = test_create_unit(f, r1);
|
||||||
u2->building = b;
|
u2->building = b;
|
||||||
set_level(u2, SK_PERCEPTION, 3);
|
set_level(u2, SK_PERCEPTION, 3);
|
||||||
CuAssertIntEquals(tc, 0, lighthouse_range(b, u2->faction));
|
|
||||||
CuAssertPtrEquals(tc, NULL, inside_building(u2));
|
CuAssertPtrEquals(tc, NULL, inside_building(u2));
|
||||||
prepare_report(&ctx, u1->faction);
|
prepare_report(&ctx, u1->faction);
|
||||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||||
|
@ -532,7 +532,12 @@ static void test_prepare_lighthouse(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_prepare_lighthouse_owners(CuTest *tc) {
|
/**
|
||||||
|
* In E3, region owners get the view range benefit of
|
||||||
|
* any lighthouse in the region.
|
||||||
|
*/
|
||||||
|
static void test_prepare_lighthouse_owners(CuTest *tc)
|
||||||
|
{
|
||||||
report_context ctx;
|
report_context ctx;
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r1, *r2, *r3;
|
region *r1, *r2, *r3;
|
||||||
|
@ -558,8 +563,9 @@ static void test_prepare_lighthouse_owners(CuTest *tc) {
|
||||||
u = test_create_unit(f, r1);
|
u = test_create_unit(f, r1);
|
||||||
u = test_create_unit(test_create_faction(0), r1);
|
u = test_create_unit(test_create_faction(0), r1);
|
||||||
u->building = b;
|
u->building = b;
|
||||||
set_level(u, SK_PERCEPTION, 3);
|
|
||||||
region_set_owner(b->region, f, 0);
|
region_set_owner(b->region, f, 0);
|
||||||
|
set_level(u, SK_PERCEPTION, 3);
|
||||||
|
CuAssertIntEquals(tc, 2, lighthouse_range(b, f, NULL));
|
||||||
prepare_report(&ctx, f);
|
prepare_report(&ctx, f);
|
||||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||||
|
@ -707,6 +713,30 @@ static void test_region_distance_ql(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_report_far_vision(CuTest *tc) {
|
||||||
|
unit *u1;
|
||||||
|
faction *f;
|
||||||
|
region *r1, *r2;
|
||||||
|
const race *rc;
|
||||||
|
test_setup();
|
||||||
|
f = test_create_faction(0);
|
||||||
|
r1 = test_create_region(0, 0, 0);
|
||||||
|
u1 = test_create_unit(f, r1);
|
||||||
|
r2 = test_create_region(10, 0, 0);
|
||||||
|
rc = test_create_race("spell");
|
||||||
|
set_observer(r2, f, 10);
|
||||||
|
CuAssertPtrEquals(tc, r1, f->first);
|
||||||
|
CuAssertPtrEquals(tc, r2, f->last);
|
||||||
|
report_context ctx;
|
||||||
|
prepare_report(&ctx, f);
|
||||||
|
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||||
|
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||||
|
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||||
|
CuAssertIntEquals(tc, seen_spell, r2->seen.mode);
|
||||||
|
finish_reports(&ctx);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_reports_suite(void)
|
CuSuite *get_reports_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -724,6 +754,7 @@ CuSuite *get_reports_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_get_addresses);
|
SUITE_ADD_TEST(suite, test_get_addresses);
|
||||||
SUITE_ADD_TEST(suite, test_get_addresses_fstealth);
|
SUITE_ADD_TEST(suite, test_get_addresses_fstealth);
|
||||||
SUITE_ADD_TEST(suite, test_get_addresses_travelthru);
|
SUITE_ADD_TEST(suite, test_get_addresses_travelthru);
|
||||||
|
SUITE_ADD_TEST(suite, test_report_far_vision);
|
||||||
SUITE_ADD_TEST(suite, test_reorder_units);
|
SUITE_ADD_TEST(suite, test_reorder_units);
|
||||||
SUITE_ADD_TEST(suite, test_seen_faction);
|
SUITE_ADD_TEST(suite, test_seen_faction);
|
||||||
SUITE_ADD_TEST(suite, test_regionid);
|
SUITE_ADD_TEST(suite, test_regionid);
|
||||||
|
|
123
src/spells.c
123
src/spells.c
|
@ -447,7 +447,7 @@ report_effect(region * r, unit * mage, message * seen, message * unseen)
|
||||||
* Vertrauten sehen, und durch den Vertrauten zaubern, allerdings nur
|
* Vertrauten sehen, und durch den Vertrauten zaubern, allerdings nur
|
||||||
* mit seiner halben Stufe. Je nach Vertrautem erhaelt der Magier
|
* mit seiner halben Stufe. Je nach Vertrautem erhaelt der Magier
|
||||||
* evtl diverse Skillmodifikationen. Der Typ des Vertrauten ist
|
* evtl diverse Skillmodifikationen. Der Typ des Vertrauten ist
|
||||||
* zufaellig bestimmt, wird aber durch Magiegebiet und Rasse beeinflu<EFBFBD>t.
|
* zufaellig bestimmt, wird aber durch Magiegebiet und Rasse beeinflußt.
|
||||||
* "Tierische" Vertraute brauchen keinen Unterhalt.
|
* "Tierische" Vertraute brauchen keinen Unterhalt.
|
||||||
*
|
*
|
||||||
* Ein paar Moeglichkeiten:
|
* Ein paar Moeglichkeiten:
|
||||||
|
@ -4115,6 +4115,94 @@ static int sp_bigrecruit(castorder * co)
|
||||||
return cast_level;
|
return cast_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct obs_data {
|
||||||
|
faction *f;
|
||||||
|
int skill;
|
||||||
|
int timer;
|
||||||
|
} obs_data;
|
||||||
|
|
||||||
|
static void obs_init(struct attrib *a)
|
||||||
|
{
|
||||||
|
a->data.v = malloc(sizeof(obs_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void obs_done(struct attrib *a)
|
||||||
|
{
|
||||||
|
free(a->data.v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obs_age(struct attrib *a, void *owner)
|
||||||
|
{
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
update_interval(od->f, (region *)owner);
|
||||||
|
return --od->timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void obs_write(const struct attrib *a, const void *owner, struct storage *store)
|
||||||
|
{
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
write_faction_reference(od->f, store);
|
||||||
|
WRITE_INT(store, od->skill);
|
||||||
|
WRITE_INT(store, od->timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int obs_read(struct attrib *a, void *owner, struct gamedata *data)
|
||||||
|
{
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
|
||||||
|
read_reference(&od->f, data, read_faction_reference, resolve_faction);
|
||||||
|
READ_INT(data->store, &od->skill);
|
||||||
|
READ_INT(data->store, &od->timer);
|
||||||
|
return AT_READ_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
attrib_type at_observer = { "observer", obs_init, obs_done, obs_age, obs_write, obs_read };
|
||||||
|
|
||||||
|
static attrib *make_observer(faction *f, int perception)
|
||||||
|
{
|
||||||
|
attrib * a = a_new(&at_observer);
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
od->f = f;
|
||||||
|
od->skill = perception;
|
||||||
|
od->timer = 2;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_observer(region *r, faction *f) {
|
||||||
|
if (fval(r, RF_OBSERVER)) {
|
||||||
|
attrib *a = a_find(r->attribs, &at_observer);
|
||||||
|
while (a && a->type == &at_observer) {
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
if (od->f == f) {
|
||||||
|
return od->skill;
|
||||||
|
}
|
||||||
|
a = a->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_observer(region *r, faction *f, int skill)
|
||||||
|
{
|
||||||
|
update_interval(f, r);
|
||||||
|
if (fval(r, RF_OBSERVER)) {
|
||||||
|
attrib *a = a_find(r->attribs, &at_observer);
|
||||||
|
while (a && a->type == &at_observer) {
|
||||||
|
obs_data *od = (obs_data *)a->data.v;
|
||||||
|
if (od->f == f && od->skill < skill) {
|
||||||
|
od->skill = skill;
|
||||||
|
od->timer = 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
a = a->nexttype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fset(r, RF_OBSERVER);
|
||||||
|
}
|
||||||
|
a_add(&r->attribs, make_observer(f, skill));
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/* Name: Aushorchen
|
/* Name: Aushorchen
|
||||||
* Stufe: 7
|
* Stufe: 7
|
||||||
|
@ -4171,12 +4259,7 @@ static int sp_pump(castorder * co)
|
||||||
return cast_level / 2;
|
return cast_level / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
u =
|
set_observer(rt, mage->faction, effskill(target, SK_PERCEPTION, 0));
|
||||||
create_unit(rt, mage->faction, 1, get_race(RC_SPELL), 0,
|
|
||||||
"spell/pump", NULL);
|
|
||||||
u->age = 2;
|
|
||||||
set_level(u, SK_PERCEPTION, effskill(target, SK_PERCEPTION, 0));
|
|
||||||
|
|
||||||
return cast_level;
|
return cast_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4776,7 +4859,7 @@ int sp_clonecopy(castorder * co)
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
int sp_dreamreading(castorder * co)
|
int sp_dreamreading(castorder * co)
|
||||||
{
|
{
|
||||||
unit *u, *u2;
|
unit *u;
|
||||||
region *r = co_get_region(co);
|
region *r = co_get_region(co);
|
||||||
unit *mage = co->magician.u;
|
unit *mage = co->magician.u;
|
||||||
int cast_level = co->level;
|
int cast_level = co->level;
|
||||||
|
@ -4809,12 +4892,7 @@ int sp_dreamreading(castorder * co)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u2 =
|
set_observer(u->region, mage->faction, effskill(u, SK_PERCEPTION, u->region));
|
||||||
create_unit(u->region, mage->faction, 1, get_race(RC_SPELL), 0,
|
|
||||||
"spell/dreamreading", NULL);
|
|
||||||
set_number(u2, 1);
|
|
||||||
u2->age = 2; /* Nur fuer diese Runde. */
|
|
||||||
set_level(u2, SK_PERCEPTION, effskill(u, SK_PERCEPTION, u2->region));
|
|
||||||
|
|
||||||
msg =
|
msg =
|
||||||
msg_message("sp_dreamreading_effect", "mage unit region", mage, u,
|
msg_message("sp_dreamreading_effect", "mage unit region", mage, u,
|
||||||
|
@ -5609,7 +5687,7 @@ int sp_showastral(castorder * co)
|
||||||
region *r2 = rl2->data;
|
region *r2 = rl2->data;
|
||||||
if (!is_cursed(r2->attribs, C_ASTRALBLOCK, 0)) {
|
if (!is_cursed(r2->attribs, C_ASTRALBLOCK, 0)) {
|
||||||
for (u = r2->units; u; u = u->next) {
|
for (u = r2->units; u; u = u->next) {
|
||||||
if (u_race(u) != get_race(RC_SPECIAL) && u_race(u) != get_race(RC_SPELL))
|
if (u_race(u) != get_race(RC_SPELL))
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5619,7 +5697,8 @@ int sp_showastral(castorder * co)
|
||||||
/* sprintf(buf, "%s kann niemanden im astralen Nebel entdecken.",
|
/* sprintf(buf, "%s kann niemanden im astralen Nebel entdecken.",
|
||||||
unitname(mage)); */
|
unitname(mage)); */
|
||||||
cmistake(mage, co->order, 220, MSG_MAGIC);
|
cmistake(mage, co->order, 220, MSG_MAGIC);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
/* Ausgeben */
|
/* Ausgeben */
|
||||||
|
|
||||||
|
@ -5629,7 +5708,7 @@ int sp_showastral(castorder * co)
|
||||||
for (rl2 = rl; rl2; rl2 = rl2->next) {
|
for (rl2 = rl; rl2; rl2 = rl2->next) {
|
||||||
if (!is_cursed(rl2->data->attribs, C_ASTRALBLOCK, 0)) {
|
if (!is_cursed(rl2->data->attribs, C_ASTRALBLOCK, 0)) {
|
||||||
for (u = rl2->data->units; u; u = u->next) {
|
for (u = rl2->data->units; u; u = u->next) {
|
||||||
if (u_race(u) != get_race(RC_SPECIAL) && u_race(u) != get_race(RC_SPELL)) {
|
if (u_race(u) != get_race(RC_SPELL)) {
|
||||||
c++;
|
c++;
|
||||||
scat(unitname(u));
|
scat(unitname(u));
|
||||||
scat(" (");
|
scat(" (");
|
||||||
|
@ -5645,7 +5724,8 @@ int sp_showastral(castorder * co)
|
||||||
scat(")");
|
scat(")");
|
||||||
if (c == n - 1) {
|
if (c == n - 1) {
|
||||||
scat(" und ");
|
scat(" und ");
|
||||||
} else if (c < n - 1) {
|
}
|
||||||
|
else if (c < n - 1) {
|
||||||
scat(", ");
|
scat(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5667,7 +5747,6 @@ int sp_showastral(castorder * co)
|
||||||
int sp_viewreality(castorder * co)
|
int sp_viewreality(castorder * co)
|
||||||
{
|
{
|
||||||
region_list *rl, *rl2;
|
region_list *rl, *rl2;
|
||||||
unit *u;
|
|
||||||
region *r = co_get_region(co);
|
region *r = co_get_region(co);
|
||||||
unit *mage = co->magician.u;
|
unit *mage = co->magician.u;
|
||||||
int cast_level = co->level;
|
int cast_level = co->level;
|
||||||
|
@ -5686,11 +5765,7 @@ int sp_viewreality(castorder * co)
|
||||||
for (rl2 = rl; rl2; rl2 = rl2->next) {
|
for (rl2 = rl; rl2; rl2 = rl2->next) {
|
||||||
region *rt = rl2->data;
|
region *rt = rl2->data;
|
||||||
if (!is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) {
|
if (!is_cursed(rt->attribs, C_ASTRALBLOCK, 0)) {
|
||||||
u =
|
set_observer(rt, mage->faction, co->level / 2);
|
||||||
create_unit(rt, mage->faction, 1, get_race(RC_SPELL), 0,
|
|
||||||
"spell/viewreality", NULL);
|
|
||||||
set_level(u, SK_PERCEPTION, co->level / 2);
|
|
||||||
u->age = 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,15 @@ extern "C" {
|
||||||
struct ship;
|
struct ship;
|
||||||
struct curse;
|
struct curse;
|
||||||
struct unit;
|
struct unit;
|
||||||
|
struct faction;
|
||||||
|
struct region;
|
||||||
struct message;
|
struct message;
|
||||||
|
|
||||||
void register_magicresistance(void);
|
void register_magicresistance(void);
|
||||||
void register_spells(void);
|
void register_spells(void);
|
||||||
void set_spelldata(struct spell *sp);
|
|
||||||
|
void set_observer(struct region *r, struct faction *f, int perception);
|
||||||
|
int get_observer(struct region *r, struct faction *f);
|
||||||
|
|
||||||
int sp_baddreams(castorder * co);
|
int sp_baddreams(castorder * co);
|
||||||
int sp_gooddreams(castorder * co);
|
int sp_gooddreams(castorder * co);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <kernel/curse.h>
|
#include <kernel/curse.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/order.h>
|
#include <kernel/order.h>
|
||||||
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
@ -108,9 +109,28 @@ static void test_bad_dreams(CuTest *tc) {
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_watch_region(CuTest *tc) {
|
||||||
|
region *r;
|
||||||
|
faction *f;
|
||||||
|
test_setup();
|
||||||
|
test_create_race("spell");
|
||||||
|
CuAssertPtrNotNull(tc, get_race(RC_SPELL));
|
||||||
|
r = test_create_region(0, 0, 0);
|
||||||
|
f = test_create_faction(0);
|
||||||
|
CuAssertIntEquals(tc, -1, get_observer(r, f));
|
||||||
|
set_observer(r, f, 0);
|
||||||
|
CuAssertIntEquals(tc, 0, get_observer(r, f));
|
||||||
|
set_observer(r, f, 10);
|
||||||
|
CuAssertIntEquals(tc, 10, get_observer(r, f));
|
||||||
|
CuAssertIntEquals(tc, RF_OBSERVER, fval(r, RF_OBSERVER));
|
||||||
|
CuAssertPtrNotNull(tc, r->attribs);
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_spells_suite(void)
|
CuSuite *get_spells_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
SUITE_ADD_TEST(suite, test_watch_region);
|
||||||
SUITE_ADD_TEST(suite, test_good_dreams);
|
SUITE_ADD_TEST(suite, test_good_dreams);
|
||||||
SUITE_ADD_TEST(suite, test_bad_dreams);
|
SUITE_ADD_TEST(suite, test_bad_dreams);
|
||||||
SUITE_ADD_TEST(suite, test_dreams);
|
SUITE_ADD_TEST(suite, test_dreams);
|
||||||
|
|
Loading…
Reference in New Issue