2001-01-25 10:37:55 +01:00
/* vi: set ts=2:
*
2001-04-14 13:39:14 +02:00
*
2001-01-25 10:37:55 +01:00
* Eressea PB ( E ) M host Copyright ( C ) 1998 - 2000
* 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 <EFBFBD> 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 <config.h>
# include "eressea.h"
# include "teleport.h"
2001-12-10 01:13:39 +01:00
/* kernel includes */
2001-01-25 10:37:55 +01:00
# include "unit.h"
# include "region.h"
2001-12-10 01:13:39 +01:00
# include "race.h"
2002-02-10 14:23:30 +01:00
# include "skill.h"
2001-01-25 10:37:55 +01:00
# include "faction.h"
# include "plane.h"
2001-12-10 01:13:39 +01:00
/* libc includes */
2001-01-25 10:37:55 +01:00
# include <assert.h>
# include <stdlib.h>
static int
real2tp ( int rk ) {
/* in C:
* - 4 / 5 = 0 ;
* + 4 / 5 = 0 ;
* ! ! ! ! ! ! ! ! ! ! ;
*/
return ( rk + ( TP_RADIUS * 5000 ) ) / TP_RADIUS - 5000 ;
}
static region *
2001-09-05 21:40:40 +02:00
tpregion ( const region * r ) {
2001-01-25 10:37:55 +01:00
return findregion ( TE_CENTER_X + real2tp ( r - > x ) , TE_CENTER_Y + real2tp ( r - > y ) ) ;
}
region *
2001-09-05 21:40:40 +02:00
r_standard_to_astral ( const region * r )
2001-01-25 10:37:55 +01:00
{
region * r2 ;
#if 0
int x , y ;
x = TE_CENTER_X + ( r - > x / TP_RADIUS ) ;
y = TE_CENTER_Y + ( r - > y / TP_RADIUS ) ;
r2 = findregion ( x , y ) ;
# endif
r2 = tpregion ( r ) ;
if ( getplaneid ( r2 ) ! = 1 | | rterrain ( r2 ) ! = T_ASTRAL )
return NULL ;
return r2 ;
}
region *
2001-09-05 21:40:40 +02:00
r_astral_to_standard ( const region * r )
2001-01-25 10:37:55 +01:00
{
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 ;
r2 = findregion ( x , y ) ;
if ( ! r2 | | getplaneid ( r2 ) ! = 0 )
return NULL ;
return r2 ;
}
regionlist *
all_in_range ( region * r , int n )
{
int x , y ;
regionlist * rlist = NULL ;
region * r2 ;
if ( r = = NULL ) return NULL ; /* Um Probleme abzufangen,
wenn zu einer Astralregion
noch kein Realit <EFBFBD> tsregion existiert .
Nicht gut , aber nicht zu <EFBFBD> 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 ) ;
2002-01-09 09:20:33 +01:00
if ( r2 ) add_regionlist ( & rlist , findregion ( x , y ) ) ;
2001-01-25 10:37:55 +01:00
}
}
}
return rlist ;
}
void
random_in_teleport_plane ( void )
{
region * r ;
unit * u ;
faction * f0 = findfaction ( MONSTER_FACTION ) ;
2001-12-10 01:13:39 +01:00
if ( ! f0 ) return ;
2001-01-25 10:37:55 +01:00
for ( r = regions ; r ; r = r - > next ) {
if ( getplaneid ( r ) ! = 1 | | rterrain ( r ) ! = T_ASTRAL ) continue ;
/* Neues Monster ? */
if ( rand ( ) % 100 = = 0 ) {
switch ( rand ( ) % 1 ) {
case 0 :
2001-12-10 01:13:39 +01:00
u = createunit ( r , f0 , 1 + rand ( ) % 10 + rand ( ) % 10 , new_race [ RC_HIRNTOETER ] ) ;
2001-01-25 10:37:55 +01:00
set_string ( & u - > name , " Hirnt<EFBFBD> ter " ) ;
set_string ( & u - > display , " Wabernde gr<67> 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. " ) ;
2002-02-10 14:23:30 +01:00
set_level ( u , SK_STEALTH , 1 ) ;
set_level ( u , SK_OBSERVATION , 1 ) ;
2001-01-25 10:37:55 +01:00
break ;
}
}
}
}
plane * astral_plane ;
void
create_teleport_plane ( void )
{
region * r ;
int i ;
if ( ! getplanebyid ( 1 ) ) {
astral_plane = create_new_plane ( 1 , " Astralraum " ,
TE_CENTER_X - 500 , TE_CENTER_X + 500 ,
TE_CENTER_Y - 500 , TE_CENTER_Y + 500 ,
2002-01-28 01:25:32 +01:00
0 ) ;
2001-01-25 10:37:55 +01:00
}
/* Regionsbereich aufbauen. */
/* wichtig: das mu<6D> auch f<> r neue regionen gemacht werden.
* Evtl . bringt man es besser in new_region ( ) unter , und
* <EFBFBD> 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 ) ;
2001-04-22 20:14:07 +02:00
if ( terrain [ rterrain ( r ) ] . flags & FORBIDDEN_LAND ) rsetterrain ( ra , T_ASTRALB ) ;
2001-01-25 10:37:55 +01:00
}
for ( i = 0 ; i < 4 ; i + + ) {
random_in_teleport_plane ( ) ;
}
}
regionlist *
2001-09-05 21:40:40 +02:00
allinhab_in_range ( const region * r , int n )
2001-01-25 10:37:55 +01:00
{
int x , y ;
regionlist * rlist = NULL ;
region * r2 ;
if ( r = = NULL ) return NULL ; /* Um Probleme abzufangen,
wenn zu einer Astralregion
noch kein Realit <EFBFBD> tsregion existiert .
Nicht gut , aber nicht zu <EFBFBD> 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 ) ) )
2002-01-09 09:20:33 +01:00
add_regionlist ( & rlist , findregion ( x , y ) ) ;
2001-01-25 10:37:55 +01:00
}
}
}
return rlist ;
}