Import ztornado by Sophie Frühling
[ztornado.git] / scores.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 Array hghscr_arr -> 7;
22 Array hghscr_tmparr -> 7;
23 [ InitHighScores  i j tmp;
24   print "^^[Trying to read highscore file]^";
25   @restore highscore_array 220 highscore_file -> i;
26   ! We couldn't read in the highscore file so we set up a new
27   ! highscore
28   if (i < 220) {
29     print "^[Couldn't read highscore file]^^";
30     print "[Please press a key]^"; Read();
31     tmp = 11000;
32     Nullify(hghscr_arr);
33     Nullify(hghscr_tmparr);
34     for (i = 0: i < 10: i++) {
35       for (j = i*22: j < i*22 + 15: j++)
36         highscore_array->j = '-';
37       tmp = tmp - 1000;
38       AddShort(hghscr_arr, hghscr_tmparr, tmp);
39       for (: j < (i+1)*22: j++)
40         highscore_array->j = hghscr_arr->(j - (i*22 + 15));
41     }
42   }
43 ];
44
45 Array tmp_hscr -> 7;
46 [ AddToHighScore player_name scr_arr  i;
47   for (i = 0: i < 10: i++) {
48     LookUpHighScore(tmp_hscr, i);
49     if (CompareLongs(scr_arr, tmp_hscr) > 0) {
50       InsertScoreTable(player_name, scr_arr, i);
51       rtrue;
52     }
53   }
54 ];
55
56 ! Copies the score at num into hs_array
57 [ LookUpHighScore hs_array num  i tmp;
58   tmp = num*22 + 15;
59   for (i = 0: i < 7: i++, tmp++)
60     hs_array->i = highscore_array->tmp;
61 ];
62
63 [ InsertScoreTable pl_nm scr_arr num  i tmp;
64   ! Shift all lower scores by 22
65   for (i = 219: i >= (num + 1)*22: i--)
66     highscore_array->i = highscore_array->(i - 22);
67   ! Insert the name
68   for (i = num*22, tmp = 2: tmp < 17: i++, tmp++)
69     highscore_array->i = pl_nm->tmp;
70   ! Insert the score
71   for (i = num*22 + 15, tmp = 0: tmp < 7: i++, tmp++)
72     highscore_array->i = scr_arr->tmp;
73 ];
74
75 [ ShowCurrentScores;
76   DrawCurrentScores();
77   DrawStatusLine();
78   Read();
79   ClearDialogWindow();
80   DrawSnowWorld();
81 ];
82
83 ! The high score window may overlap
84 ! with some part of a house or snow
85 [ ShowHighScores;
86   ClearHighScoreWindow();
87   DrawHighScores();
88   DrawStatusLine();
89   Read();
90   ClearHighScoreWindow();
91   DrawSnowWorld();
92 ];
93
94 [ PrintHighScoreName num  i;
95   for (i = num*22 : i < num*22 + 15: i++)
96     print (char) highscore_array->i;
97 ];
98
99 [ PrintHighScoreNumber num  i;
100   i = num*22 + 15;
101   ! Right-align numbers
102   while (i < (num+1)*22 - 1 && highscore_array->i == 0) {
103     print (char) ' '; i++;
104   }
105   for (: i < (num+1)*22: i++)
106     print highscore_array->i;
107 ];
108
109 !------------------ Numbers Juggling -----------------
110 ! Long numbers for calculating and printing out scores
111 ! The long numbers can have up to 7 digits.
112
113 [ Nullify num_array  i;
114   for (i = 0: i < 7: i++)
115     num_array->i = 0;
116 ];
117
118 [ CopyArray dest_array src_array  i;
119   for (i = 0: i < 7: i++)
120     dest_array->i = src_array->i;
121 ];
122
123 ! This appears not to work if dest_array is one of the source arrays
124 [ AddLongs dest_array array1 array2  i tmp plus;
125   for (i = 6, plus = 0: i >= 0: i--) {
126     tmp = array1->i + array2->i;
127     if (plus) tmp++;
128     if (tmp > 9) {
129       plus = 1;
130       tmp = tmp%10;
131     }
132     else plus = 0;
133     dest_array->i = tmp;
134   }
135 ];
136
137 Array short_array -> 7;
138 [ AddShort dest_array num_array num;
139   ShortToArray(short_array, num);
140   AddLongs(dest_array, num_array, short_array);
141 ];
142
143 [ ShortToArray num_array num  i tmp;
144   num_array->0 = 0;
145   num_array->1 = 0;
146   for (i = 2, tmp = 10000: i < 7: i++, tmp = tmp/10) {
147     num_array->i = num/tmp;
148     num = num%tmp;
149   }
150 ];
151
152 Array mult_array -> 7;
153 Array culm_array -> 7;
154 Array multitmp_array -> 7;
155 [ Multiply dest_array num_array num  i j tmp plus;
156   if (num == 0) {
157     Nullify(dest_array);
158     rtrue;
159   }
160   Nullify(culm_array);
161   ShortToArray(short_array, num);
162   i = 0;
163   while (short_array->i == 0) i++;
164   for (: i < 7: i++) {
165     Nullify(mult_array);
166     Nullify(multitmp_array);
167     for (j = 6: j >= 0: j--) {
168       tmp = num_array->j * short_array->i;
169       if (plus) tmp = tmp + plus;
170       if (tmp > 9) {
171         plus = tmp/10;
172         tmp = tmp%10;
173       }
174       else plus = 0;
175       mult_array->j = tmp;
176     }
177     Shift(mult_array, 6 - i);
178     AddLongs(multitmp_array, culm_array, mult_array);
179     Nullify(mult_array);
180     AddLongs(culm_array, multitmp_array, mult_array);
181   }
182   CopyArray(dest_array, culm_array);
183 ];
184
185 Array shift_array -> 7;
186 [ Shift the_array num  i;
187   Nullify(shift_array);
188   for (i = num: i < 7: i++)
189     shift_array->(i-num) = the_array->i;
190   CopyArray(the_array, shift_array);
191 ];
192  
193 [ CompareLongs array1 array2  i;
194   for (i = 0: i < 7: i++) {
195     if (array1->i < array2->i)
196       return -1;
197     if (array1->i > array2->i)
198       return 1;
199   }
200   return 0;
201 ];
202
203 [ longnr num_array  i;
204   i = 0;
205   ! Don't print out leading zeroes
206   while (i < 6 && num_array->i == 0)
207     i++;
208   for (: i < 7: i++)
209     print num_array->i;
210 ];
211