1 /*------------------------------------------------------------------.
2 | Copyright 1997, 1998, 2000, 2001  Alexandre Duret-Lutz            |
3 |                                    <duret_g@epita.fr>             |
4 |                                                                   |
5 | This file is part of Heroes.                                      |
6 |                                                                   |
7 | Heroes is free software; you can redistribute it and/or modify it |
8 | under the terms of the GNU General Public License version 2 as    |
9 | published by the Free Software Foundation.                        |
10 |                                                                   |
11 | Heroes is distributed in the hope that it will be useful, but     |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of        |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |
14 | General Public License for more details.                          |
15 |                                                                   |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software       |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA          |
19 | 02111-1307 USA                                                    |
20 `------------------------------------------------------------------*/
21 
22 /* Heroes constants */
23 
24 #include "system.h"
25 #include "keyb.h"
26 #include "keyvalues.h"
27 #include "joystick.h"
28 #include "pcx.h"
29 #include "sfx.h"
30 #include "structs.h"
31 #include "prefs.h"
32 #include "video.h"
33 #include "const.h"
34 #include "timer.h"
35 #include "heroes.h"
36 #include "argv.h"
37 
38 /* available round numbers */
39 int rounds_nbr_values[16] = {
40   1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 20, 30, 50, 100
41 };
42 
43 char in_menu = 1;
44 char in_demo = 0;
45 /* int error; */
46 char in_jokebox;
47 
48 char kbjoy[6] = { 0, 0, 0, 0, 0, 0 };
49 char kbjoyold[6] = { 0, 0, 0, 0, 0, 0 };
50 
51 a_pixel *(render_buffer[2]);		/* xbuf * ybuf */
52 
53 a_pixel glenz[8][256];		/* glenz lines */
54 
55 a_pcx_image main_font_img, vehicles_img;
56 a_pcx_image bonus_font_img;
57 a_pcx_image tile_set_img, font_deck_img;
58 
59 signed char minisinus[32];
60 bool two_players = false;
61 
62 a_player player[4];
63 int trail_pos[4][maxq];
64 a_dir8_pair trail_way[4][maxq];
65 int trail_offset[4];
66 char trail_size[4];		/* trail size, minus one */
67 
68 /* mapping color <-> player */
69 int col2plr[4];
70 int plr2col[4];
71 
72 a_level lvl;
73 
74 unsigned char *square_occupied;
75 a_dir8_pair *square_way;
76 a_tile_index *square_tile;
77 a_square_corrd_pair *square_coord;
78 signed char *square_object;
79 a_lemming **square_lemmings_list;
80 a_lemming **square_dead_lemmings_list;
81 a_lemming lemmings_support[lemmings_total];
82 int objects_nbr;
83 
84 int game_mode = 0;
85 a_gameid game_id;
86 int lemmings_anim_offset;
87 int lemmings_move_offset;
88 
89 char demo_ready = 0;
90 
91 char
key_or_joy_ready(void)92 key_or_joy_ready (void)
93 {
94   int i;
95   int ct = read_htimer (demo_trigger_htimer);
96 
97   if ((in_jokebox == 0)) {
98     if (ct >= 30 || check_what == check_demo)
99       demo_ready = 1;
100     else
101       demo_ready = 0;
102     if (ct >= 60) {
103       if (in_menu)
104 	event_sfx (118 + (rand () & 1));
105       reset_htimer (demo_trigger_htimer);
106     }
107   }
108 
109   if (key_ready ()) {
110     reset_htimer (demo_trigger_htimer);
111     return (1);
112   }
113   if ((joystick_detected & 1) && (opt.ctrl_one == 1 || opt.ctrl_two == 1)) {
114     for (i = 0; i < 6; i++)
115       kbjoyold[i] = kbjoy[i];
116     get_joystick_state ();
117     kbjoy[0] = is_joystick_up (0);
118     kbjoy[1] = is_joystick_right (0);
119     kbjoy[2] = is_joystick_down (0);
120     kbjoy[3] = is_joystick_left (0);
121     kbjoy[4] = is_joystick_button_a (0);
122     kbjoy[5] = is_joystick_button_b (0);
123     if ((kbjoy[0] && !kbjoyold[0])
124 	|| (kbjoy[1] && !kbjoyold[1])
125 	|| (kbjoy[2] && !kbjoyold[2])
126 	|| (kbjoy[3] && !kbjoyold[3])
127 	|| (kbjoy[4] && !kbjoyold[4])
128 	|| (kbjoy[5] && !kbjoyold[5])) {
129       reset_htimer (demo_trigger_htimer);
130       return (1);
131     }
132   }
133   return (0);
134 }
135 
136 a_keycode
get_key_or_joy(void)137 get_key_or_joy (void)
138 {
139   if (key_ready ())
140     return (get_key ());
141   if (kbjoy[0] && !kbjoyold[0])
142     return (HK_Up);
143   if (kbjoy[1] && !kbjoyold[1])
144     return (HK_Right);
145   if (kbjoy[2] && !kbjoyold[2])
146     return (HK_Down);
147   if (kbjoy[3] && !kbjoyold[3])
148     return (HK_Left);
149   if (kbjoy[4] && !kbjoyold[4])
150     return (HK_Enter);
151   if (kbjoy[5] && !kbjoyold[5])
152     return (HK_Escape);
153   printf ("get_key_or_joy(): no event.");
154   return (0);
155 }
156 
157 void
draw_glenz_box(a_pixel * dest,int c,int xt,int yt)158 draw_glenz_box (a_pixel *dest, int c, int xt, int yt)
159 {
160   a_pixel *glenzligne = glenz[c];
161   int xt2;
162 
163   for (; yt != 0; yt--) {
164     for (xt2 = xt; xt2 != 0; --xt2, ++dest)
165       *dest = glenzligne[*dest];
166     dest += xbuf - xt;
167   }
168 
169 }
170