#include "xlib.h"
#include "xtext.h"
#include "xrect.h"
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <alloc.h>
#ifndef ANIMAP.H
#include "animap.h"
#endif
#ifndef ACTOR.H
#include "actor.h"
#endif
#ifndef EVENT.H
#include "event.h"
#endif
#ifndef FACTOR.H
#include "factor.h"
#endif
#include "boodles.h"
#include "boodmisc.h"

extern int score;
extern int turns;
extern int numboodles, numgrumjugs;
extern boodlepiece ** boodles;
extern boodlepiece ** grumjugs;

void main(int argcount, char ** argvector)
{
  int boodlepoints = 35;
  int grumpoints = 36;
  if (argcount == 3)
  {
    boodlepoints = atoi(argvector[1]);
    grumpoints = atoi(argvector[2]);
  }
  randomize();
  int randomnum, hitcounter = 0;
  boodlepiece * target;
  x_set_mode(2, 380);
  x_set_doublebuffer(260);
  x_text_init();
  _DMloadpal("dm256.pal");
  load_boodle_icons();
  animap mymap("boodle.map");
  boodlepiece * myactor;
  showlogo(&mymap);
  allocate_forces(&mymap, boodlepoints, grumpoints);
  char exit = 'd';
  while (exit != 'Q')
  {
    turns++;
    exit = boodleturn(&mymap);
    if (exit == 0) break; //no living boodles
    if (score > 3) break;
    exit = grumturn(&mymap);
    for (int width_counter = 0; width_counter < mymap.width; ++width_counter)
      for (int height_counter = 0; height_counter < mymap.height; ++height_counter)
	mymap.mapdata[width_counter][height_counter].my_terrain_type &= 0xEF;
  }
  endgame();
  x_text_mode();
  puts("Thank you for playing Flight of the Boodles!");
  puts("\nLook for other upcoming releases:");
  puts("Morningstar: Futuristic combat on a grand scale.  Mechs never had");
  puts("	     it so good...");
  puts("Coverdale  : In 1994, shareware rpg's stop playing games.  Come back");
  puts("	     to the story... in Coverdale.\n");
  puts("Flight of the Boodles was written with YakIcons1.2, the flexible object-");
  puts("oriented icon programming library by V. Putz.  Available at fine FTP");
  puts("sites everywhere.\n");
}
