5 * Copyright (C) 2003, 2007, 2008 Thomas Perl <thp@perli.net>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor, Boston,
36 # define BALL_STATES 16
38 # define BALL_STATES 4
41 typedef unsigned char bool;
47 #ifdef EXTENDED_REFEREE
84 bool responsible
; /* responsible for the next fault (if any) */
85 unsigned char desire
; /* what the player aims to do (0=normal, 1=upper edge, 2=lower edge)*/
86 bool type
; /* is this player ai-controlled or human? */
87 float ball_dest
; /* prospective y-position of ball */
88 bool state_locked
; /* enabled when user keeps pressing the "hit" key */
89 int game
; /* score for the current game */
90 int sets
[SETS_TO_WIN
*2]; /* score for each set */
91 int mouse_x
; /* x position of mouse */
92 int mouse_y
; /* y position of mouse */
93 float accelerate
; /* a value [0..1] how fast the user accelerates */
94 bool mouse_locked
; /* on start, ignore unpressed mouse state */
117 char game_score_str
[50];
118 char sets_score_str
[50];
119 unsigned char referee
;
120 unsigned int current_set
;
123 unsigned int court_type
;
124 unsigned int old_court_type
;
125 unsigned int history
[3];
126 unsigned int history_size
;
127 bool history_is_locked
;
128 unsigned char ngram
[NGRAM_STEPS
][NGRAM_STEPS
][NGRAM_STEPS
];
129 float ngram_prediction
;
133 unsigned char joystick_a
;
138 unsigned int windtime
;
141 unsigned char old_referee
;
146 #define GAME_TICKS 15
148 #define GROUND_PHASE 0.4
149 #define PHASE_AMP 3.2
151 #define BALL_JUMP_MIN 4
152 #define BALL_JUMP_MAX 10
154 #define RACKET_X_MID 15
155 #define RACKET_Y_MID 24
160 #define GAME_X_MIN 41.0*2
161 #define GAME_X_MAX 270.0*2
162 #define GAME_X_MID ((GAME_X_MIN+GAME_X_MAX)/2)
164 #define GAME_Y_MIN 155.0
165 #define GAME_Y_MAX 330.0
166 #define GAME_Y_MID ((GAME_Y_MIN+GAME_Y_MAX)/2)
168 #define GAME_EDGE_AREA 20.0
169 #define GAME_EDGE_UPPER GAME_Y_MIN+GAME_EDGE_AREA
170 #define GAME_EDGE_LOWER GAME_Y_MAX-GAME_EDGE_AREA
172 #define PLAYER_Y_MIN 0.0
173 #define PLAYER_Y_MAX 1.0*HEIGHT
175 #define IS_OFFSCREEN_Y(y) (((y)<0-BALL_Y_MID*2) || ((y)>HEIGHT+BALL_Y_MID*2))
176 #define IS_OFFSCREEN_X(x) (((x)<0-BALL_X_MID*2) || ((x)>WIDTH+BALL_X_MID*2))
177 #define IS_OFFSCREEN(x,y) ((IS_OFFSCREEN_X(x)) || (IS_OFFSCREEN_Y(y)))
178 #define IS_OUT_Y(y) (y<GAME_Y_MIN || y>GAME_Y_MAX)
179 #define IS_OUT_X(x) (x<GAME_X_MIN || x>GAME_X_MAX)
181 #define PLAYER_AREA_Y RACKET_Y_MID
182 #define PLAYER_AREA_X RACKET_X_MID
183 #define IS_NEAR_Y(py,by) (fabsf(py-by)<PLAYER_AREA_Y)
184 #define IS_NEAR_Y_AI(py,by) (fabsf(py-by)<PLAYER_AREA_Y/3.5)
185 #define IS_NEAR_X(px,bx) (fabsf(px-bx)<PLAYER_AREA_X)
186 #define IS_NEAR_X_AI(px,bx) (fabsf(px-bx)<PLAYER_AREA_X*2)
188 #define PLAYER_MOVE_Y 5.0
189 #define PLAYER_ACCEL_DEFAULT 0.2
190 #define PLAYER_ACCEL_INCREASE 1.2
191 #define PLAYER_STATE_MAX 7
192 #define PLAYER_POWERSHOT 6.2
194 #define MOVE_Y_SEED 3
196 /* Comment out the following #define to enable mouse control */
199 /* GameState handling*/
200 GameState
*gamestate_new();
203 /* Game module functions */
204 void gameloop(GameState
*);
205 void render( GameState
*);
206 bool step( GameState
*);
207 void limit_value( float*, float, float);
208 float get_phase( GameState
*);
209 float get_move_y( GameState
*, unsigned char);
210 void input_human( Player
*, bool, bool, bool, bool, GameState
*);
211 void input_ai( Player
*, Ball
*, Player
*, GameState
*);
212 void game_setup_serve( GameState
*);
213 float ngram_predictor( GameState
*);
215 void score_game( GameState
*, bool);
216 char* format_sets( GameState
*);
217 char* format_game( GameState
*);
218 char* format_status( GameState
*);
219 int game_get_winner( GameState
*);