File: Weather.py

package info (click to toggle)
cyphesis-cpp 0.5.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,084 kB
  • ctags: 3,627
  • sloc: cpp: 30,418; python: 4,812; xml: 4,674; sh: 4,118; makefile: 902; ansic: 617
file content (28 lines) | stat: -rw-r--r-- 952 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#This file is distributed under the terms of the GNU General Public license.
#Copyright (C) 1999 Al Riddoch (See the file COPYING for details).

from atlas import *
from cyphesis.Thing import Thing
from common import log,const
try:
  from random import *
except ImportError:
  from whrandom import *

class Weather(Thing):
    def setup_operation(self, op):
        return Operation("tick",to=self)
    def tick_operation(self, op):
        res = Message()
        optick = Operation("tick", to=self)
        res = res + optick
        if self.rain<0.1:
            optick.setFutureSeconds(randint(60,300))
            self.rain=uniform(0.1, 0.9)
            self.visibility=10/(self.rain * self.rain)
        else:
            optick.setFutureSeconds(randint(600,2400))
            self.rain=0.0
            self.visibility=1000
        res = res+Operation("set", Entity(self.id,rain=self.rain,visibility=self.visibility), to=self)
        return res