Subversion Repositories spk

Rev

Rev 127 | Rev 166 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef _XSPFILE_H__
#define _XSPFILE_H__

#include "BaseFile.h"
#include "ShipData.h"
#include "StringList.h"
#include "VirtualFileSystem.h"

class CCatFile;

#define SHIPYARD_NONE             0
#define SHIPYARD_ARGON            1
#define SHIPYARD_BORON            2
#define SHIPYARD_PARANID          4
#define SHIPYARD_SPLIT            8
#define SHIPYARD_TELADI          16
#define SHIPYARD_PIRATES         32
#define SHIPYARD_FRIEND          64
#define SHIPYARD_XENON          128
#define SHIPYARD_TERRAN         256
#define SHIPYARD_ATF            512
#define SHIPYARD_YAKI           1024

#define SHIPYARD_MAX    SHIPYARD_TERRAN

enum {TAT_NONE, TAT_SINGLE, TAT_3};

#define TSHIPPOS_CLASS          53

enum {IMPORTSHIP_NONE, IMPORTSHIP_SCENE, IMPORTSHIP_EXTRACTSCENE, IMPORTSHIP_DUMMIES, IMPORTSHIP_COMPONANT, IMPORTSHIP_MODELS, IMPORTSHIP_TEXTURES, IMPORTSHIP_TEXTS, IMPORTSHIP_BODIES, IMPORTSHIP_COCKPITS, IMPORTSHIP_PACK, IMPORTSHIP_DONE};

int              SPKEXPORT GetMaxShipyards ();
Utils::String SPKEXPORT GetShipyardName (int s);

typedef struct STypesSection {
        Utils::String           sSection;
        Utils::CStringList      lEntries;
} STypesSection2;

typedef struct SComponentEntry {
        Utils::String           sSection;
        Utils::CList<STypesSection> lEntries;
} SComponentEntry;

typedef struct SWeaponMask {
        int             iMask;
        int             iGame;
} SWeaponMask;

typedef struct SText
{
        int             iId;
        Utils::String sName;
        Utils::String sDesc;
} SText;

typedef struct SDummy
{
        Utils::String   sSection;
        Utils::String sData;
} SDummy;

typedef struct SComponent
{
        Utils::String sSection;
        Utils::String sSection2;
        Utils::String sData;
} SComponent;

typedef struct SCockpit
{
        Utils::String      sCockpit;
        CLinkList<SWeaponMask> lWeaponMask;
        int                             iIndex;
} SCockpit;

using namespace SPK;

class SPKEXPORT CXspFile : public CBaseFile
{
public:
        CXspFile ();
        ~CXspFile () { this->Delete(); }

