using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using Syroot.BinaryData;
using Syroot.Worms.Core.IO;
namespace Syroot.Worms.WorldParty
{
///
/// Represents a team stored in a file.
///
public class Team : ILoadable, ISaveable
{
// ---- CONSTANTS ----------------------------------------------------------------------------------------------
private const int _missionCount = 45;
private const int _trainingMissionCount = 35;
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
///
/// Initializes a new instance of the class.
///
public Team()
{
WormNames = new string[8];
MissionStatuses = new TeamMissionStatus[_missionCount];
TrainingMissionTimes = new int[_trainingMissionCount];
WeaponPoints = new byte[46];
Unknown2 = new int[7];
}
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
///
/// Gets or sets the name of the team.
///
public string Name { get; set; }
///
/// Gets or sets the 8 worm names.
///
public string[] WormNames { get; set; }
///
/// Gets or sets the AI intelligence difficulty level, from 0-5, where 0 is human-controlled.
///
public byte CpuLevel { get; set; }
///
/// Gets or sets the name of soundbank for the voice of team worms.
///
public string SoundBankName { get; set; }
public byte SoundBankLocation { get; set; }
///
/// Gets or sets the name of the team fanfare.
///
public string FanfareName { get; set; }
///
/// Gets or sets a value indicating whether the fanfare with the name stored in
/// (true) or the player's countries' fanfare should be played (false).
///
public byte UseCustomFanfare { get; set; }
///
/// Gets or sets the sprite index of the team grave, -1 being a custom bitmap grave.
///
public sbyte GraveSprite { get; set; }
///
/// Gets or sets the file name of the team grave bitmap if it uses a custom one.
///
public string GraveFileName { get; set; }
///
/// Gets or sets the team grave bitmap if it uses a custom one.
///
public RawBitmap Grave { get; set; }
///
/// Gets or sets the team's special weapon.
///
public TeamWeapon TeamWeapon { get; set; }
///
/// Gets or sets the number of games lost.
///
public int GamesLost { get; set; }
///
/// Gets or sets the number of deathmatch games lost.
///
public int DeathmatchesLost { get; set; }
///
/// Gets or sets the number of games won.
///
public int GamesWon { get; set; }
///
/// Gets or sets the number of deathmatch games won.
///
public int DeathmatchesWon { get; set; }
///
/// Gets or sets the number of games drawn.
///
public int GamesDrawn { get; set; }
///
/// Gets or sets the number of deathmatch games drawn.
///
public int DeathmatchesDrawn { get; set; }
///
/// Gets or sets the number of opponent worms killed by this team.
///
public int Kills { get; set; }
///
/// Gets or sets the number of opponent worms killed by this team in deathmatches.
///
public int DeathmatchKills { get; set; }
///
/// Gets or sets the number of worms which got killed in this team.
///
public int Deaths { get; set; }
///
/// Gets or sets the number of worms which got killed in this team in deathmatches.
///
public int DeathmatchDeaths { get; set; }
///
/// Gets or sets the array of 33 mission statuses.
///
public TeamMissionStatus[] MissionStatuses { get; set; }
///
/// Gets or sets the file name of the team flag.
///
public string FlagFileName { get; set; }
///
/// Gets or sets the bitmap of the team flag.
///
public RawBitmap Flag { get; set; }
///
/// Gets or sets an unknown value.
///
public byte Unknown1 { get; set; }
///
/// Gets or sets the deathmatch rank this team reached.
///
public byte DeathmatchRank { get; set; }
///
/// Gets or sets the seconds the team required to finish all 35 training missions. The last one is unused.
///
public int[] TrainingMissionTimes { get; set; }
///
/// Gets or sets a possibly unused training mission time for a 35th mission.
///
public int UnknownTrainingMissionTime { get; set; }
///
/// Gets or sets the 46 weapons which were bought for points. Specific weapons can be accessed with the
/// enumeration.
///
public byte[] WeaponPoints { get; set; }
///
/// Gets or sets the fort of the team.
///
public byte Fort { get; set; }
///
/// Gets or sets 7 unknown integer values.
///
public int[] Unknown2 { get; set; }
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
///
/// Loads the data from the given .
///
/// The to load the data from.
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
Name = reader.ReadString(17);
WormNames = reader.ReadStrings(8, 17);
CpuLevel = reader.Read1Byte();
SoundBankName = reader.ReadString(0x20);
SoundBankLocation = reader.Read1Byte();
FanfareName = reader.ReadString(0x20);
UseCustomFanfare = reader.Read1Byte();
GraveSprite = reader.ReadSByte();
if (GraveSprite < 0)
{
GraveFileName = reader.ReadString(0x20);
Grave = new RawBitmap()
{
BitsPerPixel = 8,
Size = new Size(24, 32),
Palette = reader.ReadStructs(256),
Data = reader.ReadBytes(24 * 32)
};
}
TeamWeapon = reader.ReadEnum(true);
GamesLost = reader.ReadInt32();
DeathmatchesLost = reader.ReadInt32();
GamesWon = reader.ReadInt32();
DeathmatchesWon = reader.ReadInt32();
GamesDrawn = reader.ReadInt32();
DeathmatchesDrawn = reader.ReadInt32();
Kills = reader.ReadInt32();
DeathmatchKills = reader.ReadInt32();
Deaths = reader.ReadInt32();
DeathmatchDeaths = reader.ReadInt32();
MissionStatuses = reader.ReadStructs(_missionCount);
FlagFileName = reader.ReadString(0x20);
Flag = new RawBitmap()
{
BitsPerPixel = 8,
Size = new Size(20, 17),
Palette = reader.ReadStructs(256),
Data = reader.ReadBytes(20 * 17)
};
Unknown1 = reader.Read1Byte();
DeathmatchRank = reader.Read1Byte();
TrainingMissionTimes = reader.ReadInt32s(_trainingMissionCount);
WeaponPoints = reader.ReadBytes(46);
Fort = reader.Read1Byte();
Unknown2 = reader.ReadInt32s(7);
}
}
///
/// Saves the data into the given .
///
/// The to save the data to.
public void Save(Stream stream)
{
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
writer.WriteString(Name, 17);
writer.WriteStrings(WormNames, 17);
writer.Write(CpuLevel);
writer.WriteString(SoundBankName, 0x20);
writer.Write(SoundBankLocation);
writer.WriteString(FanfareName, 0x20);
writer.Write(UseCustomFanfare);
writer.Write(GraveSprite);
if (GraveSprite < 0)
{
writer.WriteString(GraveFileName, 0x20);
writer.WriteStructs(Grave.Palette);
writer.WriteStructs(Grave.Data);
}
writer.WriteEnum(TeamWeapon, true);
writer.Write(GamesLost);
writer.Write(DeathmatchesLost);
writer.Write(GamesWon);
writer.Write(DeathmatchesWon);
writer.Write(GamesDrawn);
writer.Write(DeathmatchesDrawn);
writer.Write(Kills);
writer.Write(DeathmatchKills);
writer.Write(Deaths);
writer.Write(DeathmatchDeaths);
writer.WriteStructs(MissionStatuses);
writer.WriteString(FlagFileName, 0x20);
writer.WriteStructs(Flag.Palette);
writer.WriteStructs(Flag.Data);
writer.Write(Unknown1);
writer.Write(DeathmatchRank);
writer.Write(TrainingMissionTimes);
writer.Write(UnknownTrainingMissionTime);
writer.WriteStructs(WeaponPoints);
writer.Write(Fort);
writer.Write(Unknown2);
}
}
}
///
/// Represents a team's progress in a mission.
///
[DebuggerDisplay("TeamMissionStatus Attemps={Attempts} Medal={Medal}")]
public struct TeamMissionStatus
{
///
/// The number of attempts the team required to solve the mission.
///
public int Attempts;
///
/// The medal the team got to solve the mission.
///
public int Medal;
}
///
/// Represents the special weapon of a team.
///
public enum TeamWeapon : byte
{
///
/// The Flame Thrower weapon.
///
Flamethrower,
///
/// The Mole Bomb weapon.
///
MoleBomb,
///
/// The Old Woman weapon.
///
OldWoman,
///
/// The Homing Pigeon weapon.
///
HomingPigeon,
///
/// The Sheep Launcher weapon.
///
SheepLauncher,
///
/// The Mad Cow weapon.
///
MadCow,
///
/// The Holy Hand Grenade weapon.
///
HolyHandGrenade,
///
/// The Super Sheep or Aqua Sheep weapon.
///
SuperSheep
}
///
/// Represents the weapons and utilities being an index into the array to store the
/// amount the team bought.
///
public enum TeamWeaponPoints
{
///
/// The Bazooka weapon.
///
Bazooka,
///
/// The Homing Missile weapon.
///
HomingMissile,
///
/// The Mortar weapon.
///
Mortar,
///
/// The Grenade weapon.
///
Grenade,
///
/// The Cluster Bomb weapon.
///
ClusterBomb,
///
/// The Skunk weapon.
///
Skunk,
///
/// The Petrol Bomb weapon.
///
PetrolBomb,
///
/// The Banana Bomb weapon.
///
BananaBomb,
///
/// The Handgun weapon.
///
Handgun,
///
/// The Shotgun weapon.
///
Shotgun,
///
/// The Uzi weapon.
///
Uzi,
///
/// The Minigun weapon.
///
Minigun,
///
/// The Longbow weapon.
///
Longbow,
///
/// The Airstrike weapon.
///
Airstrike,
///
/// The Napalm Strike weapon.
///
NapalmStrike,
///
/// The Mine weapon.
///
Mine,
///
/// The Firepunch weapon.
///
Firepunch,
///
/// The Dragonball weapon.
///
Dragonball,
///
/// The Kamikaze weapon.
///
Kamikaze,
///
/// The Prod weapon.
///
Prod,
///
/// The Battle Axe weapon.
///
BattleAxe,
///
/// The Blowtorch weapon.
///
Blowtorch,
///
/// The Pneumatic Drill weapon.
///
PneumaticDrill,
///
/// The Girder weapon.
///
Girder,
///
/// The Ninja Rope weapon.
///
NinjaRope,
///
/// The Parachute weapon.
///
Parachute,
///
/// The Bungee weapon.
///
Bungee,
///
/// The Teleport weapon.
///
Teleport,
///
/// The Dynamite weapon.
///
Dynamite,
///
/// The Sheep weapon.
///
Sheep,
///
/// The Baseball Bat weapon.
///
BaseballBat,
///
/// The Flame Thrower weapon.
///
Flamethrower,
///
/// The Homing Pigeon weapon.
///
HomingPigeon,
///
/// The Mad Cow weapon.
///
MadCow,
///
/// The Holy Hand Grenade weapon.
///
HolyHandGrenade,
///
/// The Old Woman weapon.
///
OldWoman,
///
/// The Sheep Launcher weapon.
///
SheepLauncher,
///
/// The Super Sheep or Aqua Sheep weapon.
///
SuperSheep,
///
/// The Mole Bomb weapon.
///
MoleBomb,
///
/// The Jetpack utility.
///
Jetpack,
///
/// The Low Gravity utility.
///
LowGravity,
///
/// The Laser Sight utility.
///
LaserSight,
///
/// The Fast Walk utility.
///
FastWalk,
///
/// The Invisibility utility.
///
Invisibility,
///
/// The Suicide Bomber weapon.
///
SuicideBomber,
///
/// The Worm Select utility.
///
WormSelect
}
}