Skip to content

Commit

Permalink
Use section numbers to uniquely identify sections and add FnRemoveSec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Fulgen301 committed Nov 17, 2023
1 parent 5ef865b commit 9148c58
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/C4Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ void C4Console::OnPlrQuit(GtkWidget *item, gpointer data)
const std::int32_t playerNumber{GPOINTER_TO_INT(data)};
C4Player *const player{Game.Players.Get(playerNumber)};

Game.Control.Input.Add(CID_EliminatePlayer, new C4ControlEliminatePlayer(Game.GetSectionIndex(**player->ViewSection), GPOINTER_TO_INT(data)));
Game.Control.Input.Add(CID_EliminatePlayer, new C4ControlEliminatePlayer(player->ViewSection->Number, GPOINTER_TO_INT(data)));
}

void C4Console::OnViewNew(GtkWidget *item, gpointer data)
Expand Down
24 changes: 12 additions & 12 deletions src/C4Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void C4ControlScript::Execute() const
}
}

C4Section *const section{Game.GetSectionByIndex(sectionIndex)};
C4Section *const section{Game.GetSectionByNumber(sectionNumber)};
if (!section)
{
return;
Expand Down Expand Up @@ -317,7 +317,7 @@ void C4ControlScript::Execute() const

void C4ControlScript::CompileFunc(StdCompiler *pComp)
{
pComp->Value(mkNamingAdapt(mkIntPackAdapt(sectionIndex) , "Section", 0));
pComp->Value(mkNamingAdapt(mkIntPackAdapt(sectionNumber) , "Section", 0));
pComp->Value(mkNamingAdapt(iTargetObj, "TargetObj", -1));
pComp->Value(mkNamingAdapt(Strict, "Strict", C4AulScriptStrict::MAXSTRICT));

Expand Down Expand Up @@ -871,9 +871,9 @@ void C4ControlJoinPlayer::CompileFunc(StdCompiler *pComp)

// *** C4ControlEMMoveObject

C4ControlEMMoveObject::C4ControlEMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int32_t ty, const std::int32_t sectionIndex, C4Object *pTargetObj,
C4ControlEMMoveObject::C4ControlEMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int32_t ty, const std::uint32_t sectionNumber, C4Object *pTargetObj,
int32_t iObjectNum, int32_t *pObjects, const char *szScript, const C4AulScriptStrict strict)
: eAction(eAction), tx(tx), ty(ty), sectionIndex{sectionIndex}, iTargetObj(Game.ObjectNumber(pTargetObj)),
: eAction(eAction), tx(tx), ty(ty), sectionNumber{sectionNumber}, iTargetObj(Game.ObjectNumber(pTargetObj)),
iObjectNum(iObjectNum), Strict{strict}, pObjects(pObjects), Script(szScript, true) {}

C4ControlEMMoveObject::~C4ControlEMMoveObject()
Expand Down Expand Up @@ -940,7 +940,7 @@ void C4ControlEMMoveObject::Execute() const
{
if (!pObjects) return;
// execute script ...
C4ControlScript ScriptCtrl(sectionIndex, Script.getData(), C4ControlScript::SCOPE_Global, Strict);
C4ControlScript ScriptCtrl(sectionNumber, Script.getData(), C4ControlScript::SCOPE_Global, Strict);
ScriptCtrl.SetByClient(iByClient);
// ... for each object in selection
for (int i = 0; i < iObjectNum; ++i)
Expand Down Expand Up @@ -981,7 +981,7 @@ void C4ControlEMMoveObject::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(mkIntAdaptT<uint8_t>(eAction), "Action"));
pComp->Value(mkNamingAdapt(tx, "tx", 0));
pComp->Value(mkNamingAdapt(ty, "ty", 0));
pComp->Value(mkNamingAdapt(mkIntPackAdapt(sectionIndex), "Section", 0));
pComp->Value(mkNamingAdapt(mkIntPackAdapt(sectionNumber), "Section", 0));
pComp->Value(mkNamingAdapt(iTargetObj, "TargetObj", -1));
pComp->Value(mkNamingAdapt(mkIntPackAdapt(iObjectNum), "ObjectNum", 0));
pComp->Value(mkNamingAdapt(Strict, "Strict", C4AulScriptStrict::MAXSTRICT));
Expand All @@ -1003,17 +1003,17 @@ void C4ControlEMMoveObject::CompileFunc(StdCompiler *pComp)

C4ControlEMDrawTool::C4ControlEMDrawTool(C4ControlEMDrawAction eAction, int32_t iMode,
int32_t iX, int32_t iY, int32_t iX2, int32_t iY2, int32_t iGrade,
bool fIFT, int32_t SectionIndex, const char *szMaterial, const char *szTexture)
bool fIFT, const std::uint32_t sectionNumber, const char *szMaterial, const char *szTexture)
: eAction(eAction), iMode(iMode), iX(iX), iY(iY), iX2(iX2), iY2(iY2), iGrade(iGrade),
fIFT(fIFT), SectionIndex{SectionIndex}, Material(szMaterial, true), Texture(szTexture, true) {}
fIFT(fIFT), sectionNumber{sectionNumber}, Material(szMaterial, true), Texture(szTexture, true) {}