        static bool ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord);
        static int GetAnimationType(const Utils::String &sType);
        static Utils::String TypesListToString(Utils::CList<STypesSection> &list, bool deleteAfter = false);

        bool WriteHeader(CFileIO &file, int iHeader, int iLength);

        bool IsLanguageText () { return m_bLanguageText; }
        bool IsExistingShip () { return m_bExistingShip; }

        int  GetOriginalDescription () { return m_iOrgDesc; }
        int  GetShipyards () { return m_iShipyard; }

        const Utils::String &GetShipID () const { return m_sID; }
        const Utils::String &GetShipData () const { return m_sData; }
        Utils::String GetX3ShipData();
        Utils::String GetTCShipData();
        Utils::String GetShipFilename () 
        { 
                Utils::String s = this->name() + "-" + this->author(); 
                s = s.remove(' ');
                s = s.remove('\\');
                s = s.remove('/');
                return s;
        }

        SText *FindShipText(int lang);
        Utils::String GetTextName(int lang);
        Utils::String GetTextDescription(int lang);

        void SetLanguageText            ( bool b )   { m_bLanguageText = b; _changed(); }
        void SetExistingShip            ( bool b )   { m_bExistingShip = b; _changed(); }
        void SetOriginalDescription     ( int i )        { m_iOrgDesc = i; _changed();; }
        void SetShipID                          (const Utils::String &sId ) { m_sID = sId; _changed();; }
        void SetShipData                        (const Utils::String &sData ) { m_sData = sData; _changed(); }

        void SetSceneFile ( C_File *f ) { m_pSceneFile = f; }
        void SetCockpitFile ( C_File *f ) { m_pCockpitFile = f; }

        void AddAnimation(CyStringList *list);
        void AddAnimation(const Utils::String &data) { m_lAnimations.PushBack(CyString(data), true); _changed(); }
        void AddBodies(const Utils::String &data);
        void AddBody(const Utils::String &section, const Utils::String &data);
        void AddCutData(const Utils::String &data) { m_lCutData.PushBack(CyString(data), true); _changed(); }
        void AddText(int id, const Utils::String &name, const Utils::String &desc );
        void AddCockpit(const Utils::String &cockpit, int game, int mask = -1, int index = -1 );
        void AddCockpitWeapon(const Utils::String &cockpit, int game, int mask);
        void NewCockpit(const Utils::String &id, const Utils::String &scene, int mask );
        void EditCockpit(const Utils::String &id, const Utils::String &cockpit);
        void EditCockpit(const Utils::String &id, const Utils::String &scene, int mask);
        Utils::String GetCockpitData(const Utils::String &id);
        SCockpit *FindCockpit(const Utils::String &id);
        void AddDummy(const Utils::String &section, const Utils::String &data );
        void AddComponent(const Utils::String &section, const Utils::String &section2, const Utils::String &data );
        void AddWeaponMask(int game, int mask );
        void AddMissileMask(int game, int mask );
        void RemoveText(int id);
        void ClearText() { m_lText.MemoryClear(); _changed(); }

        void AddShipyard ( int s ) { m_iShipyard |= s; _changed(); }
        void RemoveShipyard ( int s ) { m_iShipyard &= ~(s); _changed(); }
        void SetShipyard(int s, bool b) { if ( b ) AddShipyard(s); else RemoveShipyard(s); }
        void ToggleShipyard(int s) { if ( this->IsShipyard(s) ) RemoveShipyard(s); else AddShipyard(s); }

        bool RemoveCutData(const Utils::String &cut);
        bool RemoveCockpit(const Utils::String &cockpitid);
        bool RemoveComponent(const Utils::String &section1, const Utils::String &section2, const Utils::String &data);
        bool RemoveDummy(const Utils::String &section, const Utils::String &data);
        bool RemoveBodies(const Utils::String &body);
        bool RemoveAnimation(const Utils::String &ani);

        bool IsSigned() { return false; }
        bool IsValid ();
        bool IsShipyard(int s) { return (m_iShipyard & s) ? true : false; }
        bool AnyShipyards() { return (m_iShipyard > 0) ? true : false; }
        void AdjustCockpits();
        virtual Utils::String CreateValuesLine () const;
        virtual bool ParseValueLine(const Utils::String &line);

        virtual int GetType () { return TYPE_XSP; }

        Utils::String GetShipName(int lang);
        bool ConvertOld(const Utils::String &file);

        CyStringList *GetAnimations() { return &m_lAnimations; }
        CyStringList *GetCutData() { return &m_lCutData; }
        CyStringList *GetBodies() { return &m_lBodies; }
        CLinkList<SWeaponMask> *GetLaserMasks() { return &m_lWeaponMasks; }
        CLinkList<SWeaponMask> *GetMissileMasks() { return &m_lMissileMasks; }
        CLinkList<SText> *GetTexts() { return &m_lText; }
        CLinkList<SDummy> *GetDummies() { return &m_lDummy; }
        CLinkList<SComponent> *GetComponents() { return &m_lComponent; }
        CLinkList<SCockpit> *GetCockpits() { return &m_lCockpit; }
        int GetLaserMask(int game, bool getOnly = false);
        int GetMissileMask(int game, bool getOnly = false);
        void SetLaserMask(int game, int mask);
        void SetMissileMask(int game, int mask);

        void SetCreatedShipData(CShipData *data) { m_sData = data->CreateData().ToString(); }
        bool AnyTexts() { return !m_lText.empty(); }
        bool AnyDummies() { return !m_lDummy.empty(); }
        bool AnyComponents() { return !m_lComponent.empty(); }
        bool AnyCockpits() { return !m_lCockpit.empty(); }
        bool AnyCutData() { return !m_lCutData.Empty(); }
        bool AnyBodies() { return !m_lBodies.Empty(); }
        bool AnyAnimations() { return !m_lAnimations.Empty(); }

        Utils::String GetShipClass();
        bool UpdateSigned(bool updateFiles) { m_bSigned = false; return false; }

        // ship extraction
        bool startExtractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *pProgress);
        bool extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress);
        bool extractSceneFiles(CVirtualFileSystem *pVfs);
        void extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
        void extractCutData(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
        void extractDummies(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add);
        void extractTextures(CVirtualFileSystem *pVfs);
        bool extractBodies(CVirtualFileSystem *pVfs, CyStringList *sceneModels);
        bool extractCockpits(CVirtualFileSystem *pVfs);

        void addComponentsToList(CLinkList<SComponentEntry> &componentList);
        void addDummiesToList(Utils::CList<STypesSection> &list);
        void addCutDataToList(Utils::CList<STypesSection> &list);
        void addBodiesToList(Utils::CList<STypesSection> &list);
        void addAnimationsToList(Utils::CList<STypesSection> &list);

        bool processSceneFileSection(int section, CVirtualFileSystem *pVfs, CyStringList *lModels, CProgressInfo *progress);
        bool processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress);

        void PackAllFiles();
        CyStringList *ReadSceneModels();

        //TODO: convert this
        void ExtractTexts(CCatFile *catFile, CCatFile *secondCatFile, int textId);

        bool GetTextureList(CyStringList *list, const unsigned char *olddata, size_t size);
        bool AddTextFromFile(const Utils::String &file, int textId = -1);
        bool ImportBodies(CyStringList *sceneModels, const Utils::String &filename);
        bool ImportCockpits(const Utils::String &filename);
        Utils::String FormatShipData(CyStringList *cockpits, int *text, int game);

        virtual bool LoadPackageData(const Utils::String &sFfirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress = NULL) override;
        virtual bool GeneratePackagerScript(bool wildcard, Utils::CStringList *list, int game, const Utils::CStringList &gameAddons, bool datafile = false) override;
        virtual void addGeneratedFiles(HZIP &hz);

protected:
        virtual void Delete ();
        virtual void SetDefaults ();
        virtual bool CheckHeader(const Utils::String header) const;
        SCockpit *_findCockpit(const Utils::String &sID);
        void _addSection(Utils::CList<STypesSection> &list, const Utils::String &section, const Utils::String &data);
        void _addDataSection(CyStringList &list, Utils::CList<STypesSection> &sectionList, bool bUseFirst);
        bool _addTextFromFile(CFileIO &F, int textId = -1);

protected:
        C_File *m_pSceneFile, *m_pCockpitFile;

        bool m_bLanguageText, m_bExistingShip;

        int m_iOrgDesc;

        Utils::String m_sID;
        Utils::String m_sData;

        CyStringList                    m_lCutData;
        CyStringList                    m_lBodies;
        CyStringList                    m_lAnimations;
        CLinkList<SCockpit>             m_lCockpit;
        CLinkList<SText>                m_lText;
        CLinkList<SComponent>   m_lComponent;
        CLinkList<SDummy>               m_lDummy;
        CLinkList<SWeaponMask>  m_lWeaponMasks;
        CLinkList<SWeaponMask>  m_lMissileMasks;

        int m_iShipyard;
};

#endif //_XSPFILE_H__