Crossfire Server, Trunk  1.75.0
finding.py
Go to the documentation of this file.
1 # finding.py -- apply event for amulets of finding
2 #
3 # These pieces of jewelry help players remember locations on the world map.
4 # Players can bind an amulet at any location on the world map. Applying a bound
5 # amulet shows players a message indicating which direction they should travel
6 # to return to the bound location.
7 #
8 # The bound location is stored in the key-value pair "finding_location", which
9 # contains a 2-tuple of global coordinates from the CFWorld module.
10 import Crossfire
11 import CFWorld
12 
13 location_key = 'finding_location'
14 world_size = 50
15 
16 def indefinite(ob):
17  """Append 'a' or 'an' to the given object's name."""
18  name = ob.QueryName()
19  if name[0].lower() in {'a', 'e', 'i', 'o'}:
20  article = "an"
21  else:
22  article = "a"
23  return article + " " + name
24 
25 def auto_identify(ob, pl):
26  """Identify the object if it hasn't already."""
27  if not ob.Identified:
28  ob.Identified = True
29  pl.Message("This is %s!" % indefinite(ob))
30 
31 def loc_to_str(l):
32  return ",".join(map(str, l))
33 
34 def str_to_loc(s):
35  return list(map(int, s.split(",")))
36 
37 def describe_vec(v):
38  dist = CFWorld.getdist(v)
39  if dist < 1:
40  return "here"
41  if dist <= world_size:
42  modifier = "strongly"
43  elif dist <= 5*world_size:
44  modifier = "moderately"
45  else:
46  modifier = "lightly"
47  return modifier + " " + CFWorld.getdir(v)
48 
49 def on_apply():
50  whoami = Crossfire.WhoAmI()
51  player = Crossfire.WhoIsActivator()
52 
53  Crossfire.SetReturnValue(1) # do not allow players to wear this
54  auto_identify(whoami, player)
55 
56  if whoami.Env == player:
57  # applied in inventory
58  current_location = CFWorld.loc_from_ob(player)
59  else:
60  # applied on the floor
61  current_location = CFWorld.loc_from_ob(whoami)
62 
63  if current_location == False:
64  # can only be used on the world map
65  player.Message("The %s rattles for a moment, then stops." % whoami.QueryName())
66  return
67 
68  if whoami.Env == player:
69  # applied in inventory
70  stored_str = whoami.ReadKey(location_key)
71  if stored_str == "":
72  # no location bound
73  player.Message("The %s vibrates for a moment, then stops." % whoami.QueryName())
74  return
75  stored_location = str_to_loc(stored_str)
76  delta = CFWorld.getdiff(stored_location, current_location)
77  player.Message("The %s tugs you %s." % (whoami.QueryName(), describe_vec(delta)))
78  else:
79  # applied on the floor
80  whoami.WriteKey(location_key, loc_to_str(current_location), 1)
81  player.Message("The %s glows blue." % whoami.QueryName())
82 
83 on_apply()
finding.auto_identify
def auto_identify(ob, pl)
Definition: finding.py:25
finding.loc_to_str
def loc_to_str(l)
Definition: finding.py:31
finding.on_apply
def on_apply()
Definition: finding.py:49
finding.str_to_loc
def str_to_loc(s)
Definition: finding.py:34
disinfect.map
map
Definition: disinfect.py:4
CFWorld.loc_from_ob
def loc_from_ob(ob)
Definition: CFWorld.py:15
CFWorld.getdir
def getdir(v)
Definition: CFWorld.py:27
finding.describe_vec
def describe_vec(v)
Definition: finding.py:37
finding.indefinite
def indefinite(ob)
Definition: finding.py:16
CFWorld.getdiff
def getdiff(loc1, loc2)
Definition: CFWorld.py:24
CFWorld.getdist
def getdist(loc)
Definition: CFWorld.py:36
list
How to Install a Crossfire Server on you must install a python script engine on your computer Python is the default script engine of Crossfire You can find the python engine you have only to install them The VisualC Crossfire settings are for but you habe then to change the pathes in the VC settings Go in Settings C and Settings Link and change the optional include and libs path to the new python installation path o except the maps ! You must download a map package and install them the share folder Its must look like doubleclick on crossfire32 dsw There are projects in your libcross lib and plugin_python You need to compile all Easiest way is to select the plugin_python ReleaseLog as active this will compile all others too Then in Visual C press< F7 > to compile If you don t have an appropriate compiler you can try to get the the VC copies the crossfire32 exe in the crossfire folder and the plugin_python dll in the crossfire share plugins folder we will remove it when we get time for it o Last showing lots of weird write to the Crossfire mailing list
Definition: INSTALL_WIN32.txt:50