void C4ControlEMDrawTool::Execute() const
{
// Ignore in league mode
if (Game.Parameters.isLeague())
return;

C4Section *section{Game.GetSectionByIndex(SectionIndex)};
C4Section *section{Game.GetSectionByNumber(sectionNumber)};
if (!section)
{
return;
Expand Down Expand Up @@ -1078,7 +1078,7 @@ void C4ControlEMDrawTool::CompileFunc(StdCompiler *pComp)
pComp->Value(mkNamingAdapt(iY2, "Y2", 0));
pComp->Value(mkNamingAdapt(mkIntPackAdapt(iGrade), "Grade", 0));
pComp->Value(mkNamingAdapt(fIFT, "IFT", false));
pComp->Value(mkNamingAdapt(SectionIndex, "Section", 0));
pComp->Value(mkNamingAdapt(sectionNumber, "Section", 0));
pComp->Value(mkNamingAdapt(Material, "Material", ""));
pComp->Value(mkNamingAdapt(Texture, "Texture", ""));
C4ControlPacket::CompileFunc(pComp);
Expand Down Expand Up @@ -1547,7 +1547,7 @@ void C4ControlInternalScriptBase::Execute() const
{
if (!Allowed()) return;

C4Section *const section{Game.GetSectionByIndex(sectionIndex)};
C4Section *const section{Game.GetSectionByNumber(sectionNumber)};
if (!section)
{
return;
Expand All @@ -1571,7 +1571,7 @@ void C4ControlInternalScriptBase::Execute() const

void C4ControlInternalScriptBase::CompileFunc(StdCompiler *const comp)
{
comp->Value(mkNamingAdapt(mkIntPackAdapt(sectionIndex), "Section", -1));
comp->Value(mkNamingAdapt(mkIntPackAdapt(sectionNumber), "Section", -1));
C4ControlPacket::CompileFunc(comp);
}

Expand Down
40 changes: 20 additions & 20 deletions src/C4Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ class C4ControlScript : public C4ControlPacket // sync

C4ControlScript()
: iTargetObj(-1) {}
C4ControlScript(const std::int32_t sectionIndex, const char *szScript, int32_t iTargetObj = SCOPE_Global, C4AulScriptStrict strict = C4AulScriptStrict::MAXSTRICT)
: sectionIndex{sectionIndex}, iTargetObj(iTargetObj), Strict{strict}, Script(szScript, true) {}
C4ControlScript(const std::uint32_t sectionNumber, const char *szScript, int32_t iTargetObj = SCOPE_Global, C4AulScriptStrict strict = C4AulScriptStrict::MAXSTRICT)
: sectionNumber{sectionNumber}, iTargetObj(iTargetObj), Strict{strict}, Script(szScript, true) {}

protected:
std::int32_t sectionIndex;
std::uint32_t sectionNumber;
int32_t iTargetObj;
C4AulScriptStrict Strict;
StdStrBuf Script;
Expand Down Expand Up @@ -346,14 +346,14 @@ class C4ControlEMMoveObject : public C4ControlPacket // sync
{
public:
C4ControlEMMoveObject() : pObjects(nullptr) {}
C4ControlEMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int32_t ty, std::int32_t sectionIndex, C4Object *pTargetObj,
C4ControlEMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int32_t ty, std::uint32_t sectionNumber, C4Object *pTargetObj,
int32_t iObjectNum = 0, int32_t *pObjects = nullptr, const char *szScript = nullptr, C4AulScriptStrict strict = C4AulScriptStrict::MAXSTRICT);
~C4ControlEMMoveObject();

protected:
C4ControlEMObjectAction eAction; // action to be performed
int32_t tx, ty; // target position
std::int32_t sectionIndex{}; // section index
std::uint32_t sectionNumber{}; // section index
int32_t iTargetObj; // enumerated ptr to target object
int32_t iObjectNum; // number of objects moved
C4AulScriptStrict Strict; // strictness for the script to execute
Expand All @@ -379,14 +379,14 @@ class C4ControlEMDrawTool : public C4ControlPacket // sync
C4ControlEMDrawTool() {}
C4ControlEMDrawTool(C4ControlEMDrawAction eAction, int32_t iMode,
int32_t iX = -1, int32_t iY = -1, int32_t iX2 = -1, int32_t iY2 = -1, int32_t iGrade = -1,
bool fIFT = true, std::int32_t SectionIndex = 0, const char *szMaterial = nullptr, const char *szTexture = nullptr);
bool fIFT = true, std::uint32_t sectionNumber = 0, const char *szMaterial = nullptr, const char *szTexture = nullptr);

protected:
C4ControlEMDrawAction eAction; // action to be performed
int32_t iMode; // new mode, or mode action was performed in (action will fail if changed)
int32_t iX, iY, iX2, iY2, iGrade; // drawing parameters
bool fIFT; // sky/tunnel-background
std::int32_t SectionIndex; // section index
std::uint32_t sectionNumber; // section index
StdStrBuf Material; // used material
StdStrBuf Texture; // used texture

Expand Down Expand Up @@ -502,7 +502,7 @@ class C4ControlInternalScriptBase : public C4ControlPacket
{
public:
C4ControlInternalScriptBase() noexcept = default;
C4ControlInternalScriptBase(const std::int32_t sectionIndex) noexcept : sectionIndex(sectionIndex) {}
C4ControlInternalScriptBase(const std::uint32_t sectionNumber) noexcept : sectionNumber(sectionNumber) {}
public:
virtual int32_t Scope() const { return C4ControlScript::SCOPE_Global; }
virtual bool Allowed() const { return true; }
Expand All @@ -511,7 +511,7 @@ class C4ControlInternalScriptBase : public C4ControlPacket
DECLARE_C4CONTROL_VIRTUALS

private:
std::int32_t sectionIndex{};
std::uint32_t sectionNumber{};
};

class C4ControlEMDropDef : public C4ControlInternalScriptBase
Expand All @@ -522,7 +522,7 @@ class C4ControlEMDropDef : public C4ControlInternalScriptBase

public:
C4ControlEMDropDef() {}
C4ControlEMDropDef(const std::int32_t sectionIndex, C4ID id, int32_t x, int32_t y) : C4ControlInternalScriptBase{sectionIndex}, id(id), x(x), y(y) {}
C4ControlEMDropDef(const std::uint32_t sectionNumber, C4ID id, int32_t x, int32_t y) : C4ControlInternalScriptBase{sectionNumber}, id(id), x(x), y(y) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual bool Allowed() const override;
virtual StdStrBuf FormatScript() const override;
Expand All @@ -535,7 +535,7 @@ class C4ControlInternalPlayerScriptBase : public C4ControlInternalScriptBase

public:
C4ControlInternalPlayerScriptBase() {}
C4ControlInternalPlayerScriptBase(const std::int32_t sectionIndex, int32_t plr) : C4ControlInternalScriptBase{sectionIndex}, plr(plr) {}
C4ControlInternalPlayerScriptBase(const std::uint32_t sectionNumber, int32_t plr) : C4ControlInternalScriptBase{sectionNumber}, plr(plr) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual bool Allowed() const override;
};
Expand All @@ -547,7 +547,7 @@ class C4ControlMessageBoardAnswer : public C4ControlInternalPlayerScriptBase

public:
C4ControlMessageBoardAnswer() {}
C4ControlMessageBoardAnswer(const std::int32_t sectionIndex, int32_t obj, int32_t plr, const std::string &answer) : C4ControlInternalPlayerScriptBase{sectionIndex, plr}, obj(obj), answer(answer) {}
C4ControlMessageBoardAnswer(const std::uint32_t sectionNumber, int32_t obj, int32_t plr, const std::string &answer) : C4ControlInternalPlayerScriptBase{sectionNumber, plr}, obj(obj), answer(answer) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override;
};
Expand All @@ -559,7 +559,7 @@ class C4ControlCustomCommand : public C4ControlInternalPlayerScriptBase

public:
C4ControlCustomCommand() {}
C4ControlCustomCommand(const std::int32_t sectionIndex, int32_t plr, const std::string &command, const std::string &argument) : C4ControlInternalPlayerScriptBase(sectionIndex, plr), command(command), argument(argument) {}
C4ControlCustomCommand(const std::uint32_t sectionNumber, int32_t plr, const std::string &command, const std::string &argument) : C4ControlInternalPlayerScriptBase(sectionNumber, plr), command(command), argument(argument) {}
virtual bool Allowed() const override;
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override;
Expand All @@ -571,7 +571,7 @@ class C4ControlInitScenarioPlayer : public C4ControlInternalPlayerScriptBase

public:
C4ControlInitScenarioPlayer() {}
C4ControlInitScenarioPlayer(const std::int32_t sectionIndex, int32_t plr, int32_t team) : C4ControlInternalPlayerScriptBase(sectionIndex, plr), team(team) {}
C4ControlInitScenarioPlayer(const std::uint32_t sectionNumber, int32_t plr, int32_t team) : C4ControlInternalPlayerScriptBase(sectionNumber, plr), team(team) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override { return FormatString("InitScenarioPlayer(%d,%d)", static_cast<int>(plr), static_cast<int>(team)); }
};
Expand All @@ -580,7 +580,7 @@ class C4ControlActivateGameGoalMenu : public C4ControlInternalPlayerScriptBase
{
public:
C4ControlActivateGameGoalMenu() {}
C4ControlActivateGameGoalMenu(const std::int32_t sectionIndex, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionIndex, plr) {}
C4ControlActivateGameGoalMenu(const std::uint32_t sectionNumber, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionNumber, plr) {}
virtual StdStrBuf FormatScript() const override { return FormatString("ActivateGameGoalMenu(%d)", plr); }
};

