Debian Codegraph @

src/xmas.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "xmas.h"cxx . . $ `<file>/src/xmas.h`/
20
21 #include "font.h"cxx . . $ `<file>/src/font.h`/
22 #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/
23 #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/
24 #include "mouse.h"cxx . . $ `<file>/src/mouse.h`/
25 #include "palette.h"cxx . . $ `<file>/src/palette.h`/
26 #include "sprite.h"cxx . . $ `<file>/src/sprite.h`/
27 #include "vga256d.h"cxx . . $ `<file>/src/vga256d.h`/
28 #include "video.h"cxx . . $ `<file>/src/video.h`/
29
30 #include <stdio.h>
31 #include <time.h>
32
33 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! xmascxx . . $ xmas. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
34
35 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! xmas_timecxx . . $ xmas_time(c9857a73d68e59ba).(void)
36 {
37 time_tcxx . . $ time_t# now = timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
38 return localtimecxx . . $ localtime(9477a1348abbbc5).(&now)->tm_moncxx . . $ tm#tm_mon. == 11;
39 }
40
41 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! xmas_promptcxx . . $ xmas_prompt(c9857a73d68e59ba).(void)
42 {
43 static const char *const prompt[] =
44 {
45 "Christmas has been detected.",
46 "Activate Christmas?",
47 };
48 static const char *const choices[] =
49 {
50 "Yes",
51 "No",
52 };
53
54 if (shopSpriteSheetcxx . . $ shopSpriteSheet..datacxx . . $ $anonymous_type_297934740aeafb7d_2#data. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
55 JE_loadCompShapescxx . . $ JE_loadCompShapes(676db0deaa5c5c40).(&shopSpriteSheetcxx . . $ shopSpriteSheet., '1'); // need mouse pointer sprites
56
57 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! restart = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
58
59 structcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#
60 {
61 Sint16cxx . . $ Sint16# xcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#x.;
62 Sint16cxx . . $ Sint16# ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y.;
63 Uint8cxx . . $ Uint8# dyAcccxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAcc.;
64 Uint8cxx . . $ Uint8# dyAddcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAdd.;
65 }
66 flakes[80];
67
68 static const Uint8cxx . . $ Uint8# dyDen = 128;
69
70 const int xCenter = 320 / 2;
71 const int yPrompt = 85;
72 const int dyPrompt = 15;
73 const int wChoice = 40;
74 const int yChoice = 120;
75 const int hChoice = 13;
76
77 size_t selectedIndex = 0;
78
79 for (; ; )
80 {
81 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! mouseMoved = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
82 do
83 {
84 if (restart)
85 {
86 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes); ++i)
87 {
88 flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y. = 200 + randcxx . . $ rand(b126dc7c1de90089).() % 200;
89 flakes[i].dyAddcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAdd. = dyDen / 2 + i * dyDen / COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes);
90 }
91 }
92
93 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes); ++i)
94 {
95 if (flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y. >= 200)
96 {
97 flakes[i].xcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#x. = randcxx . . $ rand(b126dc7c1de90089).() % 320;
98 flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y. = 200 - 14 - flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y.;
99 flakes[i].dyAcccxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAcc. = flakes[i].dyAddcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAdd.;
100 }
101
102 int temp = randcxx . . $ rand(b126dc7c1de90089).() & 0xF;
103 if ((temp & 0xE) == 0)
104 flakes[i].xcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#x. += (temp & 1) * 2 - 1;
105
106 Uint16cxx . . $ Uint16# dyNum = flakes[i].dyAcccxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAcc. + flakes[i].dyAddcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAdd.;
107 Uint8cxx . . $ Uint8# dy = dyNum / dyDen;
108 flakes[i].dyAcccxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#dyAcc. = dyNum % dyDen;
109 flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y. += dy;
110 }
111
112 fill_rectangle_whcxx . . $ fill_rectangle_wh(2ff783435439505a).(VGAScreencxx . . $ VGAScreen., 0, 0, 320, 200, 0x8F);
113
114 // Draw background snowflakes.
115 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes) * 2 / 3; ++i)
116 blit_sprite2_blendcxx . . $ blit_sprite2_blend(b5d0f2be3b000a5b).(VGAScreencxx . . $ VGAScreen., flakes[i].xcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#x., flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y., spriteSheet8cxx . . $ spriteSheet8., 225);
117
118 // Draw prompt.
119 for (uintcxx . . $ uint# i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(prompt); ++i)
120 draw_font_hv_full_shadowcxx . . $ draw_font_hv_full_shadow(198b4ac5940c9e46).(VGAScreencxx . . $ VGAScreen., xCenter, yPrompt + dyPrompt * i, prompt[i], normal_fontcxx . . $ normal_font., centeredcxx . . $ centered., (i % 2) ? 2 : 4, -2, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, 1);
121
122 // Draw choices.
123 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(choices); ++i)
124 {
125 const int x = xCenter - wChoice / 2 + wChoice * (int)i;
126
127 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! selected = (selectedIndex == i);
128
129 draw_font_hv_full_shadowcxx . . $ draw_font_hv_full_shadow(198b4ac5940c9e46).(VGAScreencxx . . $ VGAScreen., x, yChoice, choices[i], normal_fontcxx . . $ normal_font., centeredcxx . . $ centered., 15, selected ? -2 : -4, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, 1);
130 }
131
132 // Draw foreground snowflakes.
133 for (size_t i = COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes) * 2 / 3; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(flakes); ++i)
134 blit_sprite2_blendcxx . . $ blit_sprite2_blend(b5d0f2be3b000a5b).(VGAScreencxx . . $ VGAScreen., flakes[i].xcxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#x., flakes[i].ycxx . . $ xmas_prompt(c9857a73d68e59ba).$anonymous_type_0#y., spriteSheet8cxx . . $ spriteSheet8., 226);
135
136 if (restart)
137 {
138 mouseCursorcxx . . $ mouseCursor. = MOUSE_POINTER_NORMALcxx . . $ MOUSE_POINTER_NORMAL.;
139
140 fade_palettecxx . . $ fade_palette(59ab901998e00635).(palettescxx . . $ palettes.[0], 10, 0, 255);
141
142 restart = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
143 }
144
145 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
146
147 JE_mouseStartcxx . . $ JE_mouseStart(49f6e7a06ebc5aa8).();
148 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
149 JE_mouseReplacecxx . . $ JE_mouseReplace(49f6e7a06ebc5aa8).();
150
151 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
152
153 Uint16cxx . . $ Uint16# oldMouseX = mouse_xcxx . . $ mouse_x.;
154 Uint16cxx . . $ Uint16# oldMouseY = mouse_ycxx . . $ mouse_y.;
155
156 push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).();
157 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
158
159 mouseMoved = mouse_xcxx . . $ mouse_x. != oldMouseX || mouse_ycxx . . $ mouse_y. != oldMouseY;
160 } while (!(newkeycxx . . $ newkey. || newmousecxx . . $ newmouse. || mouseMoved));
161
162 // Handle interaction.
163
164 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! action = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
165 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cancel = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
166
167 if (mouseMoved || newmousecxx . . $ newmouse.)
168 {
169 // Find choice that was hovered or clicked.
170 if (mouse_ycxx . . $ mouse_y. >= yChoice && mouse_ycxx . . $ mouse_y. < yChoice + hChoice)
171 {
172 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(choices); ++i)
173 {
174 const int xChoice = xCenter - wChoice + wChoice * (int)i;
175 if (mouse_xcxx . . $ mouse_x. >= xChoice && mouse_xcxx . . $ mouse_x. < xChoice + wChoice)
176 {
177 selectedIndex = i;
178
179 if (newmousecxx . . $ newmouse. && lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_LEFTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:445:9`! &&
180 lastmouse_xcxx . . $ lastmouse_x. >= xChoice && lastmouse_xcxx . . $ lastmouse_x. < xChoice + wChoice &&
181 lastmouse_ycxx . . $ lastmouse_y. >= yChoice && lastmouse_ycxx . . $ lastmouse_y. < yChoice + hChoice)
182 {
183 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
184 }
185
186 break;
187 }
188 }
189 }
190 }
191
192 if (newmousecxx . . $ newmouse.)
193 {
194 if (lastmouse_butcxx . . $ lastmouse_but. == SDL_BUTTON_RIGHTcxx . . $ `<external>/13849749812924280863/SDL_mouse.h:447:9`!)
195 {
196 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
197 }
198 }
199 else if (newkeycxx . . $ newkey.)
200 {
201 switch (lastkey_scancxx . . $ lastkey_scan.)
202 {
203 case SDL_SCANCODE_LEFTcxx . . $ SDL_SCANCODE_LEFT.:
204 {
205 selectedIndex = selectedIndex == 0
206 ? COUNTOFcxx . . $ `src/opentyr.h:27:9`!(choices) - 1
207 : selectedIndex - 1;
208 break;
209 }
210 case SDL_SCANCODE_RIGHTcxx . . $ SDL_SCANCODE_RIGHT.:
211 {
212 selectedIndex = selectedIndex == COUNTOFcxx . . $ `src/opentyr.h:27:9`!(choices) - 1
213 ? 0
214 : selectedIndex + 1;
215 break;
216 }
217 case SDL_SCANCODE_SPACEcxx . . $ SDL_SCANCODE_SPACE.:
218 case SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN.:
219 {
220 action = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
221 break;
222 }
223 case SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.:
224 {
225 cancel = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
226 break;
227 }
228 default:
229 break;
230 }
231 }
232
233 if (action || cancel)
234 {
235 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
236
237 return !cancel && selectedIndex == 0;
238 }
239 }
240 }