Skip to content

Commit

Permalink
Progress on Export
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoromisato committed Dec 26, 2023
1 parent 6c06b20 commit 19ce52a
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Mammoth/Include/TSEShipClass.h
Expand Up @@ -450,7 +450,7 @@ class CShipClass : public CDesignType
int GetRotationAngle (void) { return m_Perf.GetIntegralRotationDesc().GetFrameAngle(); }
const CRotationDesc &GetRotationDesc (void) const { return m_Perf.GetRotationDesc(); }
int GetRotationRange (void) { return m_Perf.GetIntegralRotationDesc().GetFrameCount(); }
int GetScore (void) { return m_iScore; }
int GetScore (void) const { return m_iScore; }
DWORD GetShipNameFlags (void) { return m_dwShipNameFlags; }
CString GetShortName (void) const;
const CShipStandard &GetStandard (void) const;
Expand Down
187 changes: 187 additions & 0 deletions Transcendence/TransData/CExportProcess.cpp
@@ -0,0 +1,187 @@
// CExportProcess.cpp
//
// CExportProcess class
// Copyright (c) 2023 Kronosaur Productions, LLC. All Rights Reserved.

#include "PreComp.h"

#define ATTRIB_INSTALLATION CONSTLIT("installation")
#define ATTRIB_OUTPUT CONSTLIT("output")

#define FILENAME_SHIP_CLASSES_CSV CONSTLIT("ShipClasses.csv")

#define INSTALLATION_CORE CONSTLIT("core")

#define PROPERTY_BALANCE_TYPE CONSTLIT("balance.type")
#define PROPERTY_FUEL_EFFICIENCY CONSTLIT("fuelEfficiency")
#define PROPERTY_MANEUVER CONSTLIT("maneuver")
#define PROPERTY_MASS CONSTLIT("mass")
#define PROPERTY_MAX_SPEED CONSTLIT("maxSpeed")
#define PROPERTY_POWER CONSTLIT("power")
#define PROPERTY_THRUST CONSTLIT("thrust")

bool CExportProcess::ParseOptions (const CXMLElement& CmdLine, SOptions& retOptions)

// ParseOptions
//
// Parses options; returns FALSE if there is an error.

{
retOptions = SOptions();
retOptions.sInstallation = CmdLine.GetAttribute(ATTRIB_INSTALLATION);
if (retOptions.sInstallation.IsBlank())
retOptions.sInstallation = INSTALLATION_CORE;

retOptions.sOutputFolder = CmdLine.GetAttribute(ATTRIB_OUTPUT);
if (retOptions.sOutputFolder.IsBlank())
retOptions.sOutputFolder = CONSTLIT("Export");

return true;
}

ALERROR CExportProcess::Run ()

// Run
//
// Runs the process.

{
CFileWriteStream ShipClassesFile(ComposeOutputFilespec(FILENAME_SHIP_CLASSES_CSV));
if (ShipClassesFile.Create() != NOERROR)
{
printf("ERROR: Unable to create output file: %s\n", FILENAME_SHIP_CLASSES_CSV.GetASCIIZPointer());
return ERR_FAIL;
}

WriteShipClasses(ShipClassesFile);

return NOERROR;
}

void CExportProcess::WriteShipClasses (IWriteStream& Output)