Expand All @@ -590,7 +590,7 @@ class C4ControlToggleHostility : public C4ControlInternalPlayerScriptBase

public:
C4ControlToggleHostility() {}
C4ControlToggleHostility(const std::int32_t sectionIndex, int32_t plr, int32_t opponent) : C4ControlInternalPlayerScriptBase(sectionIndex, plr), opponent(opponent) {}
C4ControlToggleHostility(const std::uint32_t sectionNumber, int32_t plr, int32_t opponent) : C4ControlInternalPlayerScriptBase(sectionNumber, plr), opponent(opponent) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override { return FormatString("SetHostility(%d,%d,!Hostile(%d,%d,true))", plr, opponent, plr, opponent); }
};
Expand All @@ -599,7 +599,7 @@ class C4ControlSurrenderPlayer : public C4ControlInternalPlayerScriptBase
{
public:
C4ControlSurrenderPlayer() {}
C4ControlSurrenderPlayer(const std::int32_t sectionIndex, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionIndex, plr) {}
C4ControlSurrenderPlayer(const std::uint32_t sectionNumber, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionNumber, plr) {}
virtual StdStrBuf FormatScript() const override { return FormatString("SurrenderPlayer(%d)", plr); }
};

Expand All @@ -609,7 +609,7 @@ class C4ControlActivateGameGoalRule : public C4ControlInternalPlayerScriptBase

