Crossfire Server, Trunk
CFWorld.py
Go to the documentation of this file.
1 #CFWorld.py
2 #A small module for checking where is bigworld an object is if it's in bigworld.
3 import math
4 
5 import Crossfire
6 
7 world_prefix = "/world/world_"
8 world_prefix_len = len(world_prefix)
9 world_len = len(world_prefix) + len('xxx_xxx')
10 world_sep = '_'
11 bigmapxsize = 50
12 bigmapysize = 50
13 
14 #Return an x,y tuple of where in bigworld an object is. Return false if not in bigworld. In current bigworld, values range from 5000 to 6499.
15 def loc_from_ob(ob):
16  cfmap = ob.Map
17  if ((cfmap.Path.find(world_prefix) != 0) or (len(cfmap.Path) != world_len)):
18  return False
19  strloc = cfmap.Path[world_prefix_len:].split(world_sep)
20  x = (int(strloc[0]) * bigmapxsize) + ob.X
21  y = (int(strloc[1]) * bigmapysize) + ob.Y
22  return (x, y)
23 
24 def getdiff(loc1, loc2):
25  return (loc1[0]-loc2[0], loc1[1]-loc2[1])
26 
27 def getdir(v):
28  x, y = v
29  t = math.atan2(x, y)
30  rt = round(t / (math.pi/4)) # between -4 and 4
31  directions = ["north", "northwest", "west", "southwest", "south", "southeast", "east", "northeast"]
32  dir_str = directions[(rt + 4)%8]
33  return dir_str
34 
35 #outputs in furlongs (outdoor tiles)
36 def getdist(loc):
37  return int(math.sqrt((loc[0]*loc[0])+(loc[1]*loc[1])))
CFWorld.loc_from_ob
def loc_from_ob(ob)
Definition: CFWorld.py:15
CFWorld.getdir
def getdir(v)
Definition: CFWorld.py:27
CFWorld.getdiff
def getdiff(loc1, loc2)
Definition: CFWorld.py:24
make_face_from_files.int
int
Definition: make_face_from_files.py:32
CFWorld.getdist
def getdist(loc)
Definition: CFWorld.py:36
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2606