1 // Emacs style mode select -*- C++ -*-
2 //---------------------------------------------------------------------------
3 //
4 // $Id: swmain.c,v 1.5.2.1 2003/06/08 18:16:38 fraggle Exp $
5 //
6 // Copyright(C) 1984-2000 David L. Clark
7 // Copyright(C) 2001-2003 Simon Howard
8 //
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 2 of the License, or (at your
12 // option) any later version. This program is distributed in the hope that
13 // it will be useful, but WITHOUT ANY WARRANTY; without even the implied
14 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 // the GNU General Public License for more details. You should have
16 // received a copy of the GNU General Public License along with this
17 // program; if not, write to the Free Software Foundation, Inc., 59 Temple
18 // Place - Suite 330, Boston, MA 02111-1307, USA.
19 //
20 //---------------------------------------------------------------------------
21 //
22 // swmain - SW mainline
23 //
24 //---------------------------------------------------------------------------
25
26 #include <stdio.h>
27
28 #include "timer.h"
29
30 #include "sw.h"
31 #include "swcollsn.h"
32 #include "swgrpha.h"
33 #include "swinit.h"
34 #include "swmove.h"
35 #include "swsound.h"
36 #include "swtitle.h"
37 #include "swutil.h"
38
39 // sdh: framerate control
40
41 #define FPS 10
42
43 // sdh 28/10/2001: game options
44
45 BOOL conf_missiles = 0; // allow missiles: replaces missok
46 BOOL conf_solidground = 0; // draw ground solid like in sopwith 1
47 BOOL conf_hudsplats = 1; // splatted birds etc
48 BOOL conf_wounded = 1; // enable wounded planes
49 BOOL conf_animals = 1; // birds and oxes
50 BOOL conf_harrykeys = 0; // plane rotation relative to screen
51
52 playmode_t playmode; /* Mode of play */
53 GAMES *currgame; /* Game parameters and current game */
54 OBJECTS *targets[MAX_TARG + MAX_OXEN]; /* Status of targets array */
55 int numtarg[2]; /* Number of active targets by color */
56 int savemode; /* Saved PC display mode */
57 int tickmode; /* Tick action to be performed */
58 int counttick, countmove; /* Performance counters */
59 int movetick, movemax; /* Move timing */
60
61 int gamenum; /* Current game number */
62 int gmaxspeed, gminspeed; /* Speed range based on game number */
63 int targrnge; /* Target range based on game number */
64
65 BOOL hires; /* High res flag */
66 BOOL disppos; /* Display position flag */
67 BOOL titleflg; /* Title flag */
68 int dispdbg; /* Debug value to display */
69 BOOL soundflg = 0; /* Sound flag */
70 BOOL repflag = FALSE; /* Report statistics flag */
71 BOOL joystick; /* Joystick being used */
72 BOOL ibmkeybd; /* IBM-like keyboard being used */
73 BOOL inplay; /* Game is in play */
74 int koveride; /* Keyboard override index number */
75
76 int displx; /* Display left and right */
77 int dispdx; /* Display shift */
78 BOOL dispinit; /* Inialized display flag */
79
80 OBJECTS *drawlist; /* Onscreen object list */
81 OBJECTS *nobjects; /* Objects list. */
82 OBJECTS oobjects[MAX_PLYR]; /* Original plane object description */
83 OBJECTS *objbot, *objtop, /* Top and bottom of object list */
84 *objfree, /* Free list */
85 *deltop, *delbot; /* Newly deallocated objects */
86 OBJECTS topobj, botobj; /* Top and Bottom of obj. x list */
87
88 OBJECTS *compnear[MAX_PLYR]; /* Planes near computer planes */
89 int lcompter[MAX_PLYR] = { /* Computer plane territory */
90 0, 1155, 0, 2089
91 };
92 int rcompter[MAX_PLYR] = { /* Computer plane territory */
93 0, 2088, 1154, 10000
94 };
95
96 OBJECTS *objsmax = 0; /* Maximum object allocated */
97 int endsts[MAX_PLYR]; /* End of game status and move count */
98 int endcount;
99 int player; /* Pointer to player's object */
100 int currobx; /* Current object index */
101 BOOL plyrplane; /* Current object is player flag */
102 BOOL compplane; /* Current object is a comp plane */
103 OLDWDISP wdisp[MAX_OBJS]; /* World display status */
104 BOOL goingsun; /* Going to the sun flag */
105 BOOL forcdisp; /* Force display of ground */
106 char *histin, *histout; /* History input and output files */
107 unsigned explseed; /* random seed for explosion */
108
109 int keydelay = -1; /* Number of displays per keystroke */
110 int dispcnt; /* Displays to delay keyboard */
111 int endstat; /* End of game status for curr. move */
112 int maxcrash; /* Maximum number of crashes */
113 int shothole; /* Number of shot holes to display */
114 int splatbird; /* Number of slatted bird symbols */
115 int splatox; /* Display splatted ox */
116 int oxsplatted; /* An ox has been splatted */
117
118 int sintab[ANGLES] = { /* sine table of pi/8 increments */
119 0, 98, 181, 237, /* multiplied by 256 */
120 256, 237, 181, 98,
121 0, -98, -181, -237,
122 -256, -237, -181, -98
123 };
124
125 jmp_buf envrestart; /* Restart environment for restart */
126 /* long jump. */
127
128
main(int argc,char * argv[])129 int main(int argc, char *argv[])
130 {
131 int nexttic;
132
133 nobjects = (OBJECTS *) malloc(100 * sizeof(OBJECTS));
134
135 swinit(argc, argv);
136 setjmp(envrestart);
137
138 // sdh 28/10/2001: playmode is called from here now
139 // makes for a more coherent progression through the setup process
140
141 if (!playmode)
142 getgamemode();
143 swinitlevel();
144
145 nexttic = Timer_GetMS();
146
147 for (;;) {
148
149 /*----- DLC 96/12/27 ------
150 while ( movetick < 2 );
151 movetick = 0;
152 -------------------------*/
153 //while ( movetick < movemax );
154
155 // sdh: in the original, movetick was incremented
156 // automagically by a timed interrupt. we dont
157 // have interrupts so we have to pause between tics
158
159 nexttic += 1000 / FPS;
160 do {
161 swsndupdate();
162
163 // sdh 15/11/2001: dont thrash the
164 // processor while waiting
165 Timer_Sleep(10);
166 } while (Timer_GetMS() < nexttic);
167
168 movetick -= movemax;
169
170 // swmove and swdisp should be made to run
171 // asyncronously probably
172
173 swmove();
174 swdisp();
175 swgetjoy();
176 swcollsn();
177 swsound();
178 }
179
180 return 0;
181 }
182
183
184 //---------------------------------------------------------------------------
185 //
186 // $Log: swmain.c,v $
187 // Revision 1.5.2.1 2003/06/08 18:16:38 fraggle
188 // Fix networking and some compile bugs
189 //
190 // Revision 1.5 2003/06/04 17:13:26 fraggle
191 // Remove disprx, as it is implied from displx anyway.
192 //
193 // Revision 1.4 2003/06/04 16:02:55 fraggle
194 // Remove broken printscreen function
195 //
196 // Revision 1.3 2003/04/05 22:55:11 fraggle
197 // Remove the FOREVER macro and some unused stuff from std.h
198 //
199 // Revision 1.2 2003/04/05 22:31:29 fraggle
200 // Remove PLAYMODE_MULTIPLE and swnetio.c
201 //
202 // Revision 1.1.1.1 2003/02/14 19:03:14 fraggle
203 // Initial Sourceforge CVS import
204 //
205 //
206 // sdh 14/2/2003: change license header to GPL
207 // sdh 25/11/2001: remove intson, intsoff calls
208 // sdh 15/11/2001: dont thrash the processor while waiting between gametics
209 // sdh 29/10/2001: harrykeys
210 // sdh 28/10/2001: conf_ game options
211 // sdh 28/10/2001: moved auxdisp to swgrpha.c
212 // sdh 21/10/2001: rearranged headers, added cvs tags
213 // sdh 21/10/2001: reformatted with indent
214 // sdh 19/10/2001: removed externs, these are now in headers
215 // sdh 18/10/2001: converted all functions to ANSI-style arguments
216 //
217 // 96-12-26 Speed up game a bit
218 // 87-04-06 Computer plane avoiding oxen.
219 // 87-03-12 Wounded airplanes.
220 // 87-03-09 Microsoft compiler.
221 // 85-10-31 Atari
222 // 84-06-12 PC-jr Speed-up
223 // 84-02-02 Development
224 //
225 //---------------------------------------------------------------------------
226
227