Add Timeofday generic scripts and a demo map

Those 4 script can be used as filter or triggerer based on current time. 
See test/tod for a demo map (conditionnal magic mouth, weapons that
attack only at day/night, grates that open in morning and close at dusk)


git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@7509 282e977c-c81d-0410-88c4-b93c2d0d6712
master
tchize 2007-11-16 13:27:03 +00:00
parent da810f1b29
commit 91a9bf913d
5 changed files with 2492 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# moment_only.py
#
# Copyright 2007 by David Delbecq
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
#
# This script make the event it is attached to (not global!)
# works only in specific moment of year/day
# exemple, to make an "apply" work only on
# Morning of each Day of the moon occuring during The Season of the Blizzard:
#
# arch event_apply
# title Python
# slaying /python/tod/filter_all_periods.py
# name the Day of the Moon,The Season of the Blizzard,Morning
# end
import Crossfire
import string
now = Crossfire.GetTime()
parameters = string.split(Crossfire.ScriptParameters(),",")
current = [Crossfire.GetMonthName(now[1]),Crossfire.GetWeekdayName(now[5]),Crossfire.GetSeasonName(now[7]),Crossfire.GetPeriodofdayName(now[8])]
#Crossfire.Log(Crossfire.LogDebug , "Seasons to check for are %s" %parameters)
#Crossfire.Log(Crossfire.LogDebug , "now is %s" %current)
#default: allow operation (0)
Crossfire.SetReturnValue()
if (set(parameters) - set(current)):
#some parameters had no match on 'now' -> refuse operation
Crossfire.SetReturnValue(1)

View File

@ -0,0 +1,45 @@
# moment_only.py
#
# Copyright 2007 by David Delbecq
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
#
# This script make the event it is attached to (not global!)
# works only in specific moment of year/day. Periods are separated
# by comas. See wiki doc list of possible values
# exemple, to make an "apply" work only during Blizzard, new year and every morning:
#
# arch event_apply
# title Python
# slaying /python/tod/filter_one_period.py
# name The Season of New Year,The Season of the Blizzard,Morning
# end
import Crossfire
import string
now = Crossfire.GetTime()
parameters = string.split(Crossfire.ScriptParameters(),",")
current = [Crossfire.GetMonthName(now[1]),Crossfire.GetWeekdayName(now[5]),Crossfire.GetSeasonName(now[7]),Crossfire.GetPeriodofdayName(now[8])]
#Crossfire.Log(Crossfire.LogDebug , "Seasons to check for are %s" %parameters)
#Crossfire.Log(Crossfire.LogDebug , "now is %s" %current)
#default: cancel operation (<>0). If non empty intersection, we have a match, set to continur operation (0)
Crossfire.SetReturnValue(1)
if (set(parameters) & set(current)):
Crossfire.SetReturnValue(0)

View File

@ -0,0 +1,79 @@
# push_all_periods.py
#
# Copyright 2007 by David Delbecq
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
#
# This script make the event it is attached to (not global!)
# trigger a connected value at specific moment of year/day.
# It will behave as if a button was "pushed" when entering period
# and "released" after the period. Typical use is to use it as
# event_time on a living object (that objects that triggers
# time events).
# This script ensure button remains pushed for all period, and
# get release after period. This works even is map is loaded
# in middle of period or map gets released from memory and put in
# cache. In those case, event will just ensure that "current" state
# correspond to expected state and correct status if needed.
# Note: the event must be inside an object
# which can find a path, using inventory, to a toplavel
# object that is on a Map.
#
# exemple, to make an "push" active only Mornings of The Season of New Year:
#
# arch event_time
# title Python
# slaying /python/tod/push_all_periods.py
# name 69,Morning,The Season of New Year
# end
# parameters are separated by comas. First one
# is connected value to trigger, other ones are
# one or more periods where state must become "pushed"
import Crossfire
import string
event = Crossfire.WhatIsEvent()
alreadymatched = (event.Value!=0)
parameters = string.split(Crossfire.ScriptParameters(),",")
connected = int(parameters.pop(0))
now = Crossfire.GetTime()
current = [Crossfire.GetMonthName(now[1]),Crossfire.GetWeekdayName(now[5]),Crossfire.GetSeasonName(now[7]),Crossfire.GetPeriodofdayName(now[8])]
if (set(parameters) - set(current)):
match = False
else:
match=True
#pushdown if needed
if (match & (not alreadymatched)):
op = event
while (op.Env):
op=op.Env
map = op.Map
map.TriggerConnected(connected,1,Crossfire.WhoAmI())
event.Value=1
#release if needed
if ( (not match) & alreadymatched):
op = event
while (op.Env):
op=op.Env
map = op.Map
map.TriggerConnected(connected,0,Crossfire.WhoAmI())
event.Value=0
#Crossfire.Log(Crossfire.LogDebug , "Seasons to check for are %s" %parameters)
#Crossfire.Log(Crossfire.LogDebug , "Current seasons are %s" %current)
#Crossfire.Log(Crossfire.LogDebug , "Current match status is %d but will be %d" %(alreadymatched,match))
#Crossfire.Log(Crossfire.LogDebug , "Connecte to trigger is %i" %connected)

View File

@ -0,0 +1,78 @@
# push_one_period.py
#
# Copyright 2007 by David Delbecq
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
#
# This script make the event it is attached to (not global!)
# trigger a connected value at specific moment of year/day.
# It will behave as if a button was "pushed" when entering period
# and "release" after the period. Typical use is to use it as
# event_time on a living object (that objects that triggers
# time events).
# This script ensure button remains pushed for all period, and
# get release after period. This works even is map is loaded
# in middle of period or map gets released from memory and put in
# cache. In those case, event will just ensure that "current" state
# correspond to expected state and correct status if needed.
# Note: the event must be inside an object
# which can find a path, using inventory, to a toplavel
# object that is on a Map.
#
# exemple, to make an "push" starting at Morning and ending after Noon:
#
# arch event_time
# title Python
# slaying /python/tod/push_one_period.py
# name 69,Morning,Noon
# end
# parameters are separated by comas. First one
# is connected value to trigger, other ones are
# one or more periods where state must become "pushed"
import Crossfire
import string
event = Crossfire.WhatIsEvent()
alreadymatched = (event.Value!=0)
parameters = string.split(Crossfire.ScriptParameters(),",")
connected = int(parameters.pop(0))
now = Crossfire.GetTime()
current = [Crossfire.GetMonthName(now[1]),Crossfire.GetWeekdayName(now[5]),Crossfire.GetSeasonName(now[7]),Crossfire.GetPeriodofdayName(now[8])]
if (set(parameters) & set(current)):
match = True
else:
match=False
#pushdown if need
if (match & (not alreadymatched)):
op = event
while (op.Env):
op=op.Env
map = op.Map
map.TriggerConnected(connected,1,Crossfire.WhoAmI())
event.Value=1
if ( (not match) & alreadymatched):
op = event
while (op.Env):
op=op.Env
map = op.Map
map.TriggerConnected(connected,0,Crossfire.WhoAmI())
event.Value=0
#Crossfire.Log(Crossfire.LogDebug , "Seasons to check for are %s" %parameters)
#Crossfire.Log(Crossfire.LogDebug , "Current seasons are %s" %current)
#Crossfire.Log(Crossfire.LogDebug , "Current match status is %d but will be %d" %(alreadymatched,match))
#Crossfire.Log(Crossfire.LogDebug , "Connecte to trigger is %i" %connected)

2244
test/tod 100644

File diff suppressed because it is too large Load Diff