Crossfire Server, Trunk
replace_in_map.py
Go to the documentation of this file.
1 import Crossfire
2 import random
3 from CFMapTransformer import CFMapTransformer
4 from CFTimeOfDay import TimeOfDay
5 import cjson
6 import string
7 
8 
9 event = Crossfire.WhatIsEvent()
10 alreadymatched = (event.Value!=0)
11 parameters = cjson.decode(event.Message)
12 current = TimeOfDay()
13 #current.log()
14 inverse = "inverse" in parameters and parameters["inverse"] == True
15 match = False
16 if not "match" in parameters:
17  Crossfire.Log(Crossfire.LogError,"Script replace_in_map.py didn't get a 'match' parameter. Only got %s" %parameters)
18 elif parameters["match"].lower() == "one":
19  match=TimeOfDay().matchAny(parameters["when"]) != inverse
20 elif parameters["match"].lower() == "all":
21  match=TimeOfDay().matchAll(parameters["when"]) != inverse
22 else:
23  Crossfire.Log(Crossfire.LogError,"Script replace_in_map.py didn't get a 'match' parameter. Only got %s" %parameters)
24 
25 #print "match is %s and alreadymatched is %s" %(match,alreadymatched)
26 
27 if (match != alreadymatched):
28  transformer = CFMapTransformer(parameters["key"])
29  if (match):
30  Crossfire.Log(Crossfire.LogDebug,"Transforming %s into %s" %(parameters["from"],parameters["to"]))
31  transformer.transformAll(parameters["from"],parameters["to"])
32  event.Value=1
33  else:
34  transformer.untransformAll()
35  event.Value=0
36 
37 #if random.randint(0,2) == 0 :
38 # print "transform mode"
39 # transformer.transformAll("skeleton",["bones1","bones2","bones3","bones4"])
40 #else:
41 # print "untransform mode"
42 # transformer.untransformAll()
CFMapTransformer.CFMapTransformer
Definition: CFMapTransformer.py:58
CFTimeOfDay.TimeOfDay
Definition: CFTimeOfDay.py:3