From 1b4bfe0c53561820f0135e2408ae09d90c5e1a46 Mon Sep 17 00:00:00 2001 From: ryo_saeba Date: Sat, 8 Oct 2005 09:47:06 +0000 Subject: [PATCH] GPS script git-svn-id: svn://svn.code.sf.net/p/crossfire/code/trunk/maps@3840 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/items/positioning_system.py | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 python/items/positioning_system.py diff --git a/python/items/positioning_system.py b/python/items/positioning_system.py new file mode 100644 index 000000000..9dc9c77e6 --- /dev/null +++ b/python/items/positioning_system.py @@ -0,0 +1,43 @@ +import CFPython + +world_prefix = '/world/world_' +world_len = len( world_prefix ) + len( 'xxx_xxx' ) +world_sep = '_' +world_map_size = 50 + +CFPython.SetReturnValue( 1 ) + +player = CFPython.WhoIsActivator() +gps = CFPython.WhoAmI() +map = CFPython.GetMap( player ) + +if ( map == 0 ): + CFPython.CFWrite( 'You\'re lost in a vacuum!', player ) +else: + path = CFPython.GetMapPath( map ) + if ( path.find( world_prefix ) != 0 ) or ( len( path ) != world_len ): + CFPython.Write( 'You can\'t position yourself here.', player ) + else: + marked = CFPython.GetMarkedItem( player ) + + if ( marked != gps ) and ( CFPython.GetFood( gps ) == 0 ): + CFPython.Write( 'You must fix the origin of the positioning system first!', player ) + else: + coord = path.split( world_sep ) + if ( len( coord ) != 3 ): + CFPython.Write( 'Strange place, you can\'t position yourself...', player ) + else: + map_x = int( coord[ 1 ] ) - 99 + map_y = int( coord[ 2 ] ) - 99 + x = map_x * world_map_size + CFPython.GetXPosition( player ) + y = map_y * world_map_size + CFPython.GetYPosition( player ) + + if ( marked == gps ): + CFPython.SetHP( gps, x ) + CFPython.SetSP( gps, y ) + CFPython.SetFood( gps, 1 ) + CFPython.Write( 'You reset the origin of the system.', player ) + else: + x = x - CFPython.GetHP( gps ) + y = y - CFPython.GetSP( gps ) + CFPython.Write( 'You are at %s:%s.'%( x, y ), player )