// ShipClasses.csv
//
// Installation String "core" or some extension group
// UNID Integer Unique ID in Installation
// Manufacturer String E.g., "Pacific Defense Systems"
// ClassName String E.g., "Centurion"
// TypeName String E.g., "gunship"
// Image String "Image.png|128x128|12x10x1|0,0"
// HeroImage String "Image.png|320x320|1x1x1|0,0"
// Tags String Comma-separated list of tags
// Sovereign Integer Default sovereign UNID
// Level Integer Level of ship
//
// LevelType String "minion", "standard", "boss", etc.
// CombatStrength Float Relative strength
// Score Integer Score of ship
// Length Integer Length in meters
// MassT Integer Total mass in metric tons
// Maneuverability Float Maneuverability (degrees per tick)
// Thrust Integer Thrust in tons
// MaxSpeed Integer Max speed in % of c
// ReactorPower Integer Reactor power in 1/10th MW
// MaxFuel Float Max fuel units
//
// FuelConsumption Float Fuel units consumed per tick per 1/10th MW.
// CargoSpaceT Integer Cargo space in tons
// HullMassT Integer Hull mass in metric tons
// HullValue String Price in some currency (e.g., "1000 credit")
// HullCargoSpaceT Integer Cargo space in tons
// MaxCargoSpaceT Integer Max cargo space in tons
// StdArmorMassT Integer Standard armor mass in tons (no penalty)
// MaxArmorMassT Integer Max armor mass in tons
// MaxArmorSpeedAdj Integer Speed penalty (1/100th of c) at max armor
// MinArmorSpeedAdj Integer Speed bonus (1/100th of c) at 1/2 std armor
//
// MaxDevices Integer Max number of devices
// MaxWeapons Integer Max number of weapons
// MaxNonWeapons Integer Max number of non-weapons
// MaxReactorPower Integer Max reactor power (in 1/10th MW)
// TotalInteriorHP Integer Total interior HP
// ArmorSegments String Comma-separated list of armor segment angles
// ArmorUNIDs String Comma-separated list of armor UNIDs
// DeviceSlots String Comma-separated list of device slot descriptors
// DeviceUNIDs String Comma-separated list of device UNIDs
// AmmoUNIDs String Comma-separated list of ammo UNIDs and counts

{
// Write the header first.

CString sHeaders("Installation,UNID,Manufacturer,ClassName,TypeName,Image,HeroImage,Tags,Sovereign,Level,"
"LevelType,CombatStrength,Score,Length,MassT,Maneuverability,Thrust,MaxSpeed,ReactorPower,MaxFuel,"
"FuelConsumption,CargoSpaceT,HullMassT,HullValue,HullCargoSpaceT,MaxCargoSpaceT,StdArmorMassT,MaxArmorMassT,MaxArmorSpeedAdj,MinArmorSpeedAdj,"
"MaxDevices,MaxWeapons,MaxNonWeapons,MaxReactorPower,TotalInteriorHP,ArmorSegments,ArmorUNIDs,DeviceSlots,DeviceUNIDs,AmmoUNIDs\r\n");

Output.Write(sHeaders.GetASCIIZPointer(), sHeaders.GetLength());

// Now write all the record.

for (int i = 0; i < m_Universe.GetShipClassCount(); i++)
{
const CShipClass& Class = *m_Universe.GetShipClass(i);

// Only include generic classes

if (!Class.HasLiteralAttribute(CONSTLIT("genericClass")))
continue;

// Generate the record

CString sRecord = strPatternSubst(CONSTLIT("%s,0x%08x,%s,%s,%s,%s,%s,%s,0x%08x,%d,"
"%s,%s,%d,%d,%d,%d,%d,%d,%d,%S,"
"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,"
"%d,%d,%d,%d,%d,%d,%s,%s,%s,%s,%s\r\n"),
m_Options.sInstallation,
Class.GetUNID(),
Class.GetManufacturerName(),
Class.GetNounPhrase(nounGeneric),
Class.GetNounPhrase(nounShort | nounNoModifiers),
Class.GetImage().GetFilename(), // LATER
Class.GetHeroImage().GetFilename(), // LATER
CString(), // LATER
Class.GetDefaultSovereign()->GetUNID(),
Class.GetLevel(),

Class.GetPropertyString(PROPERTY_BALANCE_TYPE),
strFromDouble((double)Class.GetCombatStrength()),
Class.GetScore(),
Class.GetHullDesc().GetSize(),
Class.GetPropertyInteger(PROPERTY_MASS),
Class.GetPropertyInteger(PROPERTY_MANEUVER),
Class.GetPropertyInteger(PROPERTY_THRUST),
Class.GetPropertyInteger(PROPERTY_MAX_SPEED),
Class.GetPropertyInteger(PROPERTY_POWER),
strFromDouble((double)Class.GetReactorDesc().GetFuelCapacity()),

Class.GetPropertyInteger(PROPERTY_FUEL_EFFICIENCY),
Class.GetCargoDesc().GetCargoSpace(),
Class.GetHullDesc().GetMass(),
Class.GetHullValue(),
Class.GetHullDesc().GetCargoSpace(),
Class.GetHullDesc().GetMaxCargoSpace(),
Class.GetHullDesc().GetArmorLimits().GetStdArmorMass(),
Class.GetHullDesc().GetArmorLimits().GetMaxArmorMass(),
Class.GetHullDesc().GetArmorLimits().GetMaxArmorSpeedPenalty(),
Class.GetHullDesc().GetArmorLimits().GetMinArmorSpeedBonus(),

Class.GetHullDesc().GetMaxDevices(),
Class.GetHullDesc().GetMaxWeapons(),
Class.GetHullDesc().GetMaxNonWeapons(),
Class.GetHullDesc().GetMaxReactorPower(),
Class.GetInteriorDesc().GetHitPoints(),
strFromInt(Class.GetArmorDesc().GetCount()), // LATER
CString(), // LATER
CString(), // LATER
CString(), // LATER
CString()); // LATER

Output.Write(sRecord.GetASCIIZPointer(), sRecord.GetLength());
}
}

