f70eeb6e891ad33d5b927b14c3593a86af2c4cd6
[ztornado.git] / weather.inf
1 ! Z-Tornado - Two player weather action game
2 !
3 ! Tornado is copyright (C) 2000-2002  Oliver Feiler
4 ! http://www.lionking.org/~kiza/linux/tornado
5 ! Inform version copyright (c) 2003  Sophie Frühling (sfruehling@aon.at)
6
7 ! This program is free software; you can redistribute it and/or modify
8 ! it under the terms of the GNU General Public License as published by
9 ! the Free Software Foundation; either version 2 of the License, or
10 ! (at your option) any later version.
11 !
12 ! This program is distributed in the hope that it will be useful,
13 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ! GNU General Public License for more details.
16 !
17 ! You should have received a copy of the GNU General Public License
18 ! along with this program; if not, write to the Free Software
19 ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ! Next Generation Weather Function
22 ! rain (strength 1) and hail (strength 2)
23 Array weather_array -> 13;
24 [ DrawWeather x shift ch strength  tmp i num_moved num_destroyed xx starty yy;
25   num_destroyed = 0;
26   yy = 5; xx = x;
27   starty = 5;
28   ! Init weather_array
29   for (i = 0: i < 13: i++) {
30     if (i%3 == 0)
31       weather_array->i = ch;
32     else
33       weather_array->i = ' ';
34   }
35   num_moved = 1;
36   while (num_moved > 0) {
37     num_moved = 0;
38     ! move each character
39     for (i = 0: i < 13: i++) {
40       ! bottom, left, or right border
41       if ((yy >= house1_y + 10) || (xx >= screen_width) || (xx <= 1))
42         weather_array->i = strength;
43       ! skip if this object has disappeared (weather_array->i >= strength)
44       if ((weather_array->i ~= ' ' or ch) && weather_array->i >= strength) {
45         xx++; continue;
46       }
47       num_moved++;
48       ! did we hit something?
49       ! no hit (there is a space character at xx yy)
50       if (CountDestroyed(' ', xx, yy, 1, 1) == 1) {
51         if (weather_array->i == ' ' or ch) {
52           @set_cursor yy xx;
53           print (char) weather_array->i;
54         }
55       }
56       ! we have hit something
57       else {
58         if (weather_array->i == ' ' or ch)
59           weather_array->i = 1;
60         else
61            (weather_array->i)++;
62         ! if ch == hail and we've hit snow, don't delete
63         if ((ch == ':') && (CountDestroyed('*', xx, yy, 1, 1) == 1))
64           ! "expire" the object
65           weather_array->i = strength;
66         else {
67           ! draw the object
68           @set_cursor yy xx;
69           print (char) ch;
70           ChangeSnowWorld(' ', xx, yy);
71           num_destroyed++;
72         }
73       }
74       xx++;
75     }
76     yy++;
77     xx = x + shift*(yy - 5);
78     @set_cursor screen_height 1;
79     Pause(2);
80   }
81   @set_cursor screen_height 1;
82   Pause(10);
83   ! delete the rain/hail/whatever (whatever ?)
84   xx = x;
85   num_moved = 1;
86   while (num_moved > 0) {
87     num_moved = 0;
88     for (i = 0: i < 13: i++) {
89       if (starty >= yy || starty >= house1_y + 10)
90         break;
91       if (xx + 13 < 1 || xx > screen_width)
92         continue;
93       tmp = GetLoc(xx, starty);
94       if (tmp < fields && snow_world->tmp == ' ') {
95         @set_cursor starty xx;
96         print (char) ' ';
97       }
98       xx++;
99       num_moved++;
100     }
101     starty++;
102     xx = x + shift*(starty - 5);
103     @set_cursor screen_height 1;
104     Pause(1);
105   }
106   return num_destroyed;
107 ];
108
109 ! Kianga's Next Generation Snow Machine
110 ! Includes Special SnowLogic(tm)
111 Array snow_x -> 13;
112 Array snow_y -> 13;
113 Array snow_startx -> 13;
114 Array snow_starty -> 13;
115 [ DrawSnow x shift  xx yy i num_moved tmp;
116   yy = 5; xx = x;
117   ! Put snow in array
118   for (i = 0: i < 13: i++) {
119     if (i%3 == 0)
120       weather_array->i = '*';
121     else 
122       weather_array->i = ' ';
123     snow_x->i = x + i;
124     snow_startx->i = x + i;
125     snow_y->i = yy;
126     snow_starty->i = yy;
127   }
128   num_moved = 1;
129   while (num_moved > 0) {
130     num_moved = 0;
131     ! move each character
132     for (i = 0: i < 13: i++) {
133       ! bottom, left, or right border
134       if ((snow_y->i >= house1_y + 10)
135       || (snow_x->i >= screen_width) || (snow_x->i <= 1))
136         weather_array->i = 1;
137       ! skip if this object has disappeared (weather_array->i >= strength)
138       if ((weather_array->i ~= ' ' or '*') && weather_array->i >= 1)
139         continue;
140       num_moved++;
141       ! did we hit something?
142       ! no hit
143       if (CountDestroyed(' ', snow_x->i, snow_y->i, 1, 1) == 1) {
144         if (weather_array->i == ' ' or '*') {
145           xx = snow_x->i;
146           yy = snow_y->i;
147           @set_cursor yy xx;
148           print (char) weather_array->i;
149         }
150       }
151       ! we've hit something
152       else {
153         weather_array->i = 1;
154         if (snow_y->i > 5) {
155           xx = snow_x->i - shift;
156           yy = snow_y->i - 1;
157           @set_cursor yy xx;
158           print (char) '*';
159           ChangeSnowWorld('*', xx, yy);
160         }
161       }
162       ! bottom
163       if (snow_y->i == screen_height - 1) {
164         weather_array->i = 1;
165         xx = snow_x->i;
166         yy = snow_y->i;
167         if (CountDestroyed(' ', xx, yy, 1, 1) == 1) {
168           @set_cursor yy xx;
169           print (char) '*';
170           ChangeSnowWorld('*', xx, yy);
171         }
172       }         
173       ! move the object
174       (snow_y->i)++;
175       snow_x->i = snow_x->i + shift;
176     }
177     @set_cursor screen_height 1;
178     Pause(2);
179   }
180   @set_cursor screen_height 1;
181   Pause(10);
182   ! delete the snow
183   num_moved = 1;
184   while (num_moved > 0) {
185     num_moved = 0;
186     for (i = 0: i < 13: i++) {
187       if (snow_starty->i >= snow_y->i)
188         continue;
189       xx = snow_startx->i;
190       yy = snow_starty->i;
191       tmp = GetLoc(xx, yy);
192       if ((tmp < fields) && (snow_world->tmp == ' ')) {
193         @set_cursor yy xx;
194         print (char) ' ';
195       }
196       num_moved++;
197       (snow_starty->i)++;
198       snow_startx->i = snow_startx->i + shift;
199     }
200     @set_cursor screen_height 1;
201     Pause(1);
202   }
203 ];
204
205 ! Probably the ugliest function in the whole program.
206 [ DrawLightning x  xx y num_destroyed;
207   ! Is needed if screen_width is smaller than 80, maybe due to some
208   ! bug somewhere else
209   DrawStatusLine();
210   xx = x + 6; y = 5;
211   if (player1)
212     num_destroyed = CountDestroyed(' ', house2_x, house2_y, 17, 10);
213   else
214     num_destroyed = CountDestroyed(' ', house1_x, house1_y, 17, 10);
215   ! draw it...
216   @set_cursor  5 xx; print "||";
217   ChangeWorld(xx, 5, 2);
218   @set_cursor  6 xx; print "//";
219   ChangeWorld(xx, 6, 2); xx--;
220   @set_cursor  7 xx; print "//@@92@@92";
221   ChangeWorld(xx, 7, 4); xx--;
222   @set_cursor  8 xx; print "//";
223   ChangeWorld(xx, 8, 2); xx = x + 7;
224   @set_cursor  8 xx; print "@@92@@92";
225   ChangeWorld(xx, 8, 2); xx = x + 3;
226   @set_cursor  9 xx; print "||";
227   ChangeWorld(xx, 9, 2); xx = x + 8;
228   @set_cursor  9 xx; print "@@92@@92";
229   ChangeWorld(xx, 9, 2); xx++;
230   @set_cursor 10 xx; print "@@92@@92";
231   ChangeWorld(xx, 10, 2); xx--;
232   @set_cursor 11 xx; print "//@@92@@92";
233   ChangeWorld(xx, 11, 4); xx--;
234   @set_cursor 12 xx; print "//";
235   ChangeWorld(xx, 12, 2); xx = x + 11;
236   @set_cursor 12 xx; print "@@92@@92";
237   ChangeWorld(xx, 12, 2); xx = x + 7;
238   @set_cursor 13 xx; print "||";
239   ChangeWorld(xx, 13, 2); xx--;
240   @set_cursor screen_height 1;
241   Pause(2);
242   @set_cursor 14 xx; print "//@@92@@92";
243   ChangeWorld(xx, 14, 4); xx--;
244   @set_cursor 15 xx; print "//";
245   ChangeWorld(xx, 15, 2); xx = x + 9;
246   @set_cursor 15 xx; print "@@92@@92";
247   ChangeWorld(xx, 15, 2); xx = x + 4;
248   @set_cursor 16 xx; print "//";
249   ChangeWorld(xx, 16, 2); xx = x + 10;
250   @set_cursor 16 xx; print "@@92@@92";
251   ChangeWorld(xx, 16, 2);
252   @set_cursor 17 xx; print "||";
253   ChangeWorld(xx, 17, 2); xx--;
254   @set_cursor 18 xx; print "//@@92@@92";
255   ChangeWorld(xx, 18, 4); xx--;
256   @set_cursor 19 xx; print "//";
257   ChangeWorld(xx, 19, 2); xx = x + 12;
258   @set_cursor 19 xx; print "@@92@@92";
259   ChangeWorld(xx, 19, 2); xx = x + 7;
260   @set_cursor 20 xx; print "//";
261   ChangeWorld(xx, 20, 2);
262   @set_cursor 21 xx; print "@@92@@92";
263   ChangeWorld(xx, 21, 2); xx++;
264   @set_cursor 22 xx; print "@@92@@92";
265   ChangeWorld(xx, 22, 2); xx++;
266   @set_cursor 23 xx; print "@@92@@92";
267   ChangeWorld(xx, 23, 2);
268   @set_cursor screen_height 1;
269   Pause(10);
270   ! ...and delete it again
271   xx = x + 6;
272   @set_cursor  5 xx; print "  ";
273   @set_cursor  6 xx; print "  ";   xx--;
274   @set_cursor  7 xx; print "    "; xx--;
275   @set_cursor  8 xx; print "  ";   xx = x + 7;
276   @set_cursor  8 xx; print "  ";   xx = x + 3;
277   @set_cursor  9 xx; print "  ";   xx = x + 8;
278   @set_cursor  9 xx; print "  ";   xx++;
279   @set_cursor 10 xx; print "  ";   xx--;
280   @set_cursor 11 xx; print "    "; xx--;
281   @set_cursor 12 xx; print "  ";   xx = x + 11;
282   @set_cursor 12 xx; print "  ";   xx = x + 7;
283   @set_cursor 13 xx; print "  ";   xx--;
284   @set_cursor 14 xx; print "    "; xx--;
285   @set_cursor 15 xx; print "  ";   xx = x + 9;
286   @set_cursor 15 xx; print "  ";   xx = x + 4;
287   @set_cursor 16 xx; print "  ";   xx = x + 10;
288   @set_cursor 16 xx; print "  ";
289   @set_cursor 17 xx; print "  ";   xx--;
290   @set_cursor 18 xx; print "    ";   xx--;
291   @set_cursor 19 xx; print "  ";   xx = x + 12;
292   @set_cursor 19 xx; print "  ";   xx = x + 7;
293   @set_cursor 20 xx; print "  ";
294   @set_cursor 21 xx; print "  ";   xx++;
295   @set_cursor 22 xx; print "  ";   xx++;
296   @set_cursor 23 xx; print "  ";
297   @set_cursor screen_height 1;
298   if (player1)
299     return CountDestroyed(' ', house2_x, house2_y, 17, 10) - num_destroyed;
300   return CountDestroyed(' ', house1_x, house1_y, 17, 10) - num_destroyed;
301 ];
302
303 [ DrawTornado x shift  xx y shift_right tmp_x tmp_y width width_tmp
304   num_destroyed;
305   xx = 0; y = 4;
306   shift_right = 0;
307   tmp_x = x; tmp_y = y;
308   width = 29;
309   if (player1)
310     num_destroyed = CountDestroyed(' ', house2_x, house2_y, 17, 10);
311   else
312     num_destroyed = CountDestroyed(' ', house1_x, house1_y, 17, 10);
313   while (tmp_y < 24) {
314     if (width > 3) {
315       width = width - 2;
316       shift_right++;
317     }
318     if (tmp_y == 18) width = 2;
319     if (tmp_y == 21) width = 1;
320     if (tmp_y == 23) {
321       width = 7;
322       shift_right = shift_right - 3;
323     }
324     xx = tmp_x + shift_right;
325     ChangeWorld(xx, tmp_y, width);
326     for (width_tmp = 0: width_tmp < width: width_tmp++) {
327       xx = tmp_x + shift_right + width_tmp;
328       if (xx > 0 && xx <= screen_width) {
329         @set_cursor tmp_y xx; print "#";
330       }
331     }
332     tmp_y++;
333     tmp_x = tmp_x + shift;
334     if (xx > 0 && xx <= screen_width) {
335       @set_cursor screen_height 1;
336       Pause(2);
337     }
338   }
339   @set_cursor screen_height 1;
340   Pause(10);
341   tmp_x = x; tmp_y = y;
342   shift_right = 0;
343   width = 29;
344   while (tmp_y < 24) {
345     if (width > 3) {
346       width = width - 2;
347       shift_right++;
348     }
349     if (tmp_y == 18) width = 2;
350     if (tmp_y == 21) width = 1;
351     if (tmp_y == 23) {
352       width = 7;
353       shift_right = shift_right - 3;
354     }
355     for (width_tmp = 0: width_tmp < width: width_tmp++) {
356       xx = tmp_x + shift_right + width_tmp;
357       if (xx > 0 && xx <= screen_width) {
358         @set_cursor tmp_y xx;
359         print " ";
360       }
361     }
362     tmp_y++;
363     tmp_x = tmp_x + shift;
364     if (xx > 0 && xx <= screen_width)
365       @set_cursor screen_height 1;
366       Pause(1);
367   }
368   if (player1)
369     return CountDestroyed(' ', house2_x, house2_y, 17, 10) - num_destroyed;
370   return CountDestroyed(' ', house1_x, house1_y, 17, 10) - num_destroyed;
371 ];
372
373 ! This *does* look like a cloud in real life ;)
374 ! @{B0} is a degree character on decent interpreters
375 [ DrawCloud x;
376   if (x ~= 0) cloud_x = x;
377   else cloud_x = random(screen_width - 29);
378   @set_cursor 1 cloud_x; print ",/+++*++***+****++++++***+@@92,";
379   @set_cursor 2 cloud_x; print "(*+++*****+++++***+++****++)";
380   @set_cursor 3 cloud_x; print "`@@92++******+*++*++*****+++*/'";
381   @set_cursor 4 cloud_x; print " `@{B0}*,.,*@{B0}'`@{B0}*,.,",
382                                "*@{B0}`@{B0}*,.,*@{B0}'";
383   @set_cursor screen_height 1;
384 ];
385
386 ! Replace the normal cloud with a bigger one
387 [ DrawTornadoCloud  i;
388   for (i = 1: i <= screen_width: i++) {
389     @set_cursor 1 i; print (string) random("+", "*");
390     @set_cursor 2 i; print (string) random("+", "*");
391     @set_cursor 3 i; print (string) random("+", "*");
392   }
393 ];
394