public:
C4ControlActivateGameGoalRule() {}
C4ControlActivateGameGoalRule(const std::int32_t sectionIndex, int32_t plr, int32_t obj) : C4ControlInternalPlayerScriptBase(sectionIndex, plr), obj(obj) {}
C4ControlActivateGameGoalRule(const std::uint32_t sectionNumber, int32_t plr, int32_t obj) : C4ControlInternalPlayerScriptBase(sectionNumber, plr), obj(obj) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override { return FormatString("Activate(%d)", plr); }
virtual int32_t Scope() const override { return obj; }
Expand All @@ -621,7 +621,7 @@ class C4ControlSetPlayerTeam : public C4ControlInternalPlayerScriptBase

public:
C4ControlSetPlayerTeam() {}
C4ControlSetPlayerTeam(const std::int32_t sectionIndex, int32_t plr, int32_t team) : C4ControlInternalPlayerScriptBase(sectionIndex, plr), team(team) {}
C4ControlSetPlayerTeam(const std::uint32_t sectionNumber, int32_t plr, int32_t team) : C4ControlInternalPlayerScriptBase(sectionNumber, plr), team(team) {}
virtual void CompileFunc(StdCompiler *pComp) override;
virtual StdStrBuf FormatScript() const override { return FormatString("SetPlayerTeam(%d,%d)", static_cast<int>(plr), static_cast<int>(team)); }
};
Expand All @@ -630,7 +630,7 @@ class C4ControlEliminatePlayer : public C4ControlInternalPlayerScriptBase
{
public:
C4ControlEliminatePlayer() {}
C4ControlEliminatePlayer(const std::int32_t sectionIndex, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionIndex, plr) {}
C4ControlEliminatePlayer(const std::uint32_t sectionNumber, int32_t plr) : C4ControlInternalPlayerScriptBase(sectionNumber, plr) {}
virtual bool Allowed() const override { return HostControl(); }
virtual StdStrBuf FormatScript() const override { return FormatString("EliminatePlayer(%d)", plr); }
};
10 changes: 5 additions & 5 deletions src/C4EditCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,31 +560,31 @@ void C4EditCursor::ApplyToolBrush()
if (!EditingOK()) return;
C4ToolsDlg *pTools = &Console.ToolsDlg;
// execute/send control
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Brush, Section->Landscape.Mode, X, Y, 0, 0, pTools->Grade, !!pTools->ModeIFT, Game.GetSectionIndex(*Section), pTools->Material, pTools->Texture));
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Brush, Section->Landscape.Mode, X, Y, 0, 0, pTools->Grade, !!pTools->ModeIFT, Section->Number, pTools->Material, pTools->Texture));
}

