#!/usr/pkg/bin/perl
# Includes
use CGI;
use DBI;
use URI::Escape;
use Data::Dumper;
use Time::HiRes qw(gettimeofday tv_interval);
my $start = [gettimeofday];
# Flush all output immediately
$| = 1;
### DEBUG ###
$ENV{DEBUG} = 0;
### DEBUG ###
### VERBOSE ###
$ENV{VERBOSE} = 0;
### VERBOSE ###
# Print the content type, etc.
print CGI::header();
# Name of the datasource
#my $dsn = "dbi:mysql:mechdbtest:localhost:6900";
my $dsn = "dbi:mysql:zax:ol.freeshell.org:3306";
# Login credentials
#my $user = "bt";
#my $pass = "bt";
my $user = "zax";
my $pass = "mechdb";
# Get a handle to the database.
my $dbh = DBI->connect($dsn, $user, $pass) or die "Can't connect to the DB: $DBI::errstr\n";
# Parameters from the HTML form
%P = ();
# Determine the script name so that it can properly reference itself
$0 =~ m,/([^/]+)$,;
my $script = $1;
# Generate some Name->Id and Id->Name lookup tables
my %ClassNameToId = GenerateLookup("Class", "Name,Id");
my %ClassIdToName = reverse(%ClassNameToId);
my %TechNameToId = GenerateLookup("Tech", "ShortName,Id");
my %TechIdToName = reverse(%TechNameToId);
my %EquipmentNameToId = GenerateLookup("Equipment", "ShortName,Id");
my %EquipmentIdToName = reverse(%EquipmentNameToId);
my %WeaponNameToId = GenerateLookup("Weapon", "ShortName,Id");
my %WeaponIdToName = reverse(%WeaponNameToId);
my %WeaponClassNameToId = GenerateLookup("WeaponClass", "ShortName,Id");
my %WeaponClassIdToName = reverse(%WeaponClassNameToId);
my %WeaponTypeNameToId = GenerateLookup("WeaponType", "Name,Id");
my %WeaponTypeIdToName = reverse(%WeaponTypeNameToId);
# Tooltips!
my %EquipmentTooltip = (
'BAP' => 'Beagle Active Probe
Passive
Extends your radar range to 1200 meters',
'ECM' => 'Electronic Countermeasures
Passive
Jams incoming missile radar, making it take longer for an enemy to get a lock',
'IFF' => 'Friend-or-Foe Jammer
Passive
Sends out a neutral signal to all receiving radar, making it impossible to determine if you are friend or foe',
'LA' => 'Light Amplification
Active
Turn on to increase visibility in low-light conditions',
'AMS' => 'Anti-Missile System
Passive
When a locked missile volley is incoming, a portion of them will be neutralized',
'JJ' => 'Jump Jets
Active
Provides your mech with limited periods of flight',
);
my %WeaponData = GetWeaponData();
my %WeaponTooltips = GenerateWeaponTooltips(%WeaponData);
# For Low-Bandwidth display
my %ArmorTypeLongToShort = ("Standard" => "Std", "Reflective" => "Rfl", "Reactive" => "Rct", "Solarian" => "Slr", "Ferro" => "Fer");
print "
\n" if ($ENV{DEBUG});
ParseParams();
my $RestrictMechStatement = BuildRestrictionStatement();
print "DEBUG: CALL GetFullMechConfig('$RestrictMechStatement');
\n" if $ENV{DEBUG};
# Prevent hitting the DB unless we're actually searching (e.g. skip getting the mech list on first load)
my @FullMechConfig = (defined $P{'Search'} || defined $P{'special'}) ? ExecSql("CALL GetFullMechConfig('$RestrictMechStatement');") : ();
my @cOrder = ();
PrintPage();
sub PrintPage
{
print "\n";
print "\n";
PrintPageHeader();
print "