-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-event-types.lisp
303 lines (257 loc) · 34.1 KB
/
init-event-types.lisp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
(in-package :trader-rl)
;;=========================================
;;
;; EVENT TYPES
;;
;;=========================================
(set-event-type-by-id +event-type-famine+ (make-instance 'event-type :descr "Famine is raging in this settlement!" :max-stage 7
:on-show #'(lambda (event settlement)
(declare (ignore settlement))
(let ((str (create-string "")))
(if (< (stage event) 15)
(format str "~A~%" (descr event))
(format str "This settlement has recently suffered from famine.~%"))
str)
)
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-high+
:string (format nil "The ~(~A~) of ~A was struck by famine!"
(get-settlement-size-name settlement)
(name settlement))))
;; add a quest to the realm ruler to deliver food to this settlement
(let ((quest))
(setf quest (make-instance 'quest-delivery
:quest-type-id +quest-type-delivery+
:giver-id (id (get-settlement-realm settlement))
:item-type-id +item-type-food+
:qty 300
:reward 1500
:move-to-market t
:dst-id (id settlement)
:event-id (id event)
:date (wtime *world*)))
(setf (quests (get-settlement-realm settlement))
(add-to-quests (quests (get-settlement-realm settlement)) quest))
)
)
(incf (stage event))
(when (<= (stage event) (- (max-stage event) 3))
(remove-from-inv +item-type-food+ (market settlement) 50)
(set-settlement-cur-demand settlement +item-type-food+ 15)
(set-settlement-cur-supply settlement +item-type-food+ 14))
(when (> (stage event) (- (max-stage event) 3))
(set-settlement-cur-demand settlement +item-type-food+ 5)
(set-settlement-cur-supply settlement +item-type-food+ 4))
;; by default lambda does not seem to create a block, thus you need this to return from it
(block nil
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event))
(return))
(when (> (get-item-inv +item-type-food+ (market settlement)) 300)
(remove-event-settlement settlement (event-type-id event))
(set-settlement-cur-demand settlement +item-type-food+ 5)
(set-settlement-cur-supply settlement +item-type-food+ 4)
(return)))
)
:on-rotate #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (<= (get-item-inv +item-type-food+ (market settlement)) 20)
t
nil))))
(set-event-type-by-id +event-type-harvest+ (make-instance 'event-type :descr "This settlement was blessed with plentiful harvest!" :max-stage 5
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "The ~(~A~) of ~A was blessed with plentiful harvest."
(get-settlement-size-name settlement)
(name settlement)))))
(incf (stage event))
(produce-settlement-item +item-type-food+ settlement 50)
(produce-settlement-item +item-type-wood+ settlement 10)
(set-settlement-cur-demand settlement +item-type-food+ -8)
(set-settlement-cur-supply settlement +item-type-food+ -9)
(set-settlement-cur-demand settlement +item-type-wood+ -5)
(set-settlement-cur-supply settlement +item-type-wood+ -6)
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (get-settlement-feature settlement +feature-type-farm+)
t
nil
)
)))
(set-event-type-by-id +event-type-ore-deposit+ (make-instance 'event-type :descr "The miners have found a rich ore vein!" :max-stage 5
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "The miners of the ~(~A~) of ~A found a rich ore vein."
(get-settlement-size-name settlement)
(name settlement)))))
(incf (stage event))
(produce-settlement-item +item-type-ore+ settlement 50)
(set-settlement-cur-demand settlement +item-type-ore+ -6)
(set-settlement-cur-supply settlement +item-type-ore+ -7)
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (get-settlement-feature settlement +feature-type-mine+)
t
nil
)
)))
(set-event-type-by-id +event-type-gem-deposit+ (make-instance 'event-type :descr "The miners have found a gem deposit!" :max-stage 5
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "The miners of the ~(~A~) of ~A found a gem deposit."
(get-settlement-size-name settlement)
(name settlement)))))
(incf (stage event))
(produce-settlement-item +item-type-gems+ settlement 20)
(set-settlement-cur-demand settlement +item-type-gems+ -5)
(set-settlement-cur-supply settlement +item-type-gems+ -6)
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (get-settlement-feature settlement +feature-type-mine+)
t
nil
)
)))
(set-event-type-by-id +event-type-fire+ (make-instance 'event-type :descr "Fire is raging through the settlement!" :max-stage 1
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-high+
:string (format nil "Fire raged through the ~(~A~) of ~A."
(get-settlement-size-name settlement)
(name settlement))))
;; destroy all warehouses
(remove-settlement-feature settlement +feature-type-small-warehouse+)
(remove-settlement-feature settlement +feature-type-med-warehouse+)
(remove-settlement-feature settlement +feature-type-large-warehouse+)
;; destroy goods which quantity exceeds the new maximum settlement capacity
(loop
for item-type-id being the hash-key in (market settlement) using (hash-value item-qty)
do
(when (> item-qty (get-settlement-max-capacity settlement))
(remove-from-inv item-type-id (market settlement) (- item-qty (get-settlement-max-capacity settlement)))
)
)
)
(incf (stage event))
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (or (get-settlement-feature settlement +feature-type-small-warehouse+)
(get-settlement-feature settlement +feature-type-med-warehouse+)
(get-settlement-feature settlement +feature-type-large-warehouse+))
t
nil
)
)))
(set-event-type-by-id +event-type-build-warehouse-1+ (make-instance 'event-type :descr "The settlement mayor decided to build a small warehouse." :max-stage 1
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "People of ~A built a small warehouse."
(name settlement))))
;; build a small warehouses
(set-settlement-feature settlement +feature-type-small-warehouse+)
)
(incf (stage event))
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (or (get-settlement-feature settlement +feature-type-small-warehouse+)
(get-settlement-feature settlement +feature-type-med-warehouse+)
(get-settlement-feature settlement +feature-type-large-warehouse+))
nil
t
)
)))
(set-event-type-by-id +event-type-build-warehouse-2+ (make-instance 'event-type :descr "The settlement mayor decided to build a medium warehouse." :max-stage 1
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "People of ~A built a medium warehouse."
(name settlement))))
;; build a medium warehouses
(remove-settlement-feature settlement +feature-type-small-warehouse+)
(set-settlement-feature settlement +feature-type-med-warehouse+)
)
(incf (stage event))
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (get-settlement-feature settlement +feature-type-small-warehouse+)
t
nil
)
)))
(set-event-type-by-id +event-type-build-warehouse-3+ (make-instance 'event-type :descr "The settlement mayor decided to build a large warehouse." :max-stage 1
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "People of ~A built a large warehouse."
(name settlement))))
;; build a large warehouses
(remove-settlement-feature settlement +feature-type-med-warehouse+)
(set-settlement-feature settlement +feature-type-large-warehouse+)
)
(incf (stage event))
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
:on-rand #'(lambda (event-type settlement)
(declare (ignore event-type))
(if (get-settlement-feature settlement +feature-type-med-warehouse+)
t
nil
)
)))
(set-event-type-by-id +event-type-rot+ (make-instance 'event-type :descr "Mushrooms in storage are suffering from a strange rot. People are troubled." :max-stage 5
:on-tick #'(lambda (event settlement)
(format t "ON-TICK ~A ~A~%" (name settlement) (descr event))
(when (zerop (stage event))
(setf (journal settlement)
(add-to-journal (journal settlement) :date (wtime *world*) :importance +journal-importance-low+
:string (format nil "Mushroom storage of ~A suffered from a strange rot."
(name settlement))))
;; build a large warehouses
)
(incf (stage event))
(remove-from-inv +item-type-food+ (market settlement) 40)
(remove-from-inv +item-type-wood+ (market settlement) 20)
(when (> (stage event) (max-stage event))
(remove-event-settlement settlement (event-type-id event)))
)
))