1 // Copyright (C) 2007 Jason Woofenden
3 // This file is part of VoR.
5 // VoR is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or (at your option)
10 // VoR is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with VoR; see the file COPYING. If not, write to the
17 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 // MA 02111-1307, USA.
21 // This file has code to generate SDL keypress events
29 // auto pilot waits a random amount of time between zero and this many 1/20ths of a second
30 #define AUTOPILOT_MAX_DELAY 20.0
33 SDLKey keysyms[NUM_KEYS] = { SDLK_SPACE, SDLK_LEFT, SDLK_RIGHT, SDLK_UP, SDLK_DOWN};
34 int states[NUM_KEYS] = { 0, 0, 0, 0, 0, };
40 autopilot_set_timer() {
42 next_time = frnd() * AUTOPILOT_MAX_DELAY;
47 autopilot_set_timer();
51 autopilot_fix_keystates(Uint8* table) {
53 for(i = 0; i < NUM_KEYS; ++i) {
54 table[keysyms[i]] = states[i];
59 autopilot_num_down() {
61 for(num = 0, i = 0; i < NUM_KEYS; ++i) {
71 autopilot_send_event() {
72 int down = autopilot_num_down();
76 if(down && frnd() < 0.25 + (down / 4.0)) {
77 //event.type = SDL_KEYUP;
78 //event.key.state = 0;
79 nth = (urnd() % down) + 1;
85 //event.key.keysym.sym = keysyms[i];
91 //event.type = SDL_KEYDOWN;
92 //event.key.state = 1;
93 nth = (urnd() % (NUM_KEYS - down)) + 1;
99 //event.key.keysym.sym = keysyms[i];
106 //fprintf(stderr, "push event: %i %i\n", event.key.keysym.sym, event.type);
107 //SDL_PushEvent(&event);
111 autopilot(float ticks) {
113 if(delay > next_time) {
114 autopilot_set_timer();
115 autopilot_send_event();