new level loader is working!
[awish.git] / asm / items / items.awa
blobf07997f8a177e8652fa1348642cb923c80318b10
1 /*
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
14  */
15   ;defetvar: animated
16   ;defetvar: afirst_frame, alast_frame, aframe
18   ;defetvar: spr_bank, spr_num, spr_dir
20   ;defetvar: pos_x, pos_y
21   ;defetvar: pos_tx, pos_ty
23   ;deftvar: activated
25   deftvar: apause
26   deftvar: liftdown
28 const: ITEM_ANIM_DELAY = 5
31 ; in:
32 ;  item_type
33 ; out:
34 ;  0 or item_thread_id
36 proc: item_at_me_typed
37 arg: .item_type
38 locals: .cnt, .t
39   set [.cnt], 1
40 .loop:
41   ; no self-detection
42   psh [.cnt]
43   tid
44   jeq .next
45   ; only running threads
46   sta [.cnt]
47   jne .next, THREAD_STATE_RUNNING
48   ; only wanted type
49   get [.cnt], item_id, [.t]
50   jne .next, [.t], [.item_type]
51   ; only not activated
52   get [.cnt], activated
53   jne .next, 0
54   ; only standing on tile
55   get [.cnt], pos_tx
56   jne .next, 0
57   get [.cnt], pos_ty
58   jne .next, 0
59   ; only our coords
60   get [.cnt], pos_x
61   jne .next, [pos_x]
62   get [.cnt], pos_y
63   jne .next, [pos_y]
64   ; found
65   ret [.cnt]
66 .next:
67   add [.cnt], 1
68   rst FRST_GET_MAX_THREAD_ID
69   jle .loop, [.cnt], [rst_result]
70   ; not found
71   ret 0
72 endp: item_at_me_typed
75 proc: item_check_fall
76   jlt .raising, [pos_ty], 0
77   jne .liftdown1, [liftdown], 0
78   jeq .liftdown, [pos_ty], 1
79   jgt .falling, [pos_ty], 0  ; already falling
80   ;set [fall_count], 0
81   mgf [pos_x], [pos_y]
82   jne .quit, FTILE_EMPTY
83   set [pos_ty], 1
84   set [falling], 1
85   jmp .falling
86 .quit:
87   ret
88 .falling:
89   bsr item_do_fall_step
90   ret
91 .raising:
92   set [liftdown], 0
93   jeq .raise_one, [pos_ty], -1
94   sub [pos_ty], 2
95   jne .quit, [pos_ty], -10
96   set [pos_ty], 0
97   sub [pos_y], 1
98   ret
99 .raise_one:
100   set [pos_ty], -2
101   ret
102 .liftdown:
103   set [liftdown], 1
104   set [pos_ty], 2
105   ret
106 .liftdown1:
107   jeq .one_wait, [pos_ty], 0
108   add [pos_ty], 2
109   jne .quit, [pos_ty], 10
110   sub [liftdown], 1
111   set [pos_ty], 0
112   add [pos_y], 1
113   ret
114 .one_wait:
115   sub [liftdown], 1
116   ret
117 endp: item_check_fall
120 proc: item_do_fall_step
121 local: .sy
122   add [fall_count], 1
123   add [pos_ty], 3
124   jlt .quit, [pos_ty], 9
125   ; full tile
126   set [pos_ty], 0
127   add [pos_y], 1
128   set [falling], -1  ; falling done (can be changed later)
129   ; out of map?
130   set [.sy], [map_height]
131   add [.sy], 1
132   jge item_fall_dead, [pos_y], [.sy]
133   mgf [pos_x], [pos_y]
134   jne .quit, FTILE_EMPTY
135   set [pos_ty], 2
136 .quit:
137   ret
138 endp: item_do_fall_step
141 item_fall_dead:
142   set [item_id], -1
143   set [falling], 0
144   end
147 include: i_key.awa
148 include: i_drill.awa
149 include: i_gloves.awa
150 include: i_umbrella.awa
151 include: i_apple.awa
152 include: i_fan.awa
153 include: i_dynamite.awa
154 include: i_vial.awa
155 include: i_rocket.awa
156 include: i_harry.awa
159 item_entry_array:
160   db: ITEM_KEY
161   dw: entry_item_key
162   ;
163   db: ITEM_FAN
164   dw: entry_item_fan
165   ;
166   db: ITEM_DYNAMITE
167   dw: entry_item_dynamite
168   ;
169   db: ITEM_DRILL
170   dw: entry_item_drill
171   ;
172   db: ITEM_UMBRELLA
173   dw: entry_item_umbrella
174   ;
175   db: ITEM_HARRY
176   dw: entry_item_monster
177   ;
178   db: ITEM_ROCKET
179   dw: entry_item_rocket
180   ;
181   db: ITEM_APPLE
182   dw: entry_item_apple
183   ;
184   db: ITEM_VIAL
185   dw: entry_item_vial
186   ;
187   db: ITEM_GLOVES
188   dw: entry_item_gloves
189   ;
190   db: 255
193 entry_item:
194   set [activated], 0
195   set [fall_count], 0
196   set [falling], 0
197   set [frozen], 0
198   set [apause], ITEM_ANIM_DELAY
199   set [pos_tx], 0
200   set [pos_ty], 0
201   set [liftdown], 0
202   jlt item_fall_dead, [item_id], 0
203   jeq item_fall_dead, [item_id], 255
204   ;
205   psh item_entry_array
206 .loop:
207   dup
208   rxc
209   dup
210   jeq .done, 255
211   jeq .found, [item_id]
212   add 3
213   jmp .loop
214 .done:
215   drp 2
216   jmp item_fall_dead
217 .found:
218   add 1
219   dup
220   rxc
221   swp
222   add 1
223   rxc
224   mul 256
225   add
226   bsr
227   ;
228   end
231 proc: set_item_name_vars
232 arg: .item_id
233 locals: .addr, .type
234   set [.addr], item_names
235 .loop:
236   rxc [.addr], [.type]
237   add [.addr], 1
238   jeq .not_found, [.type], 255
239   jne .bad_type, [.type], [.item_id]
240   ; found
241   set [item_name_ofs], [.addr]
242   set [item_name_len], -1  ; asciiz
243   ret
244 .bad_type:
245   rxc [.addr], [.type]
246   add [.addr], 1
247   jeq .loop, [.type], 0
248   jmp .bad_type
249 .not_found:
250   set [item_name_ofs], 0
251   set [item_name_len], 0
252   ret
253 endp: set_item_name_vars
255 item_names:
256   db: ITEM_KEY
257   dz: "key"
258   ;
259   db: ITEM_FAN
260   dz: "fan"
261   ;
262   db: ITEM_DYNAMITE
263   dz: "bomb"
264   ;
265   db: ITEM_DRILL
266   dz: "drill"
267   ;
268   db: ITEM_UMBRELLA
269   dz: "umbrella"
270   ;
271   db: ITEM_HARRY
272   dz: "harry"
273   ;
274   db: ITEM_ROCKET
275   dz: "rocket"
276   ;
277   db: ITEM_APPLE
278   dz: "apple"
279   ;
280   db: ITEM_VIAL
281   dz: "vial"
282   ;
283   db: ITEM_GLOVES
284   dz: "gloves"
285   ;
286   db: 255