Roaches on foot.
[koperkapel.git] / koperkapel / vehicles / base.py
1 """ Base class for vehicles.  """
2
3
4 class Vehicle:
5     """ Vehicle base class.
6
7     A vehicle should have the following attributes:
8
9     * seats -- list of roach seats.
10     * background -- actor representing background for management scene
11     """
12
13     vehicle_types = {}
14     approximate_radius = 200
15
16     @classmethod
17     def by_type(cls, vehicle_type):
18         return cls.vehicle_types.get(vehicle_type)()
19
20     @classmethod
21     def register(cls, vehicle_cls):
22         cls.vehicle_types[vehicle_cls.__name__.lower()] = vehicle_cls
23
24     @classmethod
25     def register_all(cls):
26         from .walking import Walking
27         cls.register(Walking)
28
29
30 class Seat:
31     """ A space in a vehicle for a roach.
32
33     * pos -- (x, y) position of the seat relative to the centre of the vehicle.
34       x and y may be numbers from approximately -1.0 to 1.0. They will be
35       multiplied by the approximate_radius of the vehicle.
36     * allowed -- f(roach) for checking whether a roach may occupy the
37       seat
38     """
39
40     def __init__(self, pos, allowed=None):
41         self.pos = pos
42         self.allowed = allowed or (lambda roach: True)
43
44
45 Vehicle.register_all()