From 85d03834719659910ac4421a5a8c838f04d6adb9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 24 May 2004 23:09:10 +0000 Subject: [PATCH] =?UTF-8?q?http://eressea.upb.de/mantis/bug=5Fview=5Fpage.?= =?UTF-8?q?php=3Fbug=5Fid=3D0000023=20-=20ich=20denke,=20es=20liegt=20dara?= =?UTF-8?q?n=20dass=20es=20regionen=20gibt,=20die=20schemen=20zweier=20and?= =?UTF-8?q?erer=20regionen=20sind=20-=20f=C3=BCr=20die=20ist=20nicht=20kla?= =?UTF-8?q?r,=20welche=20astralregion=20bei=20zaubern=20wie=20dem=20tor=20?= =?UTF-8?q?benutzt=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/gamecode/creport.c | 2 +- src/common/gamecode/report.c | 2 +- src/common/items/birthday_firework.c | 2 +- src/common/kernel/movement.c | 3 +- src/common/kernel/spell.c | 20 +- src/common/kernel/teleport.c | 276 ++++++++++++++------------- src/common/kernel/teleport.h | 24 +-- 7 files changed, 163 insertions(+), 166 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index e72a9cae4..690cd4b40 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -1348,7 +1348,7 @@ report_computer(FILE * F, faction * f, const faction_list * addresses, if (sd->mode==see_unit && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { /* Sonderbehandlung Teleport-Ebene */ - region_list *rl = allinhab_in_range(r_astral_to_standard(r),TP_RADIUS); + region_list *rl = astralregions(r_astral_to_standard(r), inhabitable); if (rl) { region_list *rl2 = rl; diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index cac570562..eba905579 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1367,7 +1367,7 @@ describe(FILE * F, const region * r, int partial, faction * f) if (partial==0 && r->planep && r->planep->id == 1 && !is_cursed(r->attribs, C_ASTRALBLOCK, 0)) { /* Sonderbehandlung Teleport-Ebene */ - region_list *rl = allinhab_in_range(r_astral_to_standard(r), TP_RADIUS); + region_list *rl = astralregions(r_astral_to_standard(r), inhabitable); region_list *rl2; if (rl) { diff --git a/src/common/items/birthday_firework.c b/src/common/items/birthday_firework.c index 90c3093b3..e7c793664 100644 --- a/src/common/items/birthday_firework.c +++ b/src/common/items/birthday_firework.c @@ -38,7 +38,7 @@ const int FIREWORK_RANGE=10; static int use_birthday_firework(struct unit * u, const struct item_type * itype, int amount, const char *cm) { - region_list *rlist = all_in_range(u->region, FIREWORK_RANGE); + region_list *rlist = all_in_range(u->region, FIREWORK_RANGE, NULL); region_list *rl; message *m; const char *name; diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index d1dc7f781..79b115394 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -41,6 +41,7 @@ #include "spell.h" #include "ship.h" #include "skill.h" +#include "teleport.h" #include "unit.h" /* util includes */ @@ -1065,7 +1066,7 @@ travel(unit * u, region * next, int flucht, region_list ** routep) /* Im Astralraum sind Tyb und Ill-Magier doppelt so schnell. * Nicht kumulativ mit anderen Beschleunigungen! */ - if ( mp == 1 && getplane(next) == astral_plane && is_mage(u)) { + if ( mp == 1 && getplane(next) == get_astralplane() && is_mage(u)) { if(get_mage(u)->magietyp == M_ASTRAL || get_mage(u)->magietyp == M_TRAUM) { mp *= 2; diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index 54cf7979f..cd733d401 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -1916,7 +1916,7 @@ sp_treewalkexit(castorder *co) spellparameter *pa = co->par; int cast_level = co->level; - if(getplane(r) != astral_plane) { + if(getplane(r) != get_astralplane()) { cmistake(mage, strdup(co->order), 193, MSG_MAGIC); return 0; } @@ -1939,7 +1939,7 @@ sp_treewalkexit(castorder *co) tay = rt->y; rt = NULL; - rl = allinhab_in_range(r_astral_to_standard(r),TP_RADIUS); + rl = astralregions(r_astral_to_standard(r), inhabitable); rt = 0; rl2 = rl; @@ -2232,7 +2232,7 @@ sp_fog_of_confusion(castorder *co) range = (power-11)/3-1; duration = (int)((power-11)/1.5)+1; - rl = all_in_range(r, (int)range); + rl = all_in_range(r, (int)range, NULL); for(rl2 = rl; rl2; rl2 = rl2->next) { curse * c; @@ -2807,7 +2807,7 @@ sp_summondragon(castorder *co) } } - rl = all_in_range(r, (int)power); + rl = all_in_range(r, (int)power, NULL); for(rl2 = rl; rl2; rl2 = rl2->next) { for(u = rl2->data->units; u; u = u->next) { @@ -5598,7 +5598,7 @@ sp_dream_of_confusion(castorder *co) double range = (power-14)/2-1; int duration = (int)(power-14)+1; - rl = all_in_range(r, (int)range); + rl = all_in_range(r, (int)range, NULL); for(rl2 = rl; rl2; rl2 = rl2->next) { region * r2 = rl2->data; @@ -5934,7 +5934,7 @@ sp_pullastral(castorder *co) case 1: rt = r; ro = pa->param[0]->data.r; - rl = all_in_range(r_astral_to_standard(r), TP_RADIUS); + rl = astralregions(r_astral_to_standard(r), NULL); rl2 = rl; while (rl2!=NULL) { region * r2 = rl2->data; @@ -6066,7 +6066,7 @@ sp_leaveastral(castorder *co) MSG_MAGIC, ML_MISTAKE); return 0; } - rl = allinhab_in_range(r_astral_to_standard(r), TP_RADIUS); + rl = astralregions(r_astral_to_standard(r), inhabitable); rl2 = rl; while (rl2!=NULL) { if (rl2->data == rt) break; @@ -6391,7 +6391,7 @@ sp_viewreality(castorder *co) return 0; } - rl = all_in_range(r_astral_to_standard(r), TP_RADIUS); + rl = astralregions(r_astral_to_standard(r), NULL); /* Irgendwann mal auf Curses u/o Attribut umstellen. */ for (rl2=rl; rl2; rl2=rl2->next) { @@ -6440,7 +6440,7 @@ sp_disruptastral(castorder *co) return 0; } - rl = all_in_range(rt, (int)(power/5)); + rl = all_in_range(rt, (int)(power/5), NULL); for (rl2=rl; rl2!=NULL; rl2=rl2->next) { attrib *a, *a2; @@ -6454,7 +6454,7 @@ sp_disruptastral(castorder *co) if (r2->units!=NULL) { region_list * trl2; - trl = allinhab_in_range(r_astral_to_standard(rl2->data), TP_RADIUS); + trl = astralregions(r_astral_to_standard(rl2->data), inhabitable); for (trl2 = trl; trl2; trl2 = trl2->next) ++inhab_regions; } diff --git a/src/common/kernel/teleport.c b/src/common/kernel/teleport.c index e07630b32..86a683cfa 100644 --- a/src/common/kernel/teleport.c +++ b/src/common/kernel/teleport.c @@ -1,23 +1,23 @@ /* vi: set ts=2: - * - * - * Eressea PB(E)M host Copyright (C) 1998-2003 - * Christian Schlittchen (corwin@amber.kn-bremen.de) - * Katja Zedel (katze@felidae.kn-bremen.de) - * Henning Peters (faroul@beyond.kn-bremen.de) - * Enno Rehling (enno@eressea-pbem.de) - * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) - * - * based on: - * - * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace - * Atlantis v1.7 Copyright 1996 by Alex Schröder - * - * This program may not be used, modified or distributed without - * prior permission by the authors of Eressea. - * This program may not be sold or used commercially without prior written - * permission from the authors. - */ +* +* +* Eressea PB(E)M host Copyright (C) 1998-2003 +* Christian Schlittchen (corwin@amber.kn-bremen.de) +* Katja Zedel (katze@felidae.kn-bremen.de) +* Henning Peters (faroul@beyond.kn-bremen.de) +* Enno Rehling (enno@eressea-pbem.de) +* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) +* +* based on: +* +* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace +* Atlantis v1.7 Copyright 1996 by Alex Schröder +* +* This program may not be used, modified or distributed without +* prior permission by the authors of Eressea. +* This program may not be sold or used commercially without prior written +* permission from the authors. +*/ #include #include "eressea.h" @@ -35,170 +35,172 @@ #include #include +#define TE_CENTER_X 1000 +#define TE_CENTER_Y 1000 +#define TP_RADIUS 4 + static int real2tp(int rk) { - /* in C: - * -4 / 5 = 0; - * +4 / 5 = 0; - * !!!!!!!!!!; - */ - return (rk + (TP_RADIUS*5000)) / TP_RADIUS - 5000; + /* in C: + * -4 / 5 = 0; + * +4 / 5 = 0; + * !!!!!!!!!!; + */ + return (rk + (TP_RADIUS*5000)) / TP_RADIUS - 5000; } static region * tpregion(const region *r) { - return findregion(TE_CENTER_X+real2tp(r->x), TE_CENTER_Y+real2tp(r->y)); + return findregion(TE_CENTER_X+real2tp(r->x), TE_CENTER_Y+real2tp(r->y)); +} + +region_list * +astralregions(const region * r, boolean (*valid)(const region *)) +{ + region_list * rlist = NULL; + int x, y; + + assert(rplane(r) == NULL); + if (r==NULL) return NULL; + r = r_astral_to_standard(r); + + for (x=r->x-TP_RADIUS;x<=r->x+TP_RADIUS;++x) { + for (y=r->y-TP_RADIUS;y<=r->y+TP_RADIUS;++y) { + region * rn; + int dist = koor_distance(r->x, r->y, x, y); + + if (dist > TP_RADIUS) continue; + if (dist==4) { + /* these three regions are in dispute with the NW, W & SW areas */ + if (x==-2 && y==0) continue; + if (x==-2 && y==2) continue; + if (x==0 && y==-2) continue; + } + rn = findregion(x, y); + if (rn!=NULL && (valid==NULL || valid(rn))) add_regionlist(&rlist, rn); + } + } + return rlist; } region * r_standard_to_astral(const region *r) { - region *r2; -#if 0 - int x, y; + region *r2; + r2 = tpregion(r); - x = TE_CENTER_X + (r->x/TP_RADIUS); - y = TE_CENTER_Y + (r->y/TP_RADIUS); + if (rplane(r2) != get_astralplane() || rterrain(r2) != T_ASTRAL) return NULL; - r2 = findregion(x,y); -#endif - - r2 = tpregion(r); - - if(getplaneid(r2) != 1 || rterrain(r2) != T_ASTRAL) - return NULL; - - return r2; + return r2; } region * r_astral_to_standard(const region *r) { - int x, y; - region *r2; + int x, y; + region *r2; - assert(getplaneid(r) == 1); - x = (r->x-TE_CENTER_X)*TP_RADIUS; - y = (r->y-TE_CENTER_Y)*TP_RADIUS; + assert(rplane(r) == get_astralplane()); + x = (r->x-TE_CENTER_X)*TP_RADIUS; + y = (r->y-TE_CENTER_Y)*TP_RADIUS; - r2 = findregion(x,y); - if(!r2 || getplaneid(r2) != 0) - return NULL; + r2 = findregion(x,y); + if (r2!=NULL || getplaneid(r2) != 0) return NULL; - return r2; + return r2; } region_list * -all_in_range(region *r, int n) +all_in_range(const region *r, int n, boolean (*valid)(const region *)) { - int x,y; - region_list *rlist = NULL; - region *r2; + int x,y; + region_list *rlist = NULL; - if(r == NULL) return NULL; /* Um Probleme abzufangen, - wenn zu einer Astralregion - noch kein Realitätsregion existiert. - Nicht gut, aber nicht zu ändern. */ + if (r == NULL) return NULL; - for(x = r->x-n; x <= r->x+n; x++) { - for(y = r->y-n; y <= r->y+n; y++) { - if(koor_distance(r->x, r->y, x, y) <= n) { - r2 = findregion(x,y); - if(r2) add_regionlist(&rlist, findregion(x,y)); - } - } - } + for (x = r->x-n; x <= r->x+n; x++) { + for (y = r->y-n; y <= r->y+n; y++) { + if (koor_distance(r->x, r->y, x, y) <= n) { + region * r2 = findregion(x,y); + if (r2!=NULL && (valid==NULL || valid(r2))) add_regionlist(&rlist, r2); + } + } + } - return rlist; + return rlist; } void random_in_teleport_plane(void) { - region *r; - unit *u; - faction *f0 = findfaction(MONSTER_FACTION); + region *r; + faction *f0 = findfaction(MONSTER_FACTION); + int next = rand() % 100; - if(!f0) return; + if (f0==NULL) return; - for(r=regions; r; r=r->next) { - if(getplaneid(r) != 1 || rterrain(r) != T_ASTRAL) continue; + for (r=regions; r; r=r->next) { + if (rplane(r) != get_astralplane() || rterrain(r) != T_ASTRAL) continue; - /* Neues Monster ? */ - if(rand()%100 == 0) { - switch(rand()%1) { - case 0: - u = createunit(r, f0, 1+rand()%10+rand()%10, new_race[RC_HIRNTOETER]); - set_string(&u->name, "Hirntöter"); - set_string(&u->display, "Wabernde grüne Schwaden treiben durch den Nebel und verdichten sich zu einer unheimlichen Kreatur, die nur aus einem langen Ruderschwanz und einem riesigen runden Maul zu bestehen scheint."); - set_level(u, SK_STEALTH, 1); - set_level(u, SK_OBSERVATION, 1); - break; - } - } - } + /* Neues Monster ? */ + if (next-- == 0) { + unit *u = createunit(r, f0, 1+rand()%10+rand()%10, new_race[RC_HIRNTOETER]); + + set_string(&u->name, "Hirntöter"); + set_string(&u->display, "Wabernde grüne Schwaden treiben durch den Nebel und verdichten sich zu einer unheimlichen Kreatur, die nur aus einem langen Ruderschwanz und einem riesigen runden Maul zu bestehen scheint."); + set_level(u, SK_STEALTH, 1); + set_level(u, SK_OBSERVATION, 1); + next = rand() % 100; + } + } } -plane * astral_plane; +plane * +get_astralplane(void) +{ + static plane * astral_plane = NULL; + if (astral_plane==NULL) { + astral_plane = getplanebyid(1); + } + if (astral_plane==NULL) { + astral_plane = create_new_plane(1, "Astralraum", + TE_CENTER_X-500, TE_CENTER_X+500, + TE_CENTER_Y-500, TE_CENTER_Y+500, 0); + } + return astral_plane; +} void create_teleport_plane(void) { - region *r; - int i; + region *r; + int i; + plane * aplane = get_astralplane(); - astral_plane = getplanebyid(1); + /* Regionsbereich aufbauen. */ + /* wichtig: das muß auch für neue regionen gemacht werden. + * Evtl. bringt man es besser in new_region() unter, und + * übergibt an new_region die plane mit, in der die + * Region gemacht wird. + */ - if (!astral_plane) { - astral_plane = create_new_plane(1, "Astralraum", - TE_CENTER_X-500, TE_CENTER_X+500, - TE_CENTER_Y-500, TE_CENTER_Y+500, - 0); - } + for (r=regions;r;r=r->next) if(r->planep == NULL) { + region *ra = tpregion(r); + if (ra==NULL) { + ra = new_region(TE_CENTER_X+real2tp(r->x), TE_CENTER_Y+real2tp(r->y)); + rsetterrain(ra, T_ASTRAL); + } + ra->planep = aplane; + if (terrain[rterrain(r)].flags & FORBIDDEN_LAND) rsetterrain(ra, T_ASTRALB); + } - /* Regionsbereich aufbauen. */ - /* wichtig: das muß auch für neue regionen gemacht werden. - * Evtl. bringt man es besser in new_region() unter, und - * übergibt an new_region die plane mit, in der die - * Region gemacht wird. - */ - - for (r=regions;r;r=r->next) if(r->planep == NULL) { - region *ra = tpregion(r); - if (!ra) { - ra = new_region(TE_CENTER_X+real2tp(r->x), TE_CENTER_Y+real2tp(r->y)); - rsetterrain(ra, T_ASTRAL); - } - ra->planep = getplanebyid(1); - if (terrain[rterrain(r)].flags & FORBIDDEN_LAND) rsetterrain(ra, T_ASTRALB); - } - - for(i=0;i<4;i++) { - random_in_teleport_plane(); - } + for(i=0;i<4;i++) { + random_in_teleport_plane(); + } } -region_list * -allinhab_in_range(const region *r, int n) +boolean +inhabitable(const region * r) { - int x,y; - region_list *rlist = NULL; - region *r2; - - if(r == NULL) return NULL; /* Um Probleme abzufangen, - wenn zu einer Astralregion - noch kein Realitätsregion existiert. - Nicht gut, aber nicht zu ändern. */ - - for(x = r->x-n; x <= r->x+n; x++) { - for(y = r->y-n; y <= r->y+n; y++) { - if(koor_distance(r->x, r->y, x, y) <= n) { - r2 = findregion(x,y); - if (r2 && landregion(rterrain(r2))) - add_regionlist(&rlist, findregion(x,y)); - } - } - } - - return rlist; + return landregion(rterrain(r)); } diff --git a/src/common/kernel/teleport.h b/src/common/kernel/teleport.h index 0681f419e..bab31d0f1 100644 --- a/src/common/kernel/teleport.h +++ b/src/common/kernel/teleport.h @@ -18,21 +18,15 @@ extern "C" { #endif -#define TE_CENTER_X 1000 -#define TE_CENTER_Y 1000 -#define ENNOS_PLANE 1 -#if ENNOS_PLANE -#define TP_RADIUS 4 -#else -#define RADIUS 75 -#define TP_RADIUS 2 -#endif -struct region *r_standard_to_astral(const struct region *r); -struct region *r_astral_to_standard(const struct region *); -struct region_list *all_in_range(struct region *r, int n); -struct region_list *allinhab_in_range(const struct region *r, int n); -void create_teleport_plane(void); -void set_teleport_plane_regiontypes(void); + struct region *r_standard_to_astral(const struct region *r); + struct region *r_astral_to_standard(const struct region *); + extern struct region_list *astralregions(const struct region * r, boolean (*valid)(const struct region *)); + extern struct region_list *all_in_range(const struct region *r, int n, boolean (*valid)(const struct region *)); + extern boolean inhabitable(const struct region * r); + extern struct plane * get_astralplane(void); + + void create_teleport_plane(void); + void set_teleport_plane_regiontypes(void); #ifdef __cplusplus }