CString CExportProcess::ComposeOutputFilespec (const CString& sFilename) const
{
return pathAddComponent(pathAddComponent(m_Options.sOutputFolder, m_Options.sInstallation), sFilename);
}
1 change: 1 addition & 0 deletions Transcendence/TransData/ExportData.cpp
Expand Up @@ -88,4 +88,5 @@

void ExportData (CUniverse& Universe, const CXMLElement& CmdLine)
{
printf("Exporting data...\n");
}
33 changes: 33 additions & 0 deletions Transcendence/TransData/ExportProcess.h
@@ -0,0 +1,33 @@
// ExportProcess.h
//
// CExportProcess class definition. This class is used to export a game
// Copyright (c) 2023 Kronosaur Productions, LLC. All Rights Reserved.

#pragma once

class CExportProcess
{
public:

struct SOptions
{
CString sOutputFolder; // Output folder
CString sInstallation; // Expansion group ID
};

static bool ParseOptions (const CXMLElement& CmdLine, SOptions& retOptions);

CExportProcess (CUniverse &Universe, const SOptions& Options) :
m_Universe(Universe), m_Options(Options)
{ }

ALERROR Run ();

private:

CString ComposeOutputFilespec (const CString& sFilename) const;
void WriteShipClasses (IWriteStream& Output);

CUniverse &m_Universe;
SOptions m_Options;
};
2 changes: 2 additions & 0 deletions Transcendence/TransData/TransData.h
Expand Up @@ -146,6 +146,8 @@ struct SDesignTypeInfo

typedef TSortMap<DWORD, SDesignTypeInfo> CDesignTypeStats;

#include "ExportProcess.h"

// Functions

const char *FrequencyChar (int iFreq);
Expand Down
2 changes: 2 additions & 0 deletions Transcendence/TransData/TransData.vcxproj
Expand Up @@ -397,6 +397,7 @@
<ClCompile Include="Attributes.cpp" />
<ClCompile Include="BattleSim.cpp" />
<ClCompile Include="CCTransDataLibrary.cpp" />
<ClCompile Include="CExportProcess.cpp" />
<ClCompile Include="CHost.cpp" />
<ClCompile Include="CImageGrid.cpp" />
<ClCompile Include="CItemInfoTable.cpp" />
Expand Down Expand Up @@ -569,6 +570,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Diagnostics.h" />
<ClInclude Include="ExportProcess.h" />
<ClInclude Include="ItemBenchmarks.h" />
<ClInclude Include="PreComp.h" />
<ClInclude Include="Reference.h" />
Expand Down
11 changes: 10 additions & 1 deletion Transcendence/TransData/TransData.vcxproj.filters
Expand Up @@ -19,6 +19,9 @@
<Filter Include="TLisp Files">
<UniqueIdentifier>{44ee7372-84e8-4e57-879b-9be2fbbf64a4}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CmdExport">
<UniqueIdentifier>{f6669012-c7ee-4709-936a-6a7567fb2d94}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Armor.cpp">
Expand Down Expand Up @@ -207,8 +210,11 @@
<ClCompile Include="Achievements.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CExportProcess.cpp">
<Filter>Source Files\CmdExport</Filter>
</ClCompile>
<ClCompile Include="ExportData.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\CmdExport</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand All @@ -233,6 +239,9 @@
<ClInclude Include="Diagnostics.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ExportProcess.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TransData.rc">
Expand Down

0 comments on commit 19ce52a

Please sign in to comment.