1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
2  *
3  * Quadra, an action puzzle game
4  * Copyright (C) 1998-2000  Ludus Design
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 #ifndef _HEADER_CANVAS
22 #define _HEADER_CANVAS
23 
24 #include <vector>
25 
26 #include "random.h"
27 #include "stats.h"
28 #include "id.h"
29 #include "global.h"
30 #include "attack.h"
31 #include "video.h"
32 #include "buf.h"
33 
34 class Zone_next;
35 class Packet_clientmoves;
36 class Bloc;
37 class Net_connection;
38 class Zone;
39 class Executor;
40 class Overmind;
41 class Inter;
42 
43 class Canvas: public CS, public Identifyable {
44 public:
45 	//These states are used only in survivor mode
46 	enum State {
47 		PLAYING,
48 		WAITFORWINNER,
49 		WAITFORRESTART,
50 		LAST
51 	};
52 	class Watcher {
53 	public:
54 		Net_connection *nc;
Watcher(Net_connection * pnc)55 		Watcher(Net_connection *pnc) {
56 			nc = pnc;
57 		}
58 	};
59 
60 	void add_text_scroller(const char *st, int xoffset=4, int yoffset=0);
61 	void calc_speed();
62 	void set_next();
63 	void set_message(const char *m1, const char *m2);
64 	void change_level_single();
65 	static void change_level(const int level, Palette *pal, Bitmap *bit);
66 	void delete_bloc();
67 	bool check_collide(Bloc *blo, Byte px, Byte py, Byte rot);
68 	bool collide(Byte px, Byte py, Byte rot);
69 	void clear_key_all();
70 	void calc_shadow();
71 	void reinit();
72 	void restart();
73 	void clear_tmp();
74 	void give_line();
75 	void blit_bloc(Bloc *blo);
76 	void blit_level_up();
77 	void blit_back();
78 	void blit_flash();
79 	void small_blit_bloc(Bloc *blo);
80 	void small_blit_back();
81 	void small_blit_flash();
82 	Byte check_key(int i);
83 	void clear_key(int i);
84 	void unrelease_key(int i);
85 	void dirt_rect(int x1, int y1, int w1, int h1);
86 	void add_packet(Canvas *sender, Byte nb, Byte nc, Byte lx, Attack attack, Word hole_pos[]);
87 	void start_moves();
88 	void send_p_moves();
89 	void start_byte();
90 	void set_bit(int v);
91 	void write_byte();
92 	Canvas(int game_seed, Byte team, const char *nam, int ph_repeat, int pv_repeat, bool psmooth, bool pshadow, int phandicap, Net_connection *adr, int qplayer, bool wait_down);
93 	Canvas(int qplayer, int game_seed, Palette *p);
94 	virtual ~Canvas();
95 	void set_canvas_pos(int px, int py, Bitmap *fo, Video_bitmap *s, Zone_next *z, Zone_next *z2, Zone_next *z3, Inter *in);
96 	void hide();
97 	bool islocal() const;
98 	void add_watcher(Watcher *w);
99 	void remove_watcher(Net_connection *nc);
100 
101 	std::vector<Watcher*> watchers;
102 	//Potato stuff (server only)
103 	Byte potato_team_on_last_stamp;
104 	Dword potato_lines;
105   Zone *z_lines;
106   Zone* z_potatolines;
107   Zone* z_linestot;
108   Zone* z_potatolinestot;
109   int team_potato_lines;
110   int team_potato_linestot;
111 	bool should_remove_bonus; //Remove bonus when we have the chance
112 	Dword gone_time;
113   /* possible values of canvas->idle:
114     0: busy, canvas not available (being recursed)
115     1: idle, doing nothing (moving a block)
116     2: dead, waiting
117     3: gone, the player has left the game
118   */
119 	int idle;
120 	State state;
121 	bool dying; // Set to true while in Player_dead or Player_firstfrag
122 	bool wait_download; // Set when waiting for a P_DOWNLOAD (clients only)
123 	bool trying_to_drop;
124 	Word watch_date;
125 	bool small_watch;
126 	Palette *pal;
127 	Bitmap *bit;
128 	Random rnd;
129 	Byte color;
130 	Net_connection *remote_adr;
131 	bool local_player;
132 	bool occupied[36][18];
133 	Byte block[36][18];
134 	Byte blinded[36][18];
135 	Byte bflash[36][18];
136 	Byte flash[20];
137 	Byte dirted[36][18];
138 	Byte tmp[33][18];
139 	//unit block moved in last Player_check_link anim
140 	bool moved[36][18];
141   struct {
142     Byte x;   // position of the "hole"
143     Byte color;
144 		Byte blind_time;
145 		Word hole_pos; //Hole positions
146 		bool final;
147   } bon[20];  // the waiting annoying lines
148 	Byte last_x;  // position of the last dropped block (for line sending)
149 	char snapshot[32*10*2+1]; // 32 lines * 10 columns * 2 chars per block + 1 string terminator
150   Bloc* bloc;
151   Bloc* next;
152   Bloc* next2;
153   Bloc* next3;
154   Bloc* bloc_shadow;
155 	Byte color_flash;
156 	Dword frame_start;
157   Byte attacks[MAXPLAYERS];
158   Byte last_attacker;
159 	// stuff for latest new handicap code (version 24)
160 	enum { stamp_per_handicap = 3 };
161 	Byte handicaps[MAXPLAYERS]; // stamp counter vis-a-vis other players
162 	Byte handicap_crowd; // similar counter but for the crowdedness factor
163 	// If you read this, get yourself a cookie, you deserve it!
164 	Inter *inter;
165 	Overmind *over;
166 	Executor *myself;
167 	int handicap;
168   int level;
169   int speed;
170   int player; // player: LOCAL player number (0 to 2)
171 	int num_player; // num_player: net_list player number (0 to MAXPLAYERS)
172   int h_repeat;
173   int h_repeat_delay;
174   int v_repeat;
175 	int continuous;
176 	int level_up;
177   int side_speed;
178   int down_speed;
179   int depth;
180   int complexity;
181   int bonus;
182 	bool send_for_clean;
183   int x;
184   int y;
185 	char name[40];
186 	Byte player_hash[16];
187 	char *long_name(bool handi=true, bool gone=true);
188 	char team_name[40];
189 	Byte team_hash[16];
190 	bool smooth;
191 	bool shadow;
192 
193 	//After a call to collide (or check_collide) that returned
194 	//  true, collide_side_only says if the collision
195 	//  was solely with the canvas' side walls.
196 	bool collide_side_only;
197 	Buf da_moves;
198 
199 private:
200 	void blind_all(Byte time);
201 	void draw_block(int j, int i) const;
202 	void init_block();
203 	void init();
204 	void step_bflash();
205 	void small_draw_block(int j, int i) const;
206 
207 	Word best_move; //MSB: depth, LSB: complexity
208 	Word best_clean; //same here
209 	Word best_recurse; //MSB: complexity, LSB: depth
210   Zone_next* znext;
211   Zone_next* znext2;
212   Zone_next* znext3;
213   char msg1[64];
214   char msg2[64];
215   int v_repeat_delay;
216 	Bitmap *fond;
217 	Video_bitmap *screen;
218 	SDL_Surface *sprlevel_up;
219 	// multiplayer recording stuff
220 	Packet_clientmoves *moves;
221 };
222 
223 #endif
224