void C4EditCursor::ApplyToolLine()
{
if (!EditingOK()) return;
C4ToolsDlg *pTools = &Console.ToolsDlg;
// execute/send control
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Line, Section->Landscape.Mode, X, Y, X2, Y2, pTools->Grade, !!pTools->ModeIFT, Game.GetSectionIndex(*Section), pTools->Material, pTools->Texture));
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Line, Section->Landscape.Mode, X, Y, X2, Y2, pTools->Grade, !!pTools->ModeIFT, Section->Number, pTools->Material, pTools->Texture));
}

void C4EditCursor::ApplyToolRect()
{
if (!EditingOK()) return;
C4ToolsDlg *pTools = &Console.ToolsDlg;
// execute/send control
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Rect, Section->Landscape.Mode, X, Y, X2, Y2, pTools->Grade, !!pTools->ModeIFT, Game.GetSectionIndex(*Section), pTools->Material, pTools->Texture));
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Rect, Section->Landscape.Mode, X, Y, X2, Y2, pTools->Grade, !!pTools->ModeIFT, Section->Number, pTools->Material, pTools->Texture));
}

void C4EditCursor::ApplyToolFill()
{
if (!EditingOK()) return;
C4ToolsDlg *pTools = &Console.ToolsDlg;
// execute/send control
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Fill, Section->Landscape.Mode, X, Y, 0, Y2, pTools->Grade, false, Game.GetSectionIndex(*Section), pTools->Material));
EMControl(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_Fill, Section->Landscape.Mode, X, Y, 0, Y2, pTools->Grade, false, Section->Number, pTools->Material));
}

bool C4EditCursor::DoContextMenu()
Expand Down Expand Up @@ -737,7 +737,7 @@ void C4EditCursor::EMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int
}

// execute control
EMControl(CID_EMMoveObj, new C4ControlEMMoveObject(eAction, tx, ty, Game.GetSectionIndex(*Section), pTargetObj, iObjCnt, pObjIDs, szScript, Config.Developer.ConsoleScriptStrictness));
EMControl(CID_EMMoveObj, new C4ControlEMMoveObject(eAction, tx, ty, Section->Number, pTargetObj, iObjCnt, pObjIDs, szScript, Config.Developer.ConsoleScriptStrictness));
}

void C4EditCursor::EMControl(C4PacketType eCtrlType, C4ControlPacket *pCtrl)
Expand Down
Loading

0 comments on commit 9148c58

Please sign in to comment.