Works again.
[uxul-world.git] / add-object.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 (in-package :uxul-world)
4
5 (defun i-wanna-listen-to (object room &rest args)
6   "Brings all the Objects of the given classes in <args> into the
7 listen-to-array of object. Any previous value will be deleted."
8   (dolist (arg args)
9     (setf (listen-to object)
10           (concatenate 'list
11                        (listen-to object)
12                        (get-objects room arg)))))
13
14 (defun must-be-listened-by (object room &rest args)
15   "Adds itself to the listen-to-array of all the objects of the given
16 classes in <args>"
17   (dolist (arg args)
18     (dolist (obj (get-objects room arg))
19       (push object (listen-to obj)))))
20
21 (defgeneric add-object (obj place)
22   (:documentation "Add an object to a place, i.e. a room or sth."))
23
24 (defmethod add-object ((obj t) (place t))
25   "Just Warn - this shouldnt happen!"
26   (format t
27           "add-object was called with arguments it wasnt defined
28 for. Classes: ~A ~A"
29           (class-name (class-of obj))
30           (class-name (class-of obj))))
31
32 (defmethod add-object ((object t) (room room))
33   (add-object-of-class object (object-array room)))
34
35 (defmethod add-object ((obj stone) (place room))
36   "Add a stone to a room and all the objects it can collide with"
37   (must-be-listened-by obj place 'player 'moving-enemy 'moving-item)
38   (call-next-method))
39
40 (defmethod add-object ((obj teleporter) (place room))
41   (must-be-listened-by obj place 'player)
42   (call-next-method))
43
44 (defmethod add-object ((obj moving-enemy) (place room))
45   (i-wanna-listen-to obj place 'player 'stone)
46   (must-be-listened-by obj place 'player)
47   (call-next-method))
48
49 (defmethod add-object ((obj standing-enemy) (place room))
50   (must-be-listened-by obj place 'player)
51   (call-next-method))
52
53 (defmethod add-object ((obj moving-item) (place room))
54   (must-be-listened-by obj place 'player)
55   (i-wanna-listen-to obj place 'player 'stone)
56   (call-next-method))
57
58 (defmethod add-object ((obj standing-item) (place room))
59   (must-be-listened-by obj place 'player)
60   (call-next-method))
61
62 (defmethod add-object ((obj player) (place room))
63   (setf (key-listener place) obj)
64   (setf (graphic-centralizer place) obj)
65   (must-be-listened-by obj place 'moving-enemy 'moving-item)
66   (i-wanna-listen-to obj place 'moving-enemy 'moving-item 'standing-enemy
67                      'standing-item 'stone 'bottom)
68   (call-next-method))