/[projet1]/users/barnsey123/HNEFATAFL/main.c
Defence Force logotype

Contents of /users/barnsey123/HNEFATAFL/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 978 - (show annotations)
Sun Nov 24 18:35:12 2013 UTC (6 years, 4 months ago) by barnsey123
File MIME type: text/plain
File size: 88582 byte(s)
v0.078 Trophy Text added and URUZ trophy now calculates correctly
1 // HNEFATAFL by Neil Barnes (a.k.a. Barnsey123)
2 // 24-08-2012 NB: Tided up source (removed "bracket hell")
3 // 27-08-2012 NB: v0.012 Minor changes to save memory
4 // 27-08-2012 NB: v0.013 Created Priority array and routine to populate it
5 // 28-08-2012 NB: v0.014 Add hightarget to pacman checkroute (when route to corners are empty)
6 // 30-08-2012 NB: V0.015 updated pacman routines - added brokenarrow
7 // 01-09-2012 NB: V0.016 Fixed brokenarrow
8 // 02-09-2012 NB: v0.017 Compressed - and fixed - checkroute()
9 // 03-09-2012 NB: v0.018 Rejigged pacman (do a while...to edge)
10 // 05-09-2012 NB: v0.019 pacman2
11 // 21-10-2012 NB: v0.020 Fixed bug in gspot
12 // 22-10-2012 NB: v0.021 Fixed bugs in following:
13 // pacman2 [not calculating hightarget in right place, not doing brokenarrow properly)
14 // sub [not calcing points properly]
15 // 23-10-2012 NB: v0.022 Removed some redundant code (enemytargetupdate)
16 // 24-04-2013 NB: v0.023 starting to add DEADPILE
17 // 25-04-2013 NB: v0.024 Font Changes for deadpile, endgame detection improvements, some memory reduction
18 // 27-04-2013 NB: v0.025 Some changes to make code clearer
19 // 29-04-2013 NB v0.026 some more cleary uppy stuff . fixed bug in endgame detection.broken arrow not working.
20 // 29-04-2013 NB v0.027 adding kingtracker (all the spaces where the king can get to
21 // 01-05-2013 NB v0.028 Brokenarrow fixed
22 // 01-05-2013 NB v0.029 Potential Broken Arrow Situation
23 // 02-05-2013 NB v0.030 Fixed central square "backbone" issue
24 // 02-05-2013 NB v0.031 Added TRIGGER weighting and changes to brokenarrow
25 // 04-05-2013 NB v0.032 Replecaed g variable in gspot with kingtoedge array
26 // 04-05-2013 NB v0.033 Introduced pacman3 and some changes to subpacmanx
27 // 07-05-2013 NB v0.040 Skip 03x coz of different versions floating about
28 // 07-05-2013 NB v0.041 Fixed a few bugs, reduced footprint
29 // 08-05-2013 NB v0.042 resolving the vinegar strokes (trying)
30 // 08-05-2013 NB v0.043 SHAZAM! One major bug resolved (broken arrow issue)
31 // 09-05-2013 NB v0.044 Exploiting tzonemode
32 // 13-05-2013 NB v0.045 Introduction of RED FLAG (vinegar strokes issue 1 resolved) PROBLEM with illegal moves
33 // 13-05-2013 NB v0.046 released not tested
34 // 14-05-2013 NB v0.047 bugfix in enemy[][] array testing. Minor font change. Redflag disables full brokenarrow
35 // 15-05-2013 NB v0.048 Fixed illegal moves.
36 // 21-05-2013 NB v0.049 improving AI (RingOfSteel), added color to deadpile
37 // 03-06-2013 NB v0.050 Added color cursor (removed dotted type as got messy)
38 // 03-06-2013 NB v0.051 replace some draw and curset commands
39 // 04-06-2013 NB v0.052 minor change to brokenarrow
40 // 11-06-2013 NB v0.053 using asm instead of hchar/curset
41 // 12-06-2013 NB v0.054 add RowCountAtt and ColCountAtt to record number of attackers on any given row/col
42 // 15-07-2013 nb V0.060 (V0.055 IS PARKED)
43 // 17-07-2013 NB v0.061 Adding turncounters, turns remaining (huns, thor, odin variables)
44 // 17-07-2013 NB v0.062 removed "ring of steel"
45 // 17-07-2013 nb v0.063 Tidied up display, changed font, added SAGA, THOR, ODIN modes
46 // 18-07-2013 NB v0.064 REMOVE RowCountAtt and ColCountAtt
47 // 18-07-2013 NB v0.065 added "ring of steel" for THOR and ODIN levels
48 // 18-07-2013 NB v0.066 possible screw up with new ODINJUMP (though new calchightarget looks good)
49 // 18-07-2013 NB v0.067 FIRST BLOOD MODE
50 // 22-07-2013 NB v0.068 More efficient text display (for remaining turns)
51 // 22-07-2013 NB v0.069 Flashing TEXT for "PRESS A KEY" and FIRST BLOOD
52 // 06-09-2013 NB v0.070 Bug in calcantake2 WAS: (ew < 10) NOW: (ew < 9)
53 // 07-09-2013 NB v0.071 Adding flashing messages for multiple takes
54 // 04-11-2013 NB v0.072 To be called from VIKLOADER (this version has no font data loaded) and NO FLIPRUNE
55 // 05-11-2013 NB v0.073 Calling hires from CopyFont in Loader saving 3 bytes!
56 // Also adding border tiles for Trophy Display
57 // 06-11-2013 NB v0.074 Fixed Trophy Screen issues
58 // 07-11-2013 NB v0.075 New credits text
59 // 08-11-2013 NB v0.076 New Trophy Graphic, contents drawn
60 // 09-11-2013 NB v0.077 Draw Trophy Grid edges and Color Headings
61 // 24-11-2013 NB v0.078 Adds text to Trophy Screen...
62 /****************************************/
63 // TODO:
64 // Add Text to Trophy Screen (Trophy Descriptions)
65 #include <lib.h>
66 #define NORTH 0
67 #define SOUTH 1
68 #define EAST 2
69 #define WEST 3
70 #define ENEMYWEIGHT 37
71 #define DEADPILEA 222
72 #define DEADPILED 234
73 #define SIDESTEP 3
74 #define ATTACKER 1
75 #define DEFENDER 2
76 #define KING 3
77 #define CASTLE 4
78 #define ENEMYBLOCK 3
79 #define TAKEWEIGHT 5
80 #define TRIGGERHIGH 3
81 #define TRIGGERLOW 7
82 #define PARTIAL1 0
83 #define PARTIAL2 1
84 #define FULL 2
85 #define NO 0
86 #define YES 1
87 #define BLACK 0
88 #define RED 1
89 #define GREEN 2
90 #define YELLOW 3
91 #define BLUE 4
92 #define MAGENTA 5
93 #define CYAN 6
94 #define WHITE 7
95 #define SAGA 0
96 #define THOR 1
97 #define ODIN 2
98 #define TROPHY 12
99 #define FIRSTBLOOD 1
100 #define BLOODEAGLE 2
101 #define BERZERKER 3
102 #define ALGIZ 4
103 #define URUZ 5
104 #define RAIDO 6
105 /*
106 FIRSTBLOOD = MAKE FIRST KILL
107 BLOODEAGLE = DOUBLE KILL
108 BERZERKER = TRIPLE KILL
109 ALGIZ = SURVIVAL - DONT LOSE A MAN - DEFENCE - SELF PRESERVATION
110 URUZ = SPEED - WIN WITH >= 5 TURNS REMAINING
111 RAIDO = A LONG JOURNEY - WIN ON LAST TURN
112 */
113 //#define VINEGAR 3
114 extern unsigned char ExplodeTiles[]; // extra graphics to "explode" a piece (animation)
115 extern unsigned char PictureTiles[]; // standard graphics for pieces and backgrounds
116 //extern unsigned char RunicTiles[]; // Runic alphabet
117 extern unsigned char TimerTiles[]; // display timer in central square when computer's turn
118 extern unsigned char BorderTiles2[]; // for Trophy Screen
119 /*
120 ; You simply replace the existing font from C doing this:
121 ;
122 ; extern unsigned char Font_6x8_FuturaFull[1024];
123 ;
124 ; Then to set the HIRES font:
125 ; memcpy((unsigned char*)0x9800+32*8,Font_6x8_FuturaFull,768);
126 ;
127 ; Or to set the TEXT font:
128 ; memcpy((unsigned char*)0xb400+32*8,Font_6x8_FuturaFull,768);
129 ;
130 */
131 //extern unsigned char Font_6x8_runic1_partial[520]; // runic oric chars (was [1024] 02/02/2012)
132
133 /* RUNIC Alphabet Tiles (NOT the runic1 font) ordered as follows :
134 Actually, the numbers here are not true anymore due to changes in the runes.png file
135 However, Have left the descriptions for educational purposes...
136 The Viking "alphabet" begins with "F" and is rEferred to as "FUTHAR" rather than "Alphabet"
137 0 F: Fehu Cattle/Gold/General Wealth
138 1 U: Uruz Strength/Speed/Good Health
139 2 TH: Thurisaz Norse Giants
140 3 A: Ansuz The Gods, mostly Odin
141 4 R: Raido A long Journey
142 5 K/C: Kenaz Torch/Light source
143 6 G: Gebo sACRIFICE/OFFERING TO THE gODS
144 7 W: Wunjo Comfort/Joy/Glory
145 8 H: Hagalaz Hail/Missile
146 9 N: Nauthiz Need/Necessity
147 10 I: Isa ICE
148 11 Y/J: Jera year/harvest
149 12 EI: Eithwaz Sacred Yew tree
150 13 P: Perth Unknown
151 14 Z: Algiz Defence/Protection/Self-Preservation
152 15 S: Sowilo The Sun
153 16 T: Tiwaz The War God, TYR
154 17 B: Berkano Birch Tree/LDUN(goddess of spring/fertility)
155 18 E: Ehwaz Horse
156 19 M: Mannaz Man/Mankind
157 20 L: Laguz Water
158 21 NG: Ingwaz the Danes (and danish hero ING)
159 22 D: Dagaz Day/Daylight
160 23 O: Othila Inheritance (of property or knowledge)
161 */
162 /******************* Function Declarations ************************/
163 //void brokenarrow();
164 //void deccounter(); // decrement counter
165 //void LookBackInAnger(); // runs subcanbetaken if the piece "behind" an attacker is defender/king and prospective target adjacent to defender/king
166 //void subLookBackInAnger(); // runs the various "lookbackinanger" checks
167 //void zoneupdate(); // Increment target positions on unnocupied rows/columns (especially the "zone")
168 unsigned char cantakepiece(); // returns 0=no, 1 yes
169 unsigned char checkroute(); // sets counter to be number of pieces on a given route
170 void blinkcursor(); // blinks the cursor to attract attention
171 void calccantake(); // can take be made (how many)
172 void calchightarget(); // updates value of hightarget (the highest target so far)
173 //void calctakeweight(); // calculate the weight of "takeweight"
174 void canbetaken(); // can I be taken after moving here? returns value (take) 0=no 1=yes
175 void canpiecemove(); // can a selected piece move? 0=no, 1=yes
176 void cantakeadjust(); // decrement cantake if taken piece is on same plane as king
177 void checkbrokenarrow(); // check to see if brokenarrow can be incremented
178 void checkend(); // check for end game conditions
179 void checkincroute(); // check to see if OK to incroute
180 void computerturn(); // AI for computer
181 void cursormodevalid(); // sets modevalid to 1
182 void cursormodezero(); // set cursor mode to 0 if 1
183 void decpoints(); // decrement points variable
184 void decroute(); // decs route
185 void pointsplusten(); // ADDS 10 TO POINTS
186 void drawarrow(); // draws "arrow"
187 void drawboard(); // kicks off drawgrid/drawtiles
188 void drawcursor(); // draws cursor
189 void drawpiece(); // draws piece
190 void drawplayers(); // draw playing pieces
191 void drawtile(); // draw a tile (subroutine of drawtiles)
192 void drawtiles(); // draws all tiles at board x,y boxsize z (uses draw*tile functions)
193 void enemyzero(); // set enemy value to zero when surrounded=3
194 void explodetile(); // explodes a piece (plays an animation)
195 void findpiece();
196 void flashscreen(); // flashes screen in selected color for a second or so
197 //void fliprune(); // flip the rune tiles in title screen
198 void gspot(); // count no of targets from king to edge
199 //void incbrokenarrow(); // increments the value of brokenarrow
200 void inccantake(); // increments cantake
201 void inccounter(); // inc counter
202 void incdefatt(); // increments count of attacker/defenders round king (calls incking...)
203 void inckingattacker(); // increments count of attackers round king
204 void inckingdefender(); // increments count of defenders round king
205 void incmodeone(); // increment the modeonevalid variable (from 0 to 1)
206 void incpoints(); // increment points variable
207 void incroute(); // incs route
208 void incsurround(); // increment "surrounded" variable
209 void inctarget(); // inc target[xns][xew]
210 void inverse(); // inverse the color in the square
211 void movecursor2(); // move cursor routine
212 void movepiece(); // move a piece
213 void pacman2(); // update target positions around king (need to develop further)
214 void pacman3();
215 void pacman4();
216 void pacman5();
217 //void pacman6(); // "vinegar strokes"
218 void pause(); // wait a certain period of time (pausetime)
219 void playerturn(); // takes user input to move cursor
220 void backbone(); // renamed from "printarrowsorblanks"
221 void printdestinations(); // print arrows on tiles where a piece can move
222 void printmessage(); // prints message to screen
223 void printpossiblemoves(); // Print possible moves
224 //void printtitles(); // print the title screen (used in titles/menus etc)
225 void PrintTrophyScreen(); // prints the trophy screen
226 void PrintTrophyScreen1(); // sub of PrintTrophyScreen
227 //void PrintTrophyScreen2(); // blank out right edge of board
228 void PrintTrophyScreen3(); // Draw the Trophy Grid
229 void PrintTrophyScreen4(); // Print the Trophy Titles
230 void printturnprompt(); // prints "your turn" message
231 void prioritycalc(); // updates priority array
232 void setpoints(); // set points to default value
233 void subarrows(); // subroutine of arrows or blanks
234 void subarrows2(); // subroutine of arrows or blanks (updates ENEMY with direction of enemy)
235 void subcanbetaken2(); // attempt to reduce memory footprint
236 //void subpaceastwest(); // subroutine of pacman
237 //unsigned char subpaccrosst(); // sub of pacman2
238 void subpacmanx(); // grand sub of pacman2
239 void subpacmany(); // apply points from the pacman routines
240 //void subpacnorthsouth(); // subroutine of pacman
241 //void subzoneupdate(); // subroutine of pacman
242 void surroundcheck(); // inc surrounded under various conditions
243 void surroundcount(); // counts the number of attackers surrounding KING (or edges, or central square)
244 void surroundpoints(); // increment points around king depending on "surrounded" figure
245 void takepiece(); // takes specified piece
246 void sidestep(); // add SIDESTEP to target (used in escape routine)
247 void targetselect(); // choose a target square
248 void tileloop(); // subfunction of explodetile and drawtile
249 void timertile(); // print timer
250 //void updateroutehightarget();// adds hightarget to targets on route
251 void updateroutetarget(); // increment targets on a given route
252 void updatetarget(); // updates target array
253 void zerocounter(); // set counter=0
254 //void zerofoundpiece(); // set foundpiece to 0 (PIECE NOT FOUND)
255 void deadpile(); // draw deadpile
256 void flashred(); // flash screen in red
257 //void gethightarget(); // without upsetting any other variables
258 void calccantake2(); // alternative calcantake
259 void calcturnvalue(); // calculate hundreds,tens,units (huns, thor and odin)
260 void printturnline(); // prints the turn counters
261 void takemessage(); // prints a message when multiple takes are made
262 void submessage(); // subroutine of takemessage
263 void ClearTrophies(); // Initialize the trophies array
264 void AlgizThorTrophyCalc(); // calculate awarding of the ALGIZ and THOR trophies
265 void DrawPictureTiles(); // called from lots of places so gets own function
266 /****************** GLOBAL VARIABLES *******************************/
267 /* Populate array with tile types
268 Tile types:
269 0=blank
270 1=attacker square
271 2=defender square
272 3=king square
273 */
274 extern unsigned char tiles[11][11]; // tile description on board
275 extern unsigned char target[11][11]; // uninitialized variable (will calc on fly) - target values of square
276 extern unsigned char TrophyText[6][11]; // Titles of Trophies
277 //extern const unsigned char border[6][11]; // border (of title screens/menus etc)
278 //extern unsigned char presents[8]; // array of runic chars that spell "presents"
279 //extern unsigned char hnefatafl[9]; // array of runic chars that spell "hnefatafl"
280 /* populate array with places of players
281 Players:
282 0=vacant
283 1=attacker resident
284 2=defender resident
285 3=king resident
286 4=corner square // added 21/04/2011
287 */
288 //extern char baseplayers[11][11]; // BASEPLAYERS - the starting board positions. PLAYERS is the working COPY of BASEPLAYERS
289
290 // ARRAY ENEMY unititialized variable (will calc on fly) - can enemy reach a square?
291 // values:
292 // +1 Can be reached from NORTH
293 // +5 can be reached from SOUTH
294 // +10 can be reached from EAST
295 // +20 can be reached from WEST
296 extern unsigned char enemy[11][11]; // where the defenders can get to
297 extern unsigned char computer[11][11]; // where the attackers can get to
298 //extern unsigned char priority[11][11]; // holds the priority of a piece to move
299 extern unsigned char kingtracker[11][11]; // where the king can get to
300 //extern unsigned char RowCountAtt[11]; // count of attackers on a Row
301 //extern unsigned char ColCountAtt[11]; // count of attackers on a Column
302 unsigned char players[11][11]; // to be the working copy of baseplayers
303 unsigned char playertype,piecetype; // player 1=attacker, 2=defender
304 unsigned char ns,ew; // default north/south position of central square (0-10)
305 unsigned char cx,cy; // cursor x screen position (pixels across)
306 unsigned char fb=1; // foreground/background 0=background, 1=foreground, 2=opposite, 3=nothing
307 //unsigned char inversex; // x position of square to be inversed (to highlight a selected piece)
308 //unsigned char inversey; // y position of square to be inversed (to highlight a selected piece)
309 char mkey; // code of key pressed (plus loops)
310 unsigned char cursormode; // cursor movement mode 0=freeform 1=restricted
311 unsigned char ons,oew; // original north/south board pos
312 unsigned char ocx,ocy; // original xpos of piece
313 unsigned char orientation; // 0=north, 1=south 2=east 3=west
314 unsigned char tiletype; // type of tile under inspection (used in arrows)
315 unsigned char tpns,tpew; // north-south board location of taken piece (also used for 3) NB:no idea 20/10/2011
316 unsigned char flashcolor; // color of ink to flash in
317 unsigned char flashback; // color of ink to return to
318 char game; // *** MUST NOT BE UNSIGNED ***<=0 means endgame (see checkend for values), 1=GAMEON
319 unsigned char gamestyle; // 0=human vs human; 1=human king vs computer; ** NO!!! 2=human vs computer king**; 3=undefined
320 unsigned char kingns,kingew;// kings position North-South
321 unsigned char kingattacker[4]; // number of attackers in all four directions from king
322 unsigned char kingdefender[4]; // number of defenders in all four directions from king
323 unsigned char kingpieces[4]; // number of pieces in all four directions around king (saves calculating it all the time)
324 unsigned char surrounded; // status of king "surrounded" status //
325 unsigned char ctns=0; // Computer Turn north-south board position
326 unsigned char ctew=0; // Computer Turn east-west board position
327 extern char* playertext;
328 extern char* message;
329 unsigned char foundpiece; // has a piece been found (during computer move) that can move to the hightarget square? 0=no, 1=yes&ok, 9=yes!ok
330 //char xloop=0; // general purpose loop variable
331 unsigned char xns=0; // copy of ns (arrows or blanks, and subarrows)
332 unsigned char xew=0; // copy of ew (arrows or blanks, and subarrows)
333 unsigned char arrow=1; // used in arrowsorblanks(and subarrows)
334 unsigned char flag=0;
335 unsigned char cantake; // can I take? (for computer turn)
336 unsigned char route;
337 unsigned char row,col; // used in tile drawing routines and array navigation ( a row in 11x11 grid)
338 //unsigned char col; // used in tile drawing routines and array navigation ( a column in 11x11 grid)
339 unsigned char tiletodraw; // used in tile drawing routines 0-11 (as at 18-10-2011)
340 int pausetime; // amount of time to wait
341 //unsigned char* ptr_draw; // ptr to board starting position (e.g. 0xa002)
342 unsigned char* ptr_graph; // pointer to byte values of loaded picture
343 unsigned char points; // points around king
344 char counter; // general purpose counter (*** DO NOT set to UNSIGNED *** NB 24/10/2011)
345 char uncounter; // *** MUST BE SIGNED *** general purpose counter (can be negative)
346 //unsigned char lookcol,lookrow; // used in lookbackinanger
347 unsigned char origorient; // original orientation of a piece under test (which way he is heading)
348 unsigned char takerow,takecol; // can I be taken if I stop here?
349 unsigned char paclevel1,paclevel2; // used in pacman/subpacmanx either ns/ew
350 unsigned char surns,surew; // count of attackers surrounding king n/s used in surroundcount()
351 unsigned char takena,takenb,takenc,takend,takene; // used in canbetaken routines
352 unsigned char ezns1,ezew1; // used in surroundcount/enemyzero to reset enemy[][] to zero if surrounded=3
353 // WEIGHTS
354 //unsigned char enemyweight=37; // >36. weight of "enemy could get here but piece occupied by attacker"
355 //char defaulttakeweight=5; // default weight assigned to a TAKE
356 //unsigned char takeweight; // weight assigned to a TAKE (calculated in "calctakeweight")
357 //unsigned char cbtweight=4; // weight to be applied to escape position if can be taken
358 // End of Weights
359 //unsigned char pacpointsx,pacpointsy,pacpointsa,pacpointsb; // used to calculate points in subpacmanx
360 unsigned char pcheckns1,pcheckns2; // used in taking pieces and checking for takes
361 unsigned char pcheckew1,pcheckew2; // used in taking pieces and checking for takes
362 unsigned char startrow,startcol; // used in checkroute (returns no of pieces on a given path)
363 unsigned char destrow,destcol; // used in checkroute (returns no of pieces on a given path)
364 unsigned char canmovecursor; // controls wether screen cursor can be moved or not
365 unsigned char hightarget; // contains highest value target
366 unsigned char targetns,targetew; // used to calc takes
367 unsigned char x,y,z,a,b,c,d,e,f; // general purpose variables
368 /* below used for cursor move routine */
369 unsigned char multiple; // concerning central square (how much to multiply the coords to SKIP the square
370 unsigned char xptrns; // copy of NS
371 unsigned char xptrew; // copy of EW
372 unsigned char skipns; // skip to north/south
373 unsigned char skipew; // skip to east/west
374 unsigned char modeonevalid; // is OK for mode 1? 0=no, 1=yes
375 /* above variables used in cursor move routine */
376 unsigned char gameinput=0; // 0=undefined 1=play against computer, 2=human vs human
377 unsigned char take;
378 unsigned char p1; // piece type comparison (lower) - used for determining takes - default=attacker
379 unsigned char p2; // piece type comparison (upper) - used for determining takes - default=attacker
380 /* playerturn variables */
381 unsigned char xkey; // code of key pressed
382 unsigned char canselect; // 0=no, 1=yes (is the piece selectable?)
383 char cursormovetype; // -1=no, 0=yes (n,s,e,w) 1=(north/south only), 2=(east/west only)
384 unsigned char turn; // determines end of player turn 1=playerturn, 0=end of playerturn
385 unsigned char compass[4]; // used in cantake (if compass[NORTH]=1 then means canbetaken if i move here from NORTH
386 /* end of playerturn variables */
387 unsigned char xplayers;
388 unsigned char inkcolor; // screen color
389 unsigned char checkroutemode; // mode used for checkroute function
390 // 1=count number of pieces on route
391 // 2=increment target values on route (if no pieces on route)
392 // 3=amount of targets on route
393 // 4=Number of "enemy" targets on route (where enemies CAN go)
394 // 5= Emergency! Make target=255
395 unsigned char checkrouterow, checkroutecol, checkroutestart, checkroutedest; // used in checkroute routine
396 unsigned char subpacc,subpacd; // used in subpacman5
397 unsigned char turncount; // used to count the number of turns
398 //unsigned char enemytargetcount; // count of enemy targets on a route
399 unsigned char brokenarrow[4]; // NORTH/SOUTH/EAST/WEST: 0=OK, 1=BROKENARROW, 2=POTENTIAL BROKEN ARROW in that direction
400 unsigned char deadattackers, deaddefenders, deadplayers, deadtoggle; deadcurset; // count of dead attackers or defenders
401 //unsigned char deadchar;
402 unsigned char kingtoedge[4]; // number of TARGETS from king to edge of board
403 unsigned char tzonemode; // 0=PARTIAL1, 1=PARTIAL2, 2=FULL
404 //unsigned char onlycheck; // restrict check to one route in certain situations
405 unsigned char redflag; // raise the red flag to IGNORE "can I be taken"
406 //unsigned char deadcolor; // color of deadpiece
407 //unsigned int deadspace; // start of deadcolumn
408 unsigned char turnlimit; // limit the number of turns (compares to turncount)
409 unsigned char remaining; // number of turns remaining
410 unsigned char huns,thor,odin; // hundreds, tens and units...
411 unsigned char playerlevel; // player level (0=SAGA, 1=THOR, 2=ODIN)
412 unsigned char firstblood; // set to 0, gets changed on a take to signify who gets
413 // first blood award.
414 unsigned char erasetext; // how many lines to erase
415 unsigned char takecounter; // how many pieces were taken in one move
416 unsigned char bottompattern; // draw full line or blank
417 unsigned char Trophies[7][2]; // trophy array [trophytype][playertype]
418 unsigned char TurnsRemaining; // for awarding the RAIDO Trophy (win on last turn)
419 //unsigned char TrophyTitle[12]; // Titles of Trophies
420 unsigned char textchar; // Character of Trophy String
421 //unsigned char TextCursor; // Location of Text string
422 /****************** MAIN PROGRAM ***********************************/
423 main(){
424 //gameinput=0; // 0=undefined 1=play against computer, 2=human vs human
425 /*
426 CopyFont(); //memcpy((unsigned char*)0xb400+32*8,Font_6x8_runic1_full,768);
427 hires();
428 erasetext=120; // 40*3 = 3 lines to erase (used in printmessage)
429 message="V0.072 IN MEMORY OF:\nJONATHAN 'TWILIGHTE' BRISTOW\nORIC LEGEND [1968-2013]";
430 printmessage();
431 setflags(0); // No keyclick, no cursor, no nothing
432 */
433 //printtitles();
434 for(;;){ // endless loop
435 //playertype=0; // 1=attacker, 2=defender (set at zero as incremented within loop)
436 firstblood=1;
437 ClearTrophies(); // initialize trophy array
438 //PrintTrophyScreen();
439 drawboard(); // draw the board
440 while (gamestyle==3){
441 message="PLAYERS:1-2"; // number of players
442 printmessage();
443 gameinput=getchar();
444 if ( gameinput == 49 ) gamestyle=1; // 1=human vs computer (as DEFENDERS)
445 if ( gameinput == 50 ) gamestyle=0; // 0=human vs human
446 if ( gamestyle == 3 ) {flashback=CYAN;flashred();}
447 }
448 // set turnlimits
449 turnlimit=0; turncount=0;
450 while (turnlimit == 0){
451 message="1: 'SAGA' 255 TURNS\n2: 'THOR' 22 TURNS\n3: 'ODIN' 12 TURNS";
452 printmessage();
453 gameinput=getchar();
454 // playerlevel set here, 0=SAGA, 1=THOR, 2=ODIN
455 if ( gameinput == 49 ) {turnlimit=255; playerlevel=SAGA;} // 255 turns
456 if ( gameinput == 50 ) {turnlimit=22; playerlevel=THOR;} // 22 turns
457 if ( gameinput == 51 ) {turnlimit=12; playerlevel=ODIN;} // 12 turns
458 if ( turnlimit == 0 ) {flashback=CYAN;flashred();}
459 }
460 message="\n\nTURN: REMAINING: ";
461 printmessage();
462 erasetext=80; // 40*2 (2 lines to erase)
463 while (game > 0){
464 ns=5; // default north/south position of central square
465 ew=5; // default east/west position of central square
466 cx=ew; // cursor x screen position
467 cy=ns; // cursor y screen position
468 playertype++; // playertype inited as 0 so ++ will make it 1 at start of game
469 if ( playertype == 3 ) {
470 playertype = 1; turncount++; // was defender, set to attacker player, inc turncount
471 if ( turncount > turnlimit ) gamestyle = 9; // signify end of game
472 }
473 //if (( gamestyle == 0 )||((gamestyle==1)&&(playertype==2))||((gamestyle==2)&&(playertype==1)))
474 if ( gamestyle != 9 ){ // if turns not exceeded
475 if (( gamestyle == 0 )||((gamestyle==1)&&(playertype==2))){
476 playerturn(); // player input
477 }else{
478 computerturn(); // computer has a go...
479 }
480 }
481 checkend(); // check for end of game conditions
482 }
483 /*
484 game=0 King Wins.
485 game=-1 Stalemate.
486 game=-2 Attacker wins.
487 */
488 message=" ATTACKER WINS!"; // default (game=-2)
489 // king escapes or all attackers killed
490 if ( game == 0 ) message=" KING WINS!";
491 // computer can't move
492 if ( game == -1 ) message="STALEMATE - OR TURN LIMIT EXCEEDED";
493 // Award RAIDO AND URUZ Trophies (RAIDO = win on last turn, URUZ >=5 turns remaining)
494 if ( game != -1 ){
495 if (TurnsRemaining == 0){
496 Trophies[RAIDO][playertype-1]=TROPHY;
497 }
498 if (TurnsRemaining >= 5){
499 Trophies[URUZ][playertype-1]=TROPHY;
500 }
501 }
502 printmessage();
503 erasetext=120; // 40*3 (3 lines to erase)
504 message="\n *** PRESS A KEY ***";
505 printline();
506 flashon();
507 getchar();
508 PrintTrophyScreen();
509 }
510 }
511
512 /********************* FUNCTION DEFINITIONS ************************/
513 void computerturn(){
514 //char* test2=itoa(turncount);
515 //test2=itoa(turncount);
516 //strcat (message, test2);
517 // test2=itoa(turncount);
518 //message="TURN: ";
519 //strcat(message, test2);
520 //strcat(message, " THINKING...\0");
521 message="ORIC IS THINKING...";
522 //if ( playertype == 1 ) { strcpy(playertext,"ATTACKER");}else{ strcpy(playertext,"KING");}
523 printmessage();
524 printturnline(); // print turn counters
525 // 1. initialize target, enemy and computer array to zeroes
526 ClearArrays(); // clear target, enemy, priority and computer arrays
527 //ClearArrays2(); // clear 1 dimension arrays RowCountAtt, ColCountAtt
528 //prioritycalc(); // calculates the priorities of pieces to move
529 // 2. Loop through players array searching for pieces - calculating where they can go
530 for (fb=4;fb<9;fb++){
531 timertile();
532 for (ctns=0;ctns<11;ctns++){
533 for (ctew=0;ctew<11;ctew++){
534 ns=ctns;ew=ctew;
535 // fb=4 means: don't print destinations, just update ENEMY
536 if (( fb == 4 )&&(( players[ctns][ctew] == DEFENDER )||(players[ctns][ctew] == KING))) printdestinations();
537 // fb=5 (+COMPUTER array):fb=7 (can I be taken)
538 if (((fb == 5)||(fb == 7))&&( players[ctns][ctew] == ATTACKER)) printdestinations();
539 // fb=6 if computer piece can get here update target values
540 if (( fb == 6)&&( computer[ctns][ctew] )) updatetarget();
541 // fb=8 update kingtracker
542 if (( fb == 8)&&( players[ctns][ctew] == KING )) printdestinations();
543 /*if (( fb == 9 )&&( players[ctns][ctew] == ATTACKER)){
544 RowCountAtt[ctns]++;
545 ColCountAtt[ctew]++;
546 }*/
547 }
548 }
549 }
550 // 3. Increment target positions around King (PACMAN)
551 pacman2();
552 calchightarget();
553 if (hightarget == 0) {
554 game=-1; // signify END of game: computer cannot move: stalemate
555 return;
556 }
557
558 if (redflag == NO ) pacman4(); // check for full broken arrow
559 //pacman6(); // "vinegar strokes"
560 // draw central square (overwriting timer)
561 tiletodraw=9; // KING ON A TILE
562 if (players[5][5] != KING) tiletodraw=3; // CASTLE TILE
563 row=5;col=5;
564 DrawPictureTiles();
565 //ptr_graph=PictureTiles;drawtile();
566 //if ( playertype == 1 ) {pacman();}
567 // other routines to go here to update the target array
568 // 4,5,6,7..N etc
569 //
570 targetselect(); // Choose the highest value target and piece to move to it
571 ns=targetns;ew=targetew; // make computer move compatible with human move selection
572 movepiece(); // make the move
573 }
574 void DrawPictureTiles(){
575 ptr_graph=PictureTiles;drawtile();
576
577 }
578
579 void findpiece(){ // find a piece capable of moving to selected target
580 if ( foundpiece == 0 ){
581 if (players[a][b] == ATTACKER){ // a=row, b=column (ns,ew = target location)
582 //foundpiece=1;
583 calccantake2();
584 //cantake=0;
585 //calccantake();
586 //if (( origorient == NORTH ) && ( ns > 1 )) {calccantake();}
587 //if (( origorient == SOUTH ) && ( ns < 9 )) {calccantake();}
588 //if (( origorient == EAST ) && ( ew < 9 )) {calccantake();}
589 //if (( origorient == WEST ) && ( ew > 1 )) {calccantake();}
590 if (( cantake == 0 )&&( surrounded < 3)) canbetaken(); // if cannot take can I be taken?
591 if (compass[origorient] == 0) foundpiece=1;
592 // check NORTH and SOUTH
593 if ((foundpiece == 1)&&(redflag == NO)){ // can't be taken so we've found a candidate
594 if (a != targetns) {// target is not on same row as candidate
595 if ((targetns == kingns)&&((a < 2)||(a > 8))){
596 startrow=a;destrow=a;startcol=0;destcol=10;
597 //see if by moving a piece we leave the way open for the king to escape
598 setcheckmode1(); // set checkroutemode=1 (checkroute will return count of pieces on row or column)
599 checkroute(); // returns z
600 if (z == 1) setfoundpiece10(); // don't move piece (do NOT leave the "zone" unpopulated)
601 }
602 if (a == kingns){ // if candidate is on same row as king (don't move away if only one piece E/W)
603 if ((b > kingew)&&(kingpieces[EAST]==1)) setfoundpiece10();
604 if ((b < kingew)&&(kingpieces[WEST]==1)) setfoundpiece10();
605 }
606 }
607 }
608 // CHECK EAST AND WEST
609 if ((foundpiece == 1)&&(redflag == NO)){ // can't be taken so we've found a candidate
610 if ( b != targetew){// target is not on same column as candidate
611 if ((targetew == kingew)&&((b < 2)||(b > 8))){
612 startrow=0;destrow=10;startcol=b;destcol=b;
613 checkroute(); // returns z
614 if (z == 1) setfoundpiece10(); // don't move piece (do NOT leave the "zone" unpopulated)
615 }
616 if (b == kingew){ // if candidate is on same col as king (don't move away if only one piece N/S)
617 if ((a < kingns)&&(kingpieces[NORTH]==1)) setfoundpiece10();
618 if ((a > kingns)&&(kingpieces[SOUTH]==1)) setfoundpiece10();
619 }
620 }
621 }
622 if (foundpiece == 1){
623 if (origorient < EAST){
624 ons = a;
625 }else{
626 oew = b;
627 }
628 }
629 }
630 if ((players[a][b] == DEFENDER)||(players[a][b] == KING)) foundpiece=9;
631 //if ((players[a][b] == CASTLE)&&(a!=5)) foundpiece=9;
632 }
633 }
634 /*
635 CalcHighTarget used to be part of targetselect (and is still called from it) but
636 it is also now used in PACMAN so that the kings escape route can always be blocked
637 by adding the highest score (so far) onto the necessary targets...
638 It alters the values of ctns,ctew,targetns,targetew,ons,oew,ns,ew and of course,
639 hightarget
640 */
641 void calchightarget(){
642 char nsloop=1;
643 char ewloop=1;
644 unsigned char nsstart=0;
645 unsigned char ewstart=0;
646 unsigned char nsend=10;
647 unsigned char ewend=10;
648 if ( playerlevel == THOR ){
649 nsloop=-1;
650 ewloop=-1;
651 nsstart=10;
652 ewstart=10;
653 nsend=0;
654 ewend=0;
655 }
656 if ( playerlevel == ODIN ){
657 //nsloop=1;
658 ewloop=-1;
659 //nstart=0;
660 //nsend=10;
661 ewstart=10;
662 ewend=0;
663 }
664 hightarget=0; // highest value target
665 for (ctns=nsstart;ctns != nsend; ctns += nsloop){ // find the highest value for target
666 for (ctew=ewstart;ctew != ewend ;ctew += ewloop){
667 if ( target[ctns][ctew] > hightarget ){
668 hightarget=target[ctns][ctew]; // make hightarget the highest value
669 targetns=ctns;
670 targetew=ctew;
671 ons=ctns; // target is accessible so make ons/oew the default piece position to move
672 oew=ctew; // the ACTUAL piece to move determined below (one of ons or oew will remain same)
673 ns=ctns;
674 ew=ctew;
675 }
676 }
677 }
678 /*
679 for (ctns=0;ctns<11;ctns++){ // find the highest value for target
680 for (ctew=0;ctew<11;ctew++){
681 if ( target[ctns][ctew] > hightarget ){
682 hightarget=target[ctns][ctew]; // make hightarget the highest value
683 targetns=ctns;
684 targetew=ctew;
685 ons=ctns; // target is accessible so make ons/oew the default piece position to move
686 oew=ctew; // the ACTUAL piece to move determined below (one of ons or oew will remain same)
687 ns=ctns;
688 ew=ctew;
689 }
690 }
691 }*/
692 }
693 /*
694 void gethightarget(){ // without upsetting anything else
695 hightarget=0;
696 for (ctns=0;ctns<11;ctns++){ // find the highest value for target
697 for (ctew=0;ctew<11;ctew++){
698 if ( target[ctns][ctew] > hightarget ){
699 hightarget=target[ctns][ctew]; // make hightarget the highest value
700 }
701 }
702 }
703 }
704 */
705 /*
706 void cleartarget(){ // nukes target array
707 for (ctns=0;ctns<11;ctns++){
708 for (ctew=0;ctew<11;ctew++){
709 if (target[ctns][ctew]) target[ctns][ctew]=1;
710 }
711 }
712 }
713 */
714 // TARGETSELECT - find the highest scoring TARGET
715 void targetselect(){
716 NEWTARGET:
717 calchightarget();
718 // having found target we need to select a piece to move
719 compass[NORTH]=0;compass[SOUTH]=0;compass[EAST]=0;compass[WEST]=0; // initialize compass array
720 fb=9;
721 if ( playerlevel == ODIN ) goto ODINJUMP2;
722 ODINJUMP1:
723 // NORTH + SOUTH
724 // NORTH
725 origorient=NORTH;
726 if ( foundpiece != 1 ){
727 b=oew;
728 zerofoundpiece(); // set foundpiece to ZERO "piece not found"
729 for (mkey=ons-1; mkey>-1; mkey--){a=mkey;findpiece();}
730 }
731 // SOUTH
732 if ( foundpiece != 1 ){
733 zerofoundpiece();
734 origorient=SOUTH;
735 for (mkey=ons+1; mkey<11; mkey++) {a=mkey;findpiece();}
736 }
737 if ( playerlevel == ODIN ) goto ODINJUMP3;
738 ODINJUMP2:
739 // EAST + WEST
740 // EAST
741 if ( foundpiece != 1 ){
742 a=ons;
743 zerofoundpiece();
744 origorient=EAST;
745 for (mkey=oew+1; mkey<11; mkey++) {b=mkey;findpiece();}
746 }
747 // WEST
748 if ( foundpiece != 1 ) {
749 zerofoundpiece();
750 origorient=WEST;
751 for (mkey=oew-1; mkey>-1; mkey--) {b=mkey;findpiece();}
752 }
753 if ( playerlevel == ODIN ) goto ODINJUMP1;
754 ODINJUMP3:
755 if ( foundpiece != 1 ) {target[targetns][targetew]=1;goto NEWTARGET;} // if can still be taken select new target
756 //if ( target[targetns][targetew]==2) {zoneupdate(); goto NEWTARGET;} // if nothing useful found update the zone
757 cx=oew; // piece x screen position
758 cy=ons; // piece y screen position
759 blinkcursor(); // draw cursor in foreground color at piece to move position cx,cy
760 fb=0;
761 //drawcursor(); // blank cursor
762 cx=targetew; // target x screen position
763 cy=targetns; // target y screen position
764 blinkcursor(); // draw cursor in foreground color at target position cx,cy
765 ocx=oew; // piece to move x screen position
766 ocy=ons; // piece to move y screen position
767 }
768 // subroutine of pacman
769 void subpacmanx(){
770 setpoints(); // Set points to 10
771 surroundpoints(); // add 10 * surrounded
772 /*
773 if (kingpieces[orientation] == 0){
774 incpoints();
775 if ((orientation<EAST)&&((kingew<2)||(kingew>8))) pointsplusten();
776 if ((orientation>SOUTH)&&((kingns<2)||(kingns>8))) pointsplusten();
777 }
778 */
779 // TRIGGERHIGH/TRIGGERLOW = Weight to be added depending on kings closeness to border
780 /*
781 if (( orientation == NORTH )&&(kingns <= TRIGGERLOW)) pointsplusten();
782 if (( orientation == SOUTH )&&(kingns >= TRIGGERHIGH)) pointsplusten();
783 if (( orientation == EAST ) &&(kingew >= TRIGGERHIGH)) pointsplusten();
784 if (( orientation == WEST ) &&(kingew <= TRIGGERLOW)) pointsplusten();
785 */
786 points+=brokenarrow[orientation]*10;
787 //message="NOT SET";
788
789 if (( kingpieces[orientation] == 0 )&&(kingtoedge[orientation])){
790 //calchightarget();
791 if ((orientation < EAST)&&((kingew<2)||(kingew>8))) {
792 redflag=YES; // raise a red flag
793 points=200;
794 }
795 if ((orientation > SOUTH)&&((kingns<2)||(kingns>8))) {
796 redflag=YES; // raise a red flag
797 points=200;
798 }
799 }
800
801 subpacmany(); // apply the points
802 }
803 void subpacmany(){ // apply the points generated in pacman2-6
804 // SET UNCOUNTER
805 pacman5(); // ensure correct paclevels are set
806 uncounter=paclevel2+1; // if south or east
807 if ((orientation == NORTH ) || ( orientation == WEST)){
808 uncounter=paclevel2-1;
809 }
810 // SET X & Y
811 x=paclevel1; // if EAST or WEST
812 y=uncounter;
813 if ( orientation < EAST ){ // IF NORTH OR SOUTH
814 x=uncounter;
815 y=paclevel1;
816 }
817
818 while (((players[x][y] == 0)||(tiles[x][y] == CASTLE)) && ((uncounter > -1)&&(uncounter < 11))){
819 if ( target[x][y] ){ // if accessible by attacker
820 if (( target[x][y] > 1 )||(redflag)){
821 //printmessage();getchar();
822 target[x][y]+=points;
823 }else{
824 target[x][y]=points; // can be caught if i go here
825 if (redflag) target[x][y]-=50; // take another 50 points if redflag=yes
826 }
827 decpoints();
828 }
829 //if (z){decpoints();} // only decrement points if route to edge is blocked
830 if ( (orientation == NORTH) || (orientation == WEST) ) {uncounter--;}else{uncounter++;}
831 if ( orientation < EAST ) {x=uncounter;}else{y=uncounter;}
832 }
833 /*
834 if (tzonemode==VINEGAR){
835 message="VINEGAR STROKES COMPLETE";
836 printmessage();
837 }*/
838 }
839 void checkbrokenarrow(){
840 // f= value of player piece at edge of board (if any)
841 // kingtoedge[orientation]= count of targets from king to edge
842 // kingpieces[]= count of pieces from king in a given orientation
843 unsigned char test=0;
844 //unsigned char testreturn=0;
845 setcheckmode1(); c=checkroute(); // how many pieces on the route?
846 checkroutemode=6; d=checkroute();// can king get to a T-row 0-1
847 if (( c == 0 ) && ( d )) {
848 f=players[a][b]; // check for piece at edge of board
849 if (f == CASTLE) f=0; // check for corner square
850 if (( target[a][b] )&&(tzonemode==FULL)) kingtoedge[orientation]--; // decrement kingtoedge(so maybe kingtoedge=zero) - to trigger brokenarrow
851 //if (( kingpieces[orientation] == 1) && (f) && (f != ATTACKER)) test=1;
852 if (( kingpieces[orientation] == 1) && (f)) test=1;
853 if ((kingpieces[orientation] == 0 )||( test )){
854 if ( kingtoedge[orientation] == 0){ // no targets on route to edge
855 checkroutemode=5;checkroute(); // add points to t-zone targets (startrow, startcol,destrow, destcol)
856 }else{
857 brokenarrow[orientation]++; // POTENTIAL BROKEN ARROW
858 if (tzonemode){ // if tzonemode > PARTIAL1
859 brokenarrow[orientation]+=2; // will be at LEAST 3 if PARTIAL2
860 }
861 // if we have two PARTIAL1s (possible escape) then brokenarrow will be 2 so need to elevate
862 if (brokenarrow[orientation] == 2) brokenarrow[orientation]=4; // 4 beats one PARTIAL2
863 }
864 }
865 }
866 }
867
868 /*
869 // check the T zone (for broken arrow purposes)
870 unsigned char subpaccrosst(){
871 if ( orientation == NORTH ){
872 a=0;b=kingew;startrow=1;destrow=1;startcol=0;destcol=10;
873 }
874 if ( orientation == SOUTH ){
875 a=10;b=kingew;startrow=9;destrow=9;startcol=0;destcol=10;
876 }
877 if ( orientation == EAST ){
878 a=kingns;b=10;startrow=0;destrow=10;startcol=9;destcol=9;
879 }
880 if ( orientation == WEST ){
881 a=kingns;b=0;startrow=0;destrow=10;startcol=1;destcol=1;
882 }
883 return checkroute();
884 }
885 */
886 void gspot(){
887 setcheckmode3(); // count number of targets on route from king to edge
888 // NORTH
889 startrow=0;destrow=kingns;startcol=kingew;destcol=kingew;
890 kingtoedge[NORTH]=checkroute(); // count of targets from king to edge
891 // SOUTH
892 startrow=kingns;destrow=10;
893 kingtoedge[SOUTH]=checkroute(); // count of targets from king to edge
894 // EAST
895 destrow=kingns;destcol=10;
896 kingtoedge[EAST]=checkroute();
897 // WEST
898 startcol=0;destcol=kingew;
899 kingtoedge[WEST]=checkroute();
900 }
901 /*
902 void gspot(){
903 // default=NORTH
904 if (( orientation == NORTH )&&(kingns > 1)) {
905 startrow=0;destrow=kingns;startcol=kingew;destcol=kingew;
906 }
907 if (( orientation == SOUTH )&&(kingns < 9)){
908 startrow=kingns;destrow=10;startcol=kingew;destcol=kingew;
909 }
910 if ((orientation == EAST )&&(kingew < 9)){
911 startrow=kingns;destrow=kingns;startcol=kingew;destcol=10;
912 }
913 if ((orientation == WEST) && (kingew > 1)){
914 startrow=kingns;destrow=kingns;startcol=0;destcol=kingew;
915 }
916 setcheckmode3(); g=checkroute(); // count of targets from king to edge
917 }
918 */
919 /*
920 void checkbrokenarrowhead(){
921 // NORTH
922 orientation=NORTH; brokenarrow[orientation]=0;
923 a=0;b=kingew;startrow=0;destrow=0;startcol=0;destcol=kingew;
924 checkbrokenarrow(); // PARTIAL LEVEL 1 "LEFT"
925 startcol=kingew;destcol=10;
926 checkbrokenarrow(); // PARTIAL LEVEL 1 "RIGHT"
927 // SOUTH
928 orientation=SOUTH; brokenarrow[orientation]=0;
929 a=10;startrow=10;destrow=10;startcol=0;destcol=kingew;
930 checkbrokenarrow(); // PARTIAL LEVEL 1 "LEFT"
931 startcol=kingew;destcol=10;
932 checkbrokenarrow(); // PARTIAL LEVEL 1 "RIGHT"
933 // EAST
934 orientation=EAST; brokenarrow[orientation]=0;
935 a=kingns;b=10;startrow=0; destrow=kingns;startcol=10;
936 checkbrokenarrow(); // PARTIAL LEVEL 1 "LEFT"
937 startrow=kingns;destrow=10;
938 checkbrokenarrow(); // PARTIAL LEVEL 1 "RIGHT"
939 // WEST
940 orientation=WEST; brokenarrow[orientation]=0;
941 b=0; startrow=0;destrow=kingns;startcol=0; destcol=0;
942 checkbrokenarrow(); // PARTIAL LEVEL 1 "LEFT"
943 startrow=kingns;destrow=10;
944 checkbrokenarrow(); // PARTIAL LEVEL 1 "RIGHT"
945 }*/
946
947 void pacman2(){
948 // improved version of pacman
949 redflag=NO; // at this point no red flag to be waived
950 timertile();
951 //calchightarget(); // calc highest target so far
952 //if (hightarget == 0) return; // cannot move...
953 gspot(); // sets kingtoedge[orientation]=count of targets from king to edge (no of pieces is found in kingpieces[])
954 //checkbrokenarrowhead();
955 surroundcount(); // set surrounded value (used in subpacmanx - only have to calc once though)
956 for (orientation = 0; orientation < 4; orientation++){
957 brokenarrow[orientation]=0;
958 tzonemode=PARTIAL1;
959 // count of pieces across the "T"
960 // PARTIAL LEVEL 1 "LEFT"
961 //points=50; // for level 1
962 a=0;b=kingew;startrow=0;destrow=0;startcol=0;destcol=kingew; // NORTH
963 if ( orientation ){
964 a=10;b=kingew;startrow=10;destrow=10;startcol=0;destcol=kingew; // SOUTH
965 if ( orientation == EAST ){
966 a=kingns;b=10;startrow=0; destrow=kingns;startcol=10;destcol=10;
967 }
968 if ( orientation == WEST ){
969 a=kingns;b=0; startrow=0; destrow=kingns;startcol=0; destcol=0;
970 }
971 }
972 pacman3();
973 // PARTIAL LEVEL 1 "RIGHT"
974 if (startrow == destrow){
975 startcol=kingew;destcol=10;
976 }else{
977 startrow=kingns;destrow=10;
978 }
979 pacman3();
980 // LEVEL 2
981 // PARTIAL LEVEL 2 "LEFT"
982 // a + b already set in PARTIAL LEVEL 1
983 tzonemode=PARTIAL2;
984 startrow=1;destrow=1;startcol=0;destcol=kingew; // NORTH
985 if ( orientation ){
986 startrow=9;destrow=9;startcol=0;destcol=kingew; // SOUTH
987 if ( orientation == EAST ){
988 startrow=0; destrow=kingns;startcol=9;destcol=9;
989 }
990 if ( orientation == WEST ){
991 startrow=0; destrow=kingns;startcol=1; destcol=1;
992 }
993 }
994 //points = 100;
995 pacman3();
996 // PARTIAL LEVEL 2 "RIGHT"
997 if (startrow == destrow){
998 startcol=kingew;destcol=10;
999 }else{
1000 startrow=kingns;destrow=10;
1001 }
1002 pacman3();
1003 subpacmanx(); // add points to target in all directions from king
1004 }
1005 }
1006 void pacman3(){
1007 //unsigned char test=0;
1008 unsigned char lower=0; // row/column lower bound
1009 unsigned char upper=10; // row/column upper bound
1010 pacman5(); // ensure correct paclevels are set
1011 if (tzonemode){ // if PARTIAL2 or FULL
1012 lower=1;
1013 upper=9;
1014 }
1015 if ((( orientation == NORTH )||( orientation == WEST ))&&(paclevel2 > lower)) checkbrokenarrow();
1016 if ((( orientation == SOUTH )||( orientation == EAST ))&&(paclevel2 < upper)) checkbrokenarrow();
1017 //if ((paclevel1 > 0 )&&(paclevel1 < 10)) test++;
1018 //if ( test==2 ) checkbrokenarrow();
1019 }
1020 void pacman4(){
1021 // Cross the "T", see if a FULL broken arrow condition could exist (LEVEL 2)
1022 // FULL LEVEL 2
1023 tzonemode=FULL;
1024 points=hightarget+1;
1025 orientation = NORTH;
1026 //pacman5(); // NORTH+SOUTH
1027 a=0;b=kingew;startrow=1;destrow=1;startcol=0;destcol=10;
1028 pacman3();
1029 orientation = SOUTH; // SOUTH
1030 a=10;b=kingew;startrow=9;destrow=9;startcol=0;destcol=10;
1031 pacman3();
1032 orientation = EAST; // EAST
1033 //pacman5();
1034 a=kingns;b=10;startrow=0;destrow=10;startcol=9;destcol=9;
1035 pacman3();
1036 orientation = WEST; // WEST
1037 a=kingns;b=0;startrow=0;destrow=10;startcol=1;destcol=1;
1038 pacman3();
1039 }
1040 void pacman5(){
1041 if (orientation < EAST){ // NORTH AND SOUTH (for pacman3)
1042 paclevel1=kingew;
1043 paclevel2=kingns;
1044 }else{ // EAST AND WEST
1045 paclevel1=kingns;
1046 paclevel2=kingew;
1047 }
1048 }
1049
1050 // check for endgame conditions
1051 void checkend() {
1052 /* END OF GAME CONDITIONS
1053 game=0 King Wins.
1054 game=-1 Stalemate. (or turnlimit exceeded)
1055 game=-2 Attacker wins.
1056 */
1057 // ns and ew contains new board co-ords of last piece moved
1058 if ((( players[ns][ew] == 3 ) && ( tiles[ns][ew] == 4 ))||( deadattackers > 23)) game=0; // king has escaped
1059 // check to see if king is surrounded by attackers (first find king)
1060 if ( players[ns][ew] == 1 ){ // if attacker was last to move
1061 if ((ns )&&(players[ns-1][ew] == 3 )) surroundcount();
1062 if ((ns < 10 )&&(players[ns+1][ew] == 3 )) surroundcount();
1063 if ((ew < 10 )&&(players[ns][ew+1] == 3 )) surroundcount();
1064 if ((ew )&&(players[ns][ew-1] == 3 )) surroundcount();
1065 if ( surrounded == 4 ) game=-2; // king is surrounded on all sides by attackers or king squares
1066 }
1067 if ( gamestyle == 9 ) game=-1; // turnlimit exceeded: stalemate
1068 }
1069
1070 void cursormodezero() {
1071 if ( cursormode == 0 ) canmovecursor=1;
1072 }
1073
1074
1075 // routine to move the cursor
1076 void movecursor2() {
1077 /*
1078 cursormode = [0 or 1] 0=unrestricted (move anywhere), 1= restricted (only move to possible destinations)
1079 */
1080 multiple=1; // concerning central square (how much to multiply the coords to SKIP the square
1081 xptrns=ns; // copy of NS
1082 xptrew=ew; // copy of EW
1083 skipns=ns; // skip to north/south
1084 skipew=ew; // skip to east/west
1085 modeonevalid=0; // is OK for mode 1? 0=no, 1=yes
1086 canmovecursor=0;
1087 piecetype=players[ons][oew]; // determines the piece type that is currently selected (used in mode 1)
1088 if ((mkey == 8 )&&( ew )){ // west
1089 cursormodezero();
1090 xptrew--; // decrement copyew
1091 skipew-=2;
1092 incmodeone();
1093 }
1094 if ((mkey == 9 )&&( ew < 10)) { // east
1095 cursormodezero();
1096 xptrew++;
1097 skipew+=2;
1098 incmodeone();
1099 }
1100 if ((mkey == 10)&&( ns < 10)){ // south
1101 cursormodezero();
1102 xptrns++;
1103 skipns+=2;
1104 incmodeone();
1105 }
1106 if ((mkey == 11)&&( ns )){ // north
1107 cursormodezero();
1108 xptrns--;
1109 skipns-=2;
1110 incmodeone();
1111 }
1112 if (( cursormode ) && ( modeonevalid )){ // if not at edge of board
1113 if ( players[xptrns][xptrew] == 0 ) canmovecursor=1; // ok if square vacant
1114 if ( tiles[xptrns][xptrew] == 4 ) canmovecursor=0; // !ok if corner
1115 if (( piecetype == 3 )&&( tiles[xptrns][xptrew] > 2 )) canmovecursor=1; // ok if KING and corner/central
1116 if (( xptrns == ons )&&( xptrew == oew )) canmovecursor=1; // ok if back to self
1117 // need to check that for non-king pieces wether the central square is vacant and can be skipped
1118 if (( piecetype < 3 )&&( tiles[xptrns][xptrew] == 3)&&(players[xptrns][xptrew] !=3 )){ // tiles=3(central), tiles=4(corner)
1119 if ( players[skipns][skipew] ) canmovecursor=0; // cannot skip if otherside occupied
1120 if ((( skipns == ons )&&( skipew == oew ))||( players[skipns][skipew] == 0)){ // ok to skip to self
1121 canmovecursor=1;
1122 multiple=2;
1123 }
1124 }
1125 }
1126 if (canmovecursor ){
1127 fb=0;
1128 //inversex=cx;
1129 //inversey=cy;
1130 //drawcursor();
1131 inverse(); // print blank cursor (effect=remove dots)
1132 if ( mkey == 8 ) cx-=multiple; // left
1133 if ( mkey == 9 ) cx+=multiple; // right
1134 if ( mkey == 10 )cy+=multiple; // down
1135 if ( mkey == 11 )cy-=multiple; // up
1136
1137 fb=1;
1138 //inversex=cx;
1139 //inversey=cy;
1140 //drawcursor(); // print dotted cursor
1141 inverse();
1142 if ( mkey == 8 ) ew-=multiple; // left
1143 if ( mkey == 9 ) ew+=multiple; // right
1144 if ( mkey == 10 )ns+=multiple; // down
1145 if ( mkey == 11 )ns-=multiple; // up
1146 }
1147 else{
1148 if ( cursormode == 0 ) {flashback=CYAN;flashred();printturnline();} // flash red: return to cyan:6
1149 if ( cursormode == 1 ) {flashback=GREEN;flashred();printturnline();} // flash red: return to green:2, yellow=3)
1150 }
1151 }
1152
1153
1154 // kicks off functions that print appropriate arrows at all possible
1155 // destinations and blanks them out afterwards
1156 void printpossiblemoves(){
1157 char k; // key entered
1158 fb=1;
1159 printdestinations(); // print arrows on all destinations
1160 message="\n *** PRESS ANY KEY ***";
1161 printmessage();
1162 flashon();
1163 printturnline();
1164 k=getchar();
1165 fb=0;
1166 printdestinations(); // blank out arrows on all destinations
1167 }
1168
1169 // used in printdestinations
1170 void backbone() {
1171 origorient=orientation; // original orientation (for computer turn)
1172 xns=ns; // copy of ns
1173 xew=ew; // copy of ew
1174 arrow=1;
1175 // orientation 0,1,2,3 = N, S, E, W
1176 takerow=ns;takecol=ew; // will set below to be the opposite of the orientation
1177 if ( orientation == NORTH ) { xplayers=players[xns-1][xew];takerow=xns+1;} // check north
1178 if ( orientation == SOUTH ) { xplayers=players[xns+1][xew];takerow=xns-1;} // check south
1179 if ( orientation == EAST ) { xplayers=players[xns][xew+1];takecol=xew-1;} // check east
1180 if ( orientation == WEST ) { xplayers=players[xns][xew-1];takecol=xew+1;} // check west
1181 while (( arrow )&&(fb != 7)){ // keep checking until cannot move
1182 if (( orientation == NORTH ) && ( xns )){ // check north
1183 xns--; // decrement provisional north-south player position
1184 subarrows();
1185 }
1186 if (( orientation == SOUTH ) && ( xns < 10 )){ // check south
1187 xns++; // increment provisional north-south player position
1188 subarrows();
1189 }
1190 if ((orientation == EAST ) && ( xew < 10 )){ // check east
1191 xew++; // increment provisional east-west player position
1192 subarrows();
1193 }
1194 if ((orientation == WEST ) && ( xew )){ // check west
1195 xew--; // decrement provisional east-west player position
1196 subarrows();
1197 }
1198 tiletodraw=tiles[xns][xew]; // obtain type of tile
1199 if ( arrow ){ // if MODE is "draw an arrow" (aka: I can move here) arrow=1 or 2
1200 // NOTE: arrow=2 means piece can cross this square but not occupy it as in case with CASTLE squares
1201 row=xns;
1202 col=xew;
1203 if ( arrow == 1 ){ // don't draw the arrow or update any array if arrow=2
1204 if (fb == 1) drawarrow(); // draw arrow
1205 if (fb == 4) subarrows2(); // enemy can get here, update enemy array (direction specific)
1206 if (fb == 5) computer[xns][xew]++;// computer can get here, increment computer array and set default target value
1207 if (fb == 0) drawarrow(); // if MODE is "blank an arrow"
1208 if (fb == 8) kingtracker[xns][xew]=1; // king can get here...
1209 }
1210 }
1211 // have we reached the end of the board?
1212 if (( orientation == NORTH ) && ( xns == 0 )) zeroarrow(); // check north
1213 if (( orientation == SOUTH ) && ( xns == 10 )) zeroarrow(); // check south
1214 if (( orientation == EAST ) && ( xew == 10 )) zeroarrow(); // check east
1215 if (( orientation == WEST ) && ( xew == 0 )) zeroarrow(); // check west
1216 }
1217 if ((fb == 7)&&(xplayers > ATTACKER)){ // check to see if an attacker can be caught if he stays where he is
1218 if ((players[takerow][takecol] == 0)&&(enemy[takerow][takecol] )) {
1219 a=takerow;b=takecol;sidestep();
1220 if (orientation < EAST){ // if heading north or south
1221 a=xns;
1222 if ( xew < 10 ) {b=xew+1;sidestep();}
1223 if ( xew ) {b=xew-1;sidestep();}
1224 }
1225 else{ // if heading east or west
1226 b=xew;
1227 if ( xns < 10 ) {a=xns+1;sidestep();}
1228 if ( xns ) {a=xns-1;sidestep();}
1229 }
1230 }
1231 }
1232 }
1233 // sidestep: take a step sideways if you can be caught where you are...
1234 void sidestep(){
1235 if (target[a][b] > 1) target[a][b]+=SIDESTEP;
1236 }
1237
1238 // Multi function depending on value of "fb"
1239 void printdestinations(){
1240 // check north
1241 if ( ns ) { orientation=NORTH;backbone();}
1242 // check south
1243 if ( ns < 10 ){ orientation=SOUTH;backbone();}
1244 // check east
1245 if ( ew < 10 ){ orientation=EAST;backbone();}
1246 // check west
1247 if ( ew ) { orientation=WEST;backbone();}
1248 }
1249
1250
1251 // CAN A SELECTED PIECE MOVE?
1252 void canpiecemove() {
1253 // returns 0 or 1 depending on wether a piece can move or not
1254 route=0;
1255 piecetype=players[ns][ew]; // determine TYPE of selected piece (1=attacker, 2=defendr, 3=king)
1256 /* for all piece types determine if adjacent square in any direction is blank or not
1257 it won't bother checking a particular direction if piece is at edge of board.
1258 */
1259 if ( ns ){ // check north
1260 a=ns-1;b=ew;checkincroute();
1261 }
1262 if ( ns < 10 ){ // check south
1263 a=ns+1;b=ew;checkincroute();
1264 }
1265 if ( ew < 10 ){ // check east
1266 a=ns;b=ew+1;checkincroute();
1267 }
1268 if ( ew ){ // check west
1269 a=ns;b=ew-1;checkincroute();
1270 }
1271 /* In the case that the central square is unnocupied and a piece is adjacent to that square then - for
1272 non-KING Pieces only - we need to check to see if the opposite square is occupied or not.
1273 ROUTE will be decremented if that piece is occupied (as no piece can occupy the central square except for
1274 the King but all pieces can traverse it */
1275 if (( piecetype < 3 ) && ( players[5][5] == 4 )){ // if not a king and central sqr unoccupied
1276 if ( ns == 5 ) {
1277 if ( ew == 4 ) {if ( players[5][6] ) decroute();} // check east +2 // east occupied, dec route
1278 if ( ew == 6 ) {if ( players[5][4] ) decroute();} // check west +2 // west occupied, dec route
1279 }
1280 if ( ew == 5 ){
1281 if ( ns == 4 ) { if ( players[6][5] ) decroute();} // check south +2 // south occupied, dec route
1282 if ( ns == 6 ) { if ( players[4][5] ) decroute();} // check north +2 // north occupied, dec route
1283 }
1284 }
1285 if ( route ) route=1;
1286 //return route;
1287 }
1288
1289
1290 void checkincroute(){
1291 if ( players[a][b] == 0 ) incroute();
1292 if ( (a == 5) && (b == 5) && (players[a][b] == 4)) incroute();
1293 if (( piecetype == 3 )&&(tiles[a][b] == 4 )) incroute(); // KING: corner square OK
1294 }
1295
1296
1297 // DRAW ALL THE PIECES ON THE BOARD
1298 void drawplayers() {
1299 for (row=0;row<11;row++){
1300 for (col=0;col<11;col++){
1301 if (( players[row][col] )&&(players[row][col] < 4)) drawpiece();
1302 }
1303 }
1304 }
1305 // update the deadpile
1306 void deadpile(){
1307 if (playertype == 1){ // IF ATTACKERS TURN THEN INC DEADEFENDERS "("
1308 if ( deadtoggle ) deaddefenders++;
1309 deadplayers=deaddefenders;
1310 deadcurset=0xa027;
1311 }else{ // IF DEFENDERS TURN THEN INC DEADATTACKERS ")"
1312 if ( deadtoggle ) deadattackers++;
1313 deadplayers=deadattackers;
1314 deadcurset=0xa025;
1315 }
1316 for (x=0;x<deadplayers;x++){
1317 //if ( deadtoggle == 0 ) deadchar=0x9800+(32*8); // space
1318 chasm();
1319 //deadcurset+=(40*9);
1320 deadcurset+=(40*8); // 40*8
1321 //curset(deadcurset,x*8,0);
1322 //hchar(deadchar,0,deadtoggle);
1323 }
1324 //}
1325
1326 }
1327
1328 // DRAW THE BOARD
1329 void drawboard(){
1330 inkcolor=6;inkasm();
1331 deadtoggle=0; // ensure deadpile char=space
1332 playertype=1;deadpile(); // clear the deadpile of defenders
1333 playertype=2;deadpile(); // clear the deadpile of attackers
1334 deadattackers=0;deaddefenders=0; // reset deadpile counts
1335 game=1; // game=1 means PLAY GAME
1336 gamestyle=3; // 0=play against human, 1=play as DEFENDERS, 2=play as ATTACKERS, 3=nobody
1337 kingns=5;kingew=5; // DEFAULT kings board position
1338 kingattacker[NORTH]=2; // count of attackers NORTH of king
1339 kingattacker[SOUTH]=2; // count of attackers SOUTH of king
1340 kingattacker[EAST]=2; // count of attackers EAST of king
1341 kingattacker[WEST]=2; // count of attackers WEST of king
1342 kingdefender[NORTH]=2; // count of defenders NORTH of king
1343 kingdefender[SOUTH]=2; // count of defenders SOUTH of king
1344 kingdefender[EAST]=2; // count of defenders EAST of king
1345 kingdefender[WEST]=2; // count of defenders WEST of king
1346 surrounded=0; // reset surrounded back to zero
1347 drawtiles(); // draw the background tiles
1348 //curset(12,198,1);
1349 //draw(198,0,1);
1350 bottompattern=63; drawbottom();
1351 drawedge(); // far right of board
1352 //draw(0,-198,1);
1353 drawplayers(); // draw the players
1354 deadatt(); // set dead colors attackers
1355 deaddef(); // set dead colors defenders
1356
1357 }
1358
1359
1360 // blinks the cursor a number of times to attract attention
1361 void blinkcursor() {
1362 //inversex=cx;
1363 //inversey=cy;
1364 for (counter=0;counter<5;inccounter()){ // flash the cursor to draw attention to it
1365 fb=0;
1366 //drawcursor(); // draw cursor in background color at cx,cy
1367 inverse();
1368 pausetime=500;pause();
1369 inverse();
1370 fb=1;
1371 //drawcursor(); // draw cursor in foreground color at cx,cy
1372 pausetime=1000;pause();
1373 }
1374 if ((cx==5)&&(cy==5)) inverse();
1375 }
1376 // flashes the screen in the selected ink color
1377 void flashscreen() {
1378 inkcolor=flashcolor;inkasm();
1379 pausetime=1500;pause();
1380 inkcolor=flashback;inkasm();
1381 }
1382 // The human players turn : filter keyboard input
1383 void playerturn(){
1384 /*
1385 unsigned char key; // code of key pressed
1386 unsigned char canselect; // 0=no, 1=yes (is the piece selectable?)
1387 char cursormovetype=-1; // -1=no, 0=yes (n,s,e,w) 1=(north/south only), 2=(east/west only)
1388 char turn=1; // determines end of player turn 1=playerturn, 0=end of playerturn
1389 */
1390 cursormovetype=-1; // -1=no, 0=yes (n,s,e,w) 1=(north/south only), 2=(east/west only)
1391 turn=1; // determines end of player turn 1=playerturn, 0=end of playerturn
1392 ons=ns; // original ns board position
1393 oew=ew; // original ew board position
1394 ocx=cx; // original x screen position
1395 ocy=cy; // original y screen position
1396 flashback=CYAN;
1397 playertext="ATTACKER'S";
1398 if ( playertype == 2 ) playertext="KING'S";
1399 /*
1400 if ( playertype == 2 ){
1401 playertext="KING'S";
1402 }
1403 else{
1404 playertext="ATTACKER";
1405 }
1406 */
1407 blinkcursor();
1408 printturnprompt(); // display instructions
1409 // print number of turns and remaining turns
1410 printturnline();
1411 while (turn){ // repeat until move is made
1412 xkey=getchar(); // get code of pressed key
1413 mkey=xkey;
1414 if (( xkey > 7 ) && ( xkey < 12 )){ // 8-11 = cursor keys
1415 cursormode=0; // freeform
1416 movecursor2();
1417 }
1418 /*******************************************************/
1419 /* determine if X or P is selected (to select a piece) */
1420 /*******************************************************/
1421 if (( xkey == 88) || ( xkey == 80)){ // if 'X' or 'P' is selected (88=X, 80=P)
1422 canselect=0; // set piece to NOT SELECTABLE
1423 if (( playertype == 1 )&&(players[ns][ew] == 1 )) canselect=1; // piece is selectable
1424 if (( playertype == 2 )&&((players[ns][ew] == 2 )||(players[ns][ew] == 3))) canselect=1;// piece is selectable
1425 if ( canselect ){
1426 canpiecemove();
1427 if (route ) {
1428 flashcolor=GREEN;flashscreen(); // flash 2=green, 3=yellow
1429 if ( xkey == 80 ){ // if P is pressed
1430 printpossiblemoves(); // Print possible moves
1431 printturnprompt();
1432 printturnline();
1433 }
1434 }
1435 else {
1436 flashred();
1437 canselect=0; // unselectable, cannot move
1438 }
1439 }
1440 else {
1441 flashred();
1442 }
1443 if (( mkey == 88 )&&( canselect )){ // if piece is SELECTED and CAN move
1444 inkcolor=GREEN;inkasm(); // 2=green, 3=yellow to indicate piece is selected
1445 flashback=GREEN;
1446 inverse2();
1447 //printmessage();
1448 //strcpy(message,playertext);
1449 message="PLACE CURSOR ON DESTINATION\nX:SELECT SQUARE R:RESET";
1450 printmessage();
1451 printturnline();
1452 //printf("\n\n\n%s Turn X=Select R=Reset",playertext);
1453 //inversex=cx;
1454 //inversey=cy;
1455 //inverse(); // highlight selected square (inverse color)
1456 mkey=0; // ensure mkey at known value
1457 // set Original cursor and board position of selected square
1458 ocx=cx; ocy=cy; ons=ns; oew=ew;
1459 while (( mkey != 88 ) && ( mkey != 82)){ // move cursor until X or R selected
1460 if (( ons == ns )&&( cursormovetype < 0)) cursormovetype=1; // cursor allowed north-south
1461 if (( oew == ew )&&( cursormovetype < 0)) cursormovetype=2; // cursor allowed east-west
1462 if (( ons == ns )&& (oew == ew )) cursormovetype=0; // cursor can move
1463 if (( cursormovetype == 2) && (( mkey == 8) ||(mkey == 9))) cursormovetype=-1; //!move
1464 if (( cursormovetype == 1) && (( mkey == 10)||(mkey == 11)))cursormovetype=-1; //!move
1465 if (( cursormovetype == 0) && (( mkey == 8) ||(mkey == 9))) cursormovetype=1; //move
1466 if (( cursormovetype == 0) && (( mkey == 10)||(mkey == 11)))cursormovetype=2; //move
1467 if ( cursormovetype > 0 ) {
1468 cursormode=1; // restricted
1469 movecursor2();
1470 }
1471 if ( cursormovetype < 0) { flashred();} // flashscreen red
1472 mkey=getchar();
1473 }
1474 if ( mkey == 82 ){ // R has been selected, Reset cursor to original positions
1475 fb=0;
1476 //drawcursor(); // blank out cursor at current position
1477 //inversex=cx;
1478 //inversey=cy;
1479 inverse();
1480 cx=ocx; // reset coords and board values to original positions
1481 cy=ocy;
1482 ns=ons;
1483 ew=oew;
1484 //inversex=cx;
1485 //inversey=cy;
1486 fb=1;
1487 //drawcursor(); // draw cursor at original selected position
1488 inverse2();
1489 inverse(); // inverse square
1490 }
1491 if ( mkey == 88 ){ // if X selected
1492 //inversex=ocx;
1493 //inversey=ocy;
1494 inverse(); // inverse original position
1495 // X is in original position so return to cursor movement
1496
1497 if (( ons == ns )&&( oew == ew)){
1498 inverse2();
1499 inverse();
1500 mkey=0; // piece de-selected
1501 }
1502 else{
1503 movepiece(); // move selected piece
1504 turn=0; // player has ended turn
1505 }
1506
1507 }
1508 }
1509 inkcolor=CYAN;inkasm(); // back to cyan
1510 flashback=CYAN;
1511 printturnprompt();
1512 printturnline();
1513 } // key = X or P
1514 } // While player turn
1515 }
1516
1517
1518 // Moves selected piece to new location - updating board arrays and re-drawing tiles where necessary
1519 void movepiece(){
1520 p1=ATTACKER; // piece type comparison (lower) - used for determining takes - default=attacker
1521 p2=CASTLE; // piece type comparison (upper) - used for determining takes - default=attacker
1522 piecetype=players[ons][oew]; // obtain type of piece
1523 // move piece
1524 fb=0;
1525 //drawcursor(); // blank out cursor at new selected position
1526 row=ons;
1527 col=oew;
1528 tiletodraw=tiles[ons][oew];
1529 DrawPictureTiles(); //draw tile at original location (blank out square)
1530 players[ons][oew]=0; //set original location to zero (unnocupied)
1531 players[ns][ew]=piecetype; //update square with player info
1532 // row, col required for drawpiece function
1533 row=ns;
1534 col=ew;
1535 drawpiece(); // draw piece at new location - 18-10-2011
1536 if (piecetype == KING){ // update king position (used by AI)
1537 kingns=ns;kingew=ew;
1538 if ((kingns != 5)||(kingew != 5)) {
1539 players[5][5]=CASTLE; // set central square to be 4 so it can be used in takes
1540 tiletodraw=3; row=5;col=5;
1541 DrawPictureTiles(); // draw central square
1542 }
1543 }
1544 // having moved piece we now need to check for, and implement any TAKES
1545 if (piecetype > ATTACKER ){ // if defender
1546 p1=DEFENDER;
1547 p2=KING;
1548 }
1549 tpew=ew;
1550 takecounter=0; // set the take counter to zero (incremented in takepiece)
1551 if ( ns > 1 ){// check north
1552 orientation=NORTH;
1553 if ( cantakepiece() ) { tpns=ns-1; takepiece(); }
1554 }
1555 if ( ns < 9 ){ // check south
1556 orientation=SOUTH;
1557 if ( cantakepiece() ) { tpns=ns+1; takepiece(); }
1558 }
1559 tpns=ns;
1560 if ( ew < 9 ){ // check east
1561 orientation=EAST;
1562 if ( cantakepiece() ) { tpew=ew+1; takepiece(); }
1563 }
1564 if ( ew > 1 ){ // check west
1565 orientation=WEST;
1566 if ( cantakepiece() ) { tpew=ew-1; takepiece(); }
1567 }
1568
1569 // update count of attackers around king
1570 kingattacker[NORTH]=0; // count of attackers NORTH of king
1571 kingattacker[SOUTH]=0; // count of attackers SOUTH of king
1572 kingattacker[EAST]=0; // count of attackers EAST of king
1573 kingattacker[WEST]=0; // count of attackers WEST of king
1574 kingdefender[NORTH]=0; // count of defenders NORTH of king
1575 kingdefender[SOUTH]=0; // count of defenders SOUTH of king
1576 kingdefender[EAST]=0; // count of defenders EAST of king
1577 kingdefender[WEST]=0; // count of defenders WEST of king
1578 kingpieces[NORTH]=0;
1579 kingpieces[SOUTH]=0;
1580 kingpieces[EAST]=0;
1581 kingpieces[WEST]=0;
1582 orientation=NORTH;
1583 cy=kingew;
1584 for (counter=0;counter<kingns;inccounter()){
1585 cx=counter;incdefatt();
1586 }
1587 orientation=SOUTH; // SOUTH
1588 for (counter=kingns+1;counter<11;inccounter()){
1589 cx=counter; incdefatt();
1590 }
1591 orientation=EAST; // EAST
1592 cx=kingns;
1593 for (counter=kingew+1;counter<11;inccounter()){
1594 cy=counter; incdefatt();
1595 }
1596 orientation=WEST; // WEST
1597 for (counter=0;counter<kingew;inccounter()){
1598 cy=counter; incdefatt();
1599 }
1600 if (takecounter > 1) takemessage(); // display a firstblood/multiple takes message
1601 }
1602
1603 void incdefatt(){
1604 if (players[cx][cy] == ATTACKER) inckingattacker();
1605 if (players[cx][cy] == DEFENDER) inckingdefender();
1606 }
1607
1608 void inckingdefender(){
1609 kingdefender[orientation]++;
1610 kingpieces[orientation]++;
1611 }
1612
1613 void inckingattacker(){
1614 kingattacker[orientation]++;
1615 kingpieces[orientation]++;
1616 }
1617
1618 /*void subcanbetaken(){
1619 target[targetns][targetew]=1;
1620 //if ((ns==kingns)||(ew==kingew)) { target[ns][ew]=3;} // means acceptable risk
1621 }
1622 */
1623 // can I be taken after moving here?
1624 void canbetaken() {
1625 if ((targetns )&&(targetns < 10)){
1626 takena=targetns-1;takenb=targetew;takenc=targetns+1;takend=targetew;takene=1;
1627 subcanbetaken2();
1628 takena=targetns+1;takenb=targetew;takenc=targetns-1;takend=targetew;takene=5;
1629 subcanbetaken2();
1630 }
1631
1632 if ((targetew )&&(targetew < 10)){
1633 takena=targetns;takenb=targetew+1;takenc=targetns;takend=targetew-1;takene=10;
1634 subcanbetaken2();
1635 takena=targetns;takenb=targetew-1;takenc=targetns;takend=targetew+1;takene=20;
1636 subcanbetaken2();
1637 }
1638 }
1639
1640 // Will return a value (take) who's values will be: 0= no, 1=yes
1641 unsigned char cantakepiece(){
1642 take=0;
1643 p1=ATTACKER; // piece type comparison (lower) - used for determining takes - default=attacker
1644 p2=CASTLE; // piece type comparison (upper) - used for determining takes - default=attacker
1645 pcheckns1=ns-1; // defaults to north
1646 pcheckns2=ns-2;
1647 pcheckew1=ew;
1648 pcheckew2=ew;
1649 piecetype=players[ns][ew]; // obtain type of piece
1650 //if ( fb==3) { piecetype=players[ctns][ctew];} // if computer turn set piecetype to piece being checked
1651 if ((fb == 3)||(fb == 9)) piecetype=ATTACKER; // default = ATTACKER
1652 if (piecetype > ATTACKER ){ // if defender
1653 p1=DEFENDER;
1654 p2=KING;
1655 }
1656 if ( orientation == SOUTH){ // if south
1657 pcheckns1=ns+1;
1658 pcheckns2=ns+2;
1659 }
1660 if ( orientation > SOUTH){ // if east or west
1661 pcheckns1=ns;
1662 pcheckns2=ns;
1663 pcheckew1=ew+1;
1664 pcheckew2=ew+2;
1665 if ( orientation == WEST){ // if west
1666 pcheckew1=ew-1;
1667 pcheckew2=ew-2;
1668 }
1669 }
1670 // Ring Of Steel: when fb==6 update target if defender outside it's home zone
1671 if ( playerlevel ){ // if greater than SAGA
1672 if ((fb == 6)&&(players[pcheckns1][pcheckew1] == DEFENDER)){
1673 if (( pcheckns1 < 3 ) || (pcheckns1 > 7) || (pcheckew1 < 3)||(pcheckew1 > 7)){
1674 target[ns][ew]+=10;
1675 }
1676 }
1677 }
1678 // if a take is possible increment the take counter - if values fall within bounds...
1679 if ((pcheckns2 > -1)&&(pcheckns2 < 11)&&(pcheckew2 > -1)&&(pcheckew2 < 11)){
1680 if (( players[pcheckns1][pcheckew1] )&&(players[pcheckns1][pcheckew1] != p1)&&(players[pcheckns1][pcheckew1] != p2 )&&(players[pcheckns1][pcheckew1] != CASTLE)){
1681 // if ((( players[pcheckns2][pcheckew2] == p1 )||(players[pcheckns2][pcheckew2] == p2 )||(players[pcheckns2][pcheckew2] == 4)&&(pcheckns2!=5)&&(pcheckew2!=5))) // the 5 is to EXCLUDE central square
1682 if (( players[pcheckns2][pcheckew2] == p1 )||(players[pcheckns2][pcheckew2] == p2 )||(players[pcheckns2][pcheckew2] == CASTLE)){
1683 take++;
1684 //if ((players[pcheckns1][pcheckew1]==3)&&(surrounded<3))take--; // if possible take is a king but not surrounded
1685 if (players[pcheckns1][pcheckew1]==KING) take--;// if possible take is a king
1686
1687 }
1688 if ( computer[pcheckns2][pcheckew2] ) inctarget(); // 31-10-2011 - can possibly take on next turn
1689 }
1690 }
1691 return take;
1692 }
1693
1694 // performs taking/removing a piece
1695 void takepiece(){
1696 players[tpns][tpew]=0; // clear board location
1697 row=tpns;
1698 col=tpew;
1699 inkcolor=6;inkasm();
1700 explodetile(); // plays animation to "kill" a tile
1701 tiletodraw=tiles[row][col]; // decide tile to draw
1702 DrawPictureTiles();// draw tile at location
1703 // update deadpile
1704 deadtoggle=1; // ensure deadpiece is drawn in foreground color on deadpile
1705 deadpile();
1706 inctakecounter(); // increment the take counter
1707 if (firstblood){
1708 Trophies[FIRSTBLOOD][playertype-1]=TROPHY; // update Trophies Array
1709 firstblood=0;
1710 message="\n FIRST BLOOD TO ATTACKER * PRESS A KEY";
1711 if ( playertype == DEFENDER ){
1712 message="\n FIRST BLOOD TO KING * PRESS A KEY";
1713 }
1714 submessage();
1715
1716 }
1717 }
1718 void takemessage(){ // displays a firstblood or multiple take message
1719 if ( takecounter == 2 ) {
1720 message="\n DOUBLE TAKE! * PRESS A KEY";
1721 Trophies[BLOODEAGLE][playertype-1]=TROPHY;
1722 }
1723 if ( takecounter == 3 ) {
1724 message="\n TRIPLE TAKE! * PRESS A KEY";
1725 Trophies[BERZERKER][playertype-1]=TROPHY;
1726 }
1727 submessage();
1728 }
1729 void submessage(){
1730 printmessage();
1731 flashon();
1732 printturnline();
1733 getchar();
1734 }
1735 void subarrows(){
1736 if ( tiles[xns][xew] == CASTLE ) arrow=2;
1737 if ((players[xns][xew])&&(players[xns][xew] < CASTLE)) {
1738 arrow=0; // !ok if piece occupied
1739 if ((fb == 4)&&(players[xns][xew] == ATTACKER)) enemy[xns][xew]+=ENEMYWEIGHT; // means enemy could get here if attacker moved elsewhere
1740 }
1741 if (( players[ns][ew] == KING )&&( tiles[xns][xew] == CASTLE )) arrow = 1; // CASTLE square ok if king
1742 }
1743
1744 void subarrows2(){
1745 if ( orientation == NORTH ) enemy[xns][xew]+=5; // means enemy can get here from SOUTH
1746 if ( orientation == SOUTH ) enemy[xns][xew]+=1; // means enemy can get here from NORTH
1747 if ( orientation == EAST ) enemy[xns][xew]+=20; // means enemy can get here from WEST
1748 if ( orientation == WEST ) enemy[xns][xew]+=10; // means enemy can get here from EAST
1749 }
1750
1751 void inccantake(){
1752 z=cantakepiece();
1753 if (z ){
1754 cantake+=z;
1755 cantakeadjust(); // decrement take count if taken piece on same plane as king and taker isn't
1756 }
1757 }
1758
1759 // Explodes a tile
1760 void explodetile() {
1761 //unsigned char b;
1762 ptr_graph=ExplodeTiles; // pointer to byte values of loaded picture
1763 for (b=0;b<8;b++){
1764 tileloop();
1765 pausetime=900;
1766 if (b == 5) pausetime=3000; // pause longer on skull&crossbones
1767 pause(); // add a pause
1768 }
1769 }
1770
1771 void timertile(){
1772 unsigned char timer;
1773 ptr_graph=TimerTiles; // pointer to byte values of loaded picture (Timer)
1774 row=5;col=5;
1775 for (timer=0;timer<8;timer++){
1776 tileloop();
1777 pausetime=250;pause();
1778 }
1779 }
1780
1781 void drawpiece(){
1782 tiletodraw=players[row][col];
1783 if ( tiletodraw ) tiletodraw+=3;
1784 if ( tiles[row][col] ) tiletodraw+=3;
1785 DrawPictureTiles();
1786 }
1787
1788 void drawarrow(){
1789 if ( fb == 1 ){
1790 tiletodraw=10;
1791 if ( tiles[row][col] ) tiletodraw++; // add another 1 for arrow with background
1792 }
1793 else{
1794 tiletodraw=tiles[row][col]; // draw original tile (includes blank)
1795 }
1796 DrawPictureTiles();
1797 }
1798
1799 void surroundcount(){
1800 //unsigned char test;
1801 zerocounter();
1802 //setpoints();
1803 surrounded=0;
1804 if (( kingns == 0)||(kingns == 10)||(kingew == 0)||(kingew == 10)) incsurround(); // added 18/10/2011 (inc surround if at an edge)
1805 surew=kingew;
1806 if ( kingns ) {surns=kingns-1;surroundcheck();}
1807 if ( kingns < 10 ){surns=kingns+1;surroundcheck();}
1808 surns=kingns;
1809 if ( kingew ) {surew=kingew-1;surroundcheck();}
1810 if ( kingew < 10 ){surew=kingew+1;surroundcheck();}
1811 /*for (test=surrounded;test >0; test--){
1812 zap();
1813 }*/
1814 // unset any "enemy and target values" ONLY if blank square adjacent to king is accessible
1815 if (surrounded == 3){
1816 ezew1=kingew;
1817 if ( kingns ){ // NORTH
1818 ezns1=kingns-1;
1819 enemyzero();
1820 }
1821 if ( kingns < 10 ){ // SOUTH
1822 ezns1=kingns+1;
1823 enemyzero();
1824 }
1825 ezns1=kingns;
1826 if ( kingew < 10 ){ // EAST
1827 ezew1=kingew+1;
1828 enemyzero();
1829 }
1830 if ( kingew ){
1831 ezew1=kingew-1; // WEST
1832 enemyzero();
1833 }
1834 }
1835 }
1836
1837 void pause(){
1838 int p;
1839 for (p=0; p<pausetime;p++){};
1840 }
1841
1842
1843 /******************************/
1844
1845 void subcanbetaken2(){ // DO NOT MESS with this (NBARNES 10-01-2012)
1846 if (players[takena][takenb] > ATTACKER){
1847 if ((players[takenc][takend] == 0)||(enemy[takenc][takend] > ENEMYWEIGHT)){
1848 if ((enemy[takenc][takend]-takene)&&((enemy[takenc][takend] < ENEMYWEIGHT)||(enemy[takenc][takend]-ENEMYWEIGHT))){ // 23-12-2011
1849 compass[origorient]=1; // e.g. compass[NORTH]=1 means canbetaken here if moving from NORTH
1850 if (enemy[takenc][takend]>ENEMYWEIGHT){ // THIS is the business!!!
1851 if ((origorient < EAST)&&(mkey != takenc)&&(oew != takend)) compass[origorient]=0;
1852 if ((origorient > SOUTH)&&(ons != takenc)&&(mkey != takend))compass[origorient]=0;
1853 }
1854 }
1855 }
1856 }
1857 }
1858
1859
1860 void inctarget(){
1861 target[targetns][targetew]+=2;
1862 //target[targetns][targetew]++; // 28-04-2013
1863 }
1864
1865
1866 void surroundcheck(){
1867 // if attacker or kingsquare n/s/e/w then inc surrounded
1868 //if (players[surns][surew]==1) incsurround(); // is attacker n,s,e,w
1869 //if (tiles[surns][surew]>2) incsurround(); // is king square n,s,e,w
1870 if ((players[surns][surew] == 1)||(tiles[surns][surew] > 2)) {
1871 incsurround();
1872 }
1873 }
1874
1875
1876
1877
1878 // called from "surroundcount()"
1879 void enemyzero() {
1880 if (( players[ezns1][ezew1] == 0 )&&(target[ezns1][ezew1])){ // if adjacent square n/s/e/w is blank and accessible
1881 ClearArrays(); // set all arrays to zero (target, enemy, computer)
1882 target[ezns1][ezew1]=100; // set big target value to final space by king
1883 }
1884 }
1885 // Checkroute:
1886 // checkroutemode=1 Returns number of pieces on a given route
1887 // checkroutemode=2 Increments the target values on route
1888 // checkroutemode=3 Number of targets on route
1889 // checkroutemode=4 Number of "enemy" targets on route (where enemies CAN go)
1890 // checkroutemode=5 Emergency! Make target=hightarget+1
1891 unsigned char checkroute(){
1892 z=0;
1893 // a SINGLE COLUMN (North to South) so check each row on it
1894 checkroutestart=startrow;
1895 checkroutedest=destrow;
1896 checkrouterow=startrow;
1897 checkroutecol=startcol;
1898 if ( startrow == destrow ){ // ELSE a single ROW (EAST to WEST)
1899 checkroutestart=startcol;
1900 checkroutedest=destcol;
1901 }
1902 for (x=checkroutestart;x<=checkroutedest;x++){
1903 //if ( startrow==destrow ) {checkroutecol++;}else{checkrouterow++;}
1904 switch(checkroutemode){
1905 case 1: if ((players[checkrouterow][checkroutecol] == ATTACKER )||(players[checkrouterow][checkroutecol] == DEFENDER )) z++;break;
1906 case 2: if (target[checkrouterow][checkroutecol] ) target[checkrouterow][checkroutecol]+=2;break;
1907 case 3: if (target[checkrouterow][checkroutecol] > 1 ) z++;break;
1908 case 4: if (enemy[checkrouterow][checkroutecol] ) z+=ENEMYBLOCK;break;
1909 case 5: if (target[checkrouterow][checkroutecol]){
1910 target[checkrouterow][checkroutecol]+=points;} // brokenarrow
1911 break;
1912 //case 6: if (players[checkrouterow][checkroutecol]) z++;break;
1913 case 6: if (kingtracker[checkrouterow][checkroutecol]) z++;break;
1914 }
1915 if ( startrow == destrow ) {checkroutecol++;}else{checkrouterow++;}
1916
1917 }
1918 return z;
1919 }
1920
1921 /*
1922 // ORIGINAL 02/09/2012
1923 unsigned char checkroute(){
1924 z=0;
1925 if (orientation<EAST){ // if checking ROWS (crossing the T) (used for NORTH SOUTH checks)
1926 for (x=startcol;x<=destcol;x++){ // check row
1927 switch(checkroutemode){
1928 case 1: if ((players[startrow][x]==1)||(players[startrow][x]==2)) {z++;}break;
1929 case 2: if (target[startrow][x]) {target[startrow][x]+=2;}break;
1930 case 3: if (target[startrow][x]) {z++;}break;
1931 case 4: if (enemy[startrow][x]) {z+=10;}break;
1932 case 5: if (target[startrow][x]) {target[startrow][x]=255;}
1933 }
1934 }
1935 }
1936 else { // EAST WEST checks (crossing the T)
1937 for (x=startrow;x<=destrow;x++){ // check accross
1938 switch(checkroutemode){
1939 case 1: if ((players[x][startcol]==1)||(players[x][startcol]==2)) {z++;}break;
1940 case 2: if (target[x][startcol]) {target[x][startcol]+=2;}break;
1941 case 3: if (target[x][startcol]) {z++;}break;
1942 case 4: if (enemy[x][startcol]) {z++;}break;
1943 case 5: if (target[x][startcol]) {target[x][startcol]==255;}
1944 }
1945 }
1946 }
1947 return z;
1948 }
1949 */
1950 // decrements cantake if taken piece is on same plane as king
1951 // and attacking piece isn't AND only one defender on plane
1952 void cantakeadjust(){
1953 flag=0;
1954 if ((playertype == 1)&&(gamestyle == 1)){ // if computer playing as attacker and his turn
1955 if (pcheckns1 == kingns){
1956 flag=1;
1957 if (ctew < kingew){orientation=WEST;}else{orientation=EAST;}
1958 //if ((kingattacker[orientation]+kingdefender[orientation])<4){cantake--;}
1959 }
1960 if (pcheckew1 == kingew){
1961 flag=1;
1962 if (ctns < kingns){orientation=NORTH;}else{orientation=SOUTH;}
1963 //if ((kingattacker[orientation]+kingdefender[orientation])<4){cantake--;}
1964 }
1965 if (flag ) {
1966 //if ((kingattacker[orientation]+kingdefender[orientation])<4){cantake--;}
1967 if (kingpieces[orientation] < 4) cantake--; //10-05-2013 if no other pieces on plane
1968 }
1969
1970 }
1971 }
1972
1973 void updatetarget(){
1974 targetns=ctns;targetew=ctew;
1975 target[targetns][targetew]=2; // set target to 2 (1=canbetaken if i go here)
1976 // set "illegal" squares to zero
1977 target[5][5]=0;
1978 target[0][10]=0;
1979 target[0][0]=0;
1980 target[10][0]=0;
1981 target[10][10]=0;
1982 if ( target[targetns][targetew] ){ // only if target is valid (i.e. not a king square)
1983 // increase target if blocking 1 enemy
1984 if ( enemy[targetns][targetew] ) inctarget();
1985 // increase taregt if blocking 2 enemies
1986 if (( enemy[targetns][targetew] == 6)||(enemy[targetns][targetew] == 11)||(enemy[targetns][targetew] == 21)||(enemy[targetns][targetew] == 15)||(enemy[targetns][targetew] == 25)||(enemy[targetns][targetew] == 30)) inctarget();
1987 // increase target if blocking 3 enemies
1988 if (( enemy[targetns][targetew] == 35)||(enemy[targetns][targetew] == 16)||(enemy[targetns][targetew] == 26) || (enemy[targetns][targetew] == 31)) inctarget();
1989 // calculates how many takes can be made in this position (cantake)
1990 calccantake2();
1991 //calccantake(); // calculates how many takes can be made in this position (cantake)
1992 //y=cantake*TAKEWEIGHT; // value to be added to target
1993 //target[targetns][targetew]+=y; // add cantake (will be zero if cannot take)
1994 target[targetns][targetew]+=(cantake*TAKEWEIGHT);
1995 //if (cantake==0) {canbetaken();} // sets target to 1 if cannot take but can be taken
1996 }
1997 }
1998
1999
2000 // calculate how many takes can be made
2001 /*
2002 void calccantake() {
2003 //unsigned char x;
2004 //cantake=0;
2005 inccantake(); // inc cantake if can take in direction of travel
2006 //for (x=0;x<4;x++) {
2007 //if ( x<2 ){ // heading north/south
2008 if ( origorient < EAST ){ // HEADING NORTH/SOUTH
2009 if ( ew < 10 ) {orientation=EAST; inccantake();} // check EAST
2010 if ( ew > 1 ) {orientation=WEST; inccantake();} // check WEST
2011 }else{ // heading east/west
2012 if ( ns > 1 ) {orientation=NORTH; inccantake();} // check NORTH
2013 if ( ns < 9 ) {orientation=SOUTH; inccantake(); } // check SOUTH
2014 }
2015 }
2016 */
2017 void calccantake2(){
2018 // check all directions from a given target square...
2019 cantake=0;
2020 if ( ew < 9 ) {orientation=EAST; inccantake();} // check EAST
2021 if ( ew > 1 ) {orientation=WEST; inccantake();} // check WEST
2022 if ( ns > 1 ) {orientation=NORTH; inccantake();} // check NORTH
2023 if ( ns < 9 ) {orientation=SOUTH; inccantake();} // check SOUTH
2024 }
2025 // print the title screen
2026 /*
2027 void printtitles() {
2028 unsigned char f=0;
2029 inkcolor=3;inkasm(); // yellow, erm...gold
2030 row=0;c=6;d=11;col=0;
2031 for (mkey=0;mkey<2;mkey++){
2032 for (a=row;a<c;a++){
2033 col=0;
2034 if (mkey ) {fliprune();col=1;} // flip the row
2035 for(b=col;b<d;b++){
2036 tiletodraw=border[a][b]; // get runic chars
2037 if (f == 1) tiletodraw++; // get western chars on 2nd pass
2038 if ( tiletodraw < 99){
2039 ptr_graph=RunicTiles; // pointer to Border Tiles graphics
2040 drawtile(); // draw tile
2041 }
2042 col++;
2043 }
2044 row++;
2045 }
2046 row=1;col=1;c=5;d=10;pausetime=26000;pause();
2047 f++;if (f==2) f=0;
2048 }
2049 }
2050 */
2051 void PrintTrophyScreen(){
2052 // Print text in text area
2053 erasetextarea();
2054 message=" ()( HNEFATAFL ()(\n )() VALHALLA AWARDS )()\n ()( PRESS A KEY ()(";
2055 printline();
2056 // set ink color for main screen
2057 inkcolor=3;inkasm(); // yellow, erm...gold
2058 row=0;a=0;b=4;c=1;
2059 PrintTrophyScreen1(); // print top row of border
2060 a=6;b=8;c=7;
2061 for (row=1;row<10;row++){
2062 PrintTrophyScreen1(); // print middle rows of border
2063 }
2064 row=10;a=2;b=5;c=3;
2065 PrintTrophyScreen1(); // print bottom row of border
2066 bottompattern=0;drawbottom(); // blank out line at bottom
2067 //PrintTrophyScreen2(); // blank out right edge before redrawing board
2068 AlgizThorTrophyCalc(); // Calculate the awarding of ALGIZ/THOR Trophies
2069 PrintTrophyScreen3(); // print the trophy grid (with trophies)
2070 cy=2;cx=7;inverse();cx=8;inverse(); // inverse the trophy head columns
2071 PrintTrophyScreen4(); // print text onto the hires part of screen
2072 getchar();
2073 }
2074 void PrintTrophyScreen1(){
2075 for (col=0; col<11; col++){
2076 tiletodraw=b;
2077 if (col==0) tiletodraw=a;
2078 if (col==10) tiletodraw=c;
2079 ptr_graph=BorderTiles2;
2080 drawtile();
2081 }
2082 }
2083 /*
2084 void PrintTrophyScreen2(){
2085 tiletodraw=8; // blank tile
2086 for (row=0;row<11;row++){
2087 for (col=11;col<13;col++){
2088 ptr_graph=BorderTiles2;
2089 drawtile();
2090 }
2091 }
2092 }
2093 */
2094 void PrintTrophyScreen3(){
2095 // draw grid header
2096 for (row=2;row<9;row++){
2097 for (col=7;col<9;col++){
2098 a=row-2;b=col-7; // adjust a,b to align with array values
2099 tiletodraw=Trophies[a][b];
2100 DrawPictureTiles();
2101 }
2102 }
2103 DrawTrophyEdge();
2104 DrawTrophyBottom();
2105 }
2106 // Print the trophy names
2107
2108 void PrintTrophyScreen4(){
2109 //deadtext=0xa5ae; //starting position of text on screen
2110 row=3;col=2;
2111 for (x=0;x<6;x++){
2112 //deadcurset=0xad29+((40*8)*(x*2))+((40*8)*2);
2113 deadcurset=0xa002+(40*18*row)+(40*6)+(col*3);
2114 for (y=0;y<11;y++){
2115 //textchar=(TrophyText[x][y]-32)*8;
2116 textchar=TrophyText[x][y];
2117 chasm2();
2118 deadcurset++;
2119 }
2120 row++;
2121 //deadtext=0xa5ae+((40*8)*2);
2122 }
2123 }
2124
2125 void AlgizThorTrophyCalc(){ // Calculate if anyone should get the ALGIZ or THOR Trophies
2126 //if ( playertype == 1){ // if current player is ATTACKER
2127 if (deadattackers==0) Trophies[ALGIZ][0]=TROPHY;
2128 if (deaddefenders==0) Trophies[ALGIZ][1]=TROPHY;
2129 if (deaddefenders>11) Trophies[THOR][0]=TROPHY;
2130 if (deadattackers==24)Trophies[THOR][1]=TROPHY;
2131 //}
2132 //if ( playertype == 2){ // if current player is DEFENDER
2133
2134 //}
2135 }
2136 void ClearTrophies(){
2137 Trophies[0][0]=7; // PictureTiles : attacker tile
2138 Trophies[0][1]=9; // PictureTiles : king tile
2139 Trophies[1][0]=0;
2140 Trophies[1][1]=0;
2141 Trophies[2][0]=0;
2142 Trophies[2][1]=0;
2143 Trophies[3][0]=0;
2144 Trophies[3][1]=0;
2145 Trophies[4][0]=0;
2146 Trophies[4][1]=0;
2147 Trophies[5][0]=0;
2148 Trophies[5][1]=0;
2149 Trophies[6][0]=0;
2150 Trophies[6][1]=0;
2151 }
2152 /*
2153 // performs the rune flipping sequence in title screen
2154 void fliprune() {
2155 for (tiletodraw=30;tiletodraw<35;tiletodraw++){
2156 for (col=1;col<10;col++){
2157 if (border[row][col] < 99){
2158 ptr_graph=RunicTiles; // pointer to Border Tiles graphics
2159 drawtile();pausetime=50;pause();
2160 }
2161 }
2162 }
2163 }
2164 */
2165 /*
2166 void subzoneupdate(){ // (updates border targets)
2167 message="BROKEN ARROW UPDATE";
2168 printline();
2169 message="\nPRESS A KEY";
2170 printline();
2171 getchar();
2172 checkroutemode=5;checkroute();
2173 }
2174 */
2175 void updateroutetarget(){
2176 //setcheckmode3(); // set the mode of checkroute to 3 (count how many TARGETS are on route)
2177 //pacpointsz=checkroute();
2178 //pacpointsz=25-pacpointsz; // 20 = max amount of targets on a given route to a corner
2179 setcheckmode2(); // set the mode of checkroute to 2 (update targets)
2180 checkroute();
2181 }
2182
2183 // flashes the screen red (goes back to whatever flashback is set to)
2184 void flashred(){
2185 flashcolor=RED;
2186 flashscreen();
2187 }
2188 // gets the turn values and splits into huns, thor, odin
2189 void calcturnvalue(){
2190 // calculate values
2191 huns=x/100;
2192 thor=(x-(huns*100))/10;
2193 odin=x-(huns*100)-(thor*10);
2194 // transform to ascii code (hundreds, tens and units)
2195 huns+=48;
2196 thor+=48;
2197 odin+=48;
2198 }
2199 // prints the turn counters (uses huns, thor, odin)
2200 void printturnline(){
2201 x=turncount;
2202 calcturnvalue(); // for display purposes
2203 printturncount(); // print number of turns
2204 x=turnlimit-turncount;// x= turns remaining
2205 calcturnvalue(); // for display purposes
2206 TurnsRemaining=x; // for RAIDO Trophy Calculation
2207 printremaining(); // print turns remaining
2208 y=GREEN;
2209 if ( x < 10) y=YELLOW;
2210 if ( x < 5 ) y=RED;
2211 colorturn(); // set color for turn row
2212 }
2213 /*
2214 void prioritycalc(){ // calculates the priorities of moving a piece
2215 for(a=0;a<11;a++){
2216 for (b=0;b<11;b++){
2217 if (players[a][b]==1){
2218 // count attackers on row
2219 for (c=0;c<11;c++){
2220 if (players[c][b]==1) priority[a][b]++;
2221 }
2222 for (d=0;d<11;d++){
2223 if (players[a][d]==1) priority[a][b]++;
2224 }
2225 }
2226 }
2227 }
2228 }
2229 */

  ViewVC Help
Powered by ViewVC 1.1.26