CREATE TABLE IF NOT EXISTS `match` (
  `match_id`       INT UNSIGNED     NOT NULL AUTO_INCREMENT,
  `match_time`     DATETIME         NOT NULL,
  `server_name`    VARCHAR(256)     NOT NULL DEFAULT '',
  `server_ip`      VARCHAR(64)      NOT NULL DEFAULT '',
  `map_name`       VARCHAR(128)     NOT NULL DEFAULT '',
  `scenario_name`  VARCHAR(128)     NOT NULL DEFAULT '',
  `game_type`      INT              NOT NULL DEFAULT 0,
  `game_type_name` VARCHAR(64)      NOT NULL DEFAULT '',
  `is_team_game`   TINYINT(1)       NOT NULL DEFAULT 0,
  `player_count`   INT              NOT NULL DEFAULT 0,
  `team_count`     INT              NOT NULL DEFAULT 0,
  `team_scores`    VARCHAR(64)      NOT NULL DEFAULT '',
  `game_length`    INT              NOT NULL DEFAULT 0,
  `kill_limit`     INT              NOT NULL DEFAULT 0,
  `respawn_limit`  INT              NOT NULL DEFAULT 0,
  `friendly_fire`  INT              NOT NULL DEFAULT 0,
  `heat_on`        TINYINT(1)       NOT NULL DEFAULT 0,
  `armor_mode`     TINYINT(1)       NOT NULL DEFAULT 0,
  `unlimited_ammo` TINYINT(1)       NOT NULL DEFAULT 0,
  `is_night`       TINYINT(1)       NOT NULL DEFAULT 0,
  `min_tonnage`    INT              NOT NULL DEFAULT 0,
  `max_tonnage`    INT              NOT NULL DEFAULT 0,
  PRIMARY KEY (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `player_result` (
  `result_id`   INT UNSIGNED  NOT NULL AUTO_INCREMENT,
  `match_id`    INT UNSIGNED  NOT NULL,
  `player_name` VARCHAR(64)   NOT NULL DEFAULT '',
  `mech_name`   VARCHAR(64)   NOT NULL DEFAULT '',
  `team`        INT           NOT NULL DEFAULT 0,
  `score`       INT           NOT NULL DEFAULT 0,
  `kills`       INT           NOT NULL DEFAULT 0,
  `deaths`      INT           NOT NULL DEFAULT 0,
  `is_bot`      TINYINT(1)    NOT NULL DEFAULT 0,
  `pilot_decal` INT           NOT NULL DEFAULT 0,
  PRIMARY KEY (`result_id`),
  KEY `match_id` (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `pvp` (
  `pvp_id`    INT UNSIGNED  NOT NULL AUTO_INCREMENT,
  `match_id`  INT UNSIGNED  NOT NULL,
  `attacker`  VARCHAR(64)   NOT NULL DEFAULT '',
  `victim`    VARCHAR(64)   NOT NULL DEFAULT '',
  `kills`     INT           NOT NULL DEFAULT 0,
  `score`     INT           NOT NULL DEFAULT 0,
  PRIMARY KEY (`pvp_id`),
  KEY `match_id` (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Optional: only populated when ExportEvents=1 in mw4print.ini
CREATE TABLE IF NOT EXISTS `event` (
  `event_id`   INT UNSIGNED  NOT NULL AUTO_INCREMENT,
  `match_id`   INT UNSIGNED  NOT NULL,
  `event_type` INT           NOT NULL DEFAULT 0,
  `actor`      VARCHAR(64)   NOT NULL DEFAULT '',
  `target`     VARCHAR(64)   NOT NULL DEFAULT '',
  `weapon`     INT           NOT NULL DEFAULT 0,
  `body_zone`  INT           NOT NULL DEFAULT 0,
  `param`      INT           NOT NULL DEFAULT 0,
  PRIMARY KEY (`event_id`),
  KEY `match_id` (`match_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
