From 22016e075fe1a581f8045a610159454487b733ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Brammer?= Date: Sun, 3 Mar 2013 19:25:18 +0100 Subject: [PATCH] Replace some usages of C4ID with C4Def* In particular those that made the c4script shell depend on C4Id.cpp. --- CMakeLists.txt | 6 ++-- docs/sdk/script/fn/C4Id.xml | 30 ------------------- .../Libraries.ocd/Base.ocd/Script.c | 2 +- src/control/C4RoundResults.cpp | 5 ++-- src/editor/C4EditCursor.cpp | 2 +- src/game/C4Game.cpp | 13 +++----- src/game/C4Game.h | 2 +- src/gamescript/C4FindObject.cpp | 11 ++++--- src/gamescript/C4FindObject.h | 8 ++--- src/gui/C4GameOverDlg.cpp | 2 +- src/gui/C4MainMenu.cpp | 4 +-- src/gui/C4MouseControl.cpp | 6 ++-- src/landscape/C4Landscape.cpp | 3 +- src/mape/cpp-handles/stub-handle.cpp | 2 +- src/object/C4Command.cpp | 12 ++++---- src/object/C4DefList.cpp | 5 ++++ src/object/C4DefList.h | 1 + src/object/C4Object.cpp | 18 +++++------ src/object/C4Object.h | 2 +- src/object/C4ObjectList.cpp | 4 +-- src/object/C4ObjectList.h | 2 +- src/object/C4ObjectMenu.cpp | 4 +-- src/object/C4ObjectScript.cpp | 4 +-- src/script/C4AulDefFunc.h | 6 ++-- src/script/C4AulLink.cpp | 14 ++++----- src/script/C4AulParse.cpp | 8 ++--- src/script/C4Script.cpp | 21 ++----------- src/script/C4ScriptHost.cpp | 4 +-- src/script/C4ScriptHost.h | 4 +-- src/script/C4ScriptStandalone.cpp | 2 +- src/script/C4Value.cpp | 19 ++++++------ src/script/C4Value.h | 3 +- 32 files changed, 94 insertions(+), 135 deletions(-) delete mode 100644 docs/sdk/script/fn/C4Id.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index b178b283e..ba8cb4fc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -407,6 +407,8 @@ set(OC_CLONK_SOURCES src/object/C4DefList.h src/object/C4GameObjects.cpp src/object/C4GameObjects.h + src/object/C4Id.cpp + src/object/C4Id.h src/object/C4IDList.cpp src/object/C4IDList.h src/object/C4InfoCore.cpp @@ -485,6 +487,8 @@ set(MAPE_BASE_SOURCES src/lib/C4NameList.h src/lib/C4Rect.cpp src/lib/C4Rect.h + src/object/C4Id.cpp + src/object/C4Id.h ) set(MAPE_SOURCES @@ -1060,8 +1064,6 @@ src/lib/C4Real.cpp src/lib/C4Real.h src/lib/C4Random.cpp src/lib/C4Random.h -src/object/C4Id.cpp -src/object/C4Id.h src/script/C4Aul.cpp src/script/C4AulDefFunc.h src/script/C4AulExec.cpp diff --git a/docs/sdk/script/fn/C4Id.xml b/docs/sdk/script/fn/C4Id.xml deleted file mode 100644 index 7bfe55a80..000000000 --- a/docs/sdk/script/fn/C4Id.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - C4Id - Script - Strings - 5.1 OC - - id - - - string - id_string - String to be converted into an id. - - - - Converts a string into an id. - - - C4Id("Rock") - Returns the id 'Rock'. - - - - jwk2002-04 - diff --git a/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c index 9535a4335..5e89f6f40 100644 --- a/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Base.ocd/Script.c @@ -209,7 +209,7 @@ func OpenBuyMenu(object pClonk, id idDef, int iSelection) var aBuy = [0,0,0]; var iIndex, iSelection; AddClonkBuyList(pClonk); - pClonk->CreateMenu (Library_Base, this, C4MN_Extra_Value, "$TxtNothingToBuy$", 0, C4MN_Style_Normal, 0, C4Id("BuyMenu")); + pClonk->CreateMenu (Library_Base, this, C4MN_Extra_Value, "$TxtNothingToBuy$", 0, C4MN_Style_Normal); for(aBuy in GetBuyObjects()) { if(aBuy[0] == idDef) iSelection = iIndex; diff --git a/src/control/C4RoundResults.cpp b/src/control/C4RoundResults.cpp index a6030e09b..dd4756f08 100644 --- a/src/control/C4RoundResults.cpp +++ b/src/control/C4RoundResults.cpp @@ -24,6 +24,7 @@ #include #include #include +#include // *** C4RoundResultsPlayer @@ -282,8 +283,8 @@ void C4RoundResults::EvaluateGoals(C4IDList &GoalList, C4IDList &FulfilledGoalLi { // determine if the goal is fulfilled - do the calls even if the menu is not to be opened to ensure synchronization bool fFulfilled = false;; - C4Object *pObj; - if ((pObj = ::Objects.Find(idGoal))) + C4Object *pObj = C4Id2Def(idGoal) ? ::Objects.Find(::Definitions.ID2Def(idGoal)) : NULL; + if (pObj) { // Check fulfilled per player, this enables the possibility of rivalry. C4AulParSet pars(C4VInt(iPlayerNumber)); diff --git a/src/editor/C4EditCursor.cpp b/src/editor/C4EditCursor.cpp index d68292e2b..2a53ddcd8 100644 --- a/src/editor/C4EditCursor.cpp +++ b/src/editor/C4EditCursor.cpp @@ -153,7 +153,7 @@ bool C4EditCursor::Move(float iX, float iY, DWORD dwKeyState) Target = ((dwKeyState & MK_SHIFT) && Selection.Last) ? Selection.Last->Obj : NULL; do { - Target = Game.FindObject(C4ID::None,X,Y,0,0,OCF_NotContained, Target); + Target = Game.FindObject(NULL,X,Y,0,0,OCF_NotContained, Target); } while ((dwKeyState & MK_SHIFT) && Target && Selection.GetLink(Target)); } diff --git a/src/game/C4Game.cpp b/src/game/C4Game.cpp index fb340ee12..e830c7819 100644 --- a/src/game/C4Game.cpp +++ b/src/game/C4Game.cpp @@ -1126,7 +1126,7 @@ C4Object* C4Game::OverlapObject(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt return NULL; } -C4Object* C4Game::FindObject(C4ID id, +C4Object* C4Game::FindObject(C4Def * pDef, int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, DWORD ocf, C4Object *pFindNext) @@ -1136,15 +1136,10 @@ C4Object* C4Game::FindObject(C4ID id, int32_t iClosest = 0,iDistance,iFartherThan=-1; C4Object *cObj; C4ObjectLink *cLnk; - C4Def *pDef; C4Object *pFindNextCpy=pFindNext; - // check the easy cases first - if (id!=C4ID::None) - { - if (!(pDef=C4Id2Def(id))) return NULL; // no valid def - if (!pDef->Count) return NULL; // no instances at all - } + // check the easy case first: no instances at all? + if (pDef && !pDef->Count) return NULL; // Finding next closest: find closest but further away than last closest if (pFindNext && (iWdt==-1) && (iHgt==-1)) @@ -1161,7 +1156,7 @@ C4Object* C4Game::FindObject(C4ID id, // Status if (cObj->Status) // ID - if ((id==C4ID::None) || (cObj->Def->id==id)) + if (!pDef || (cObj->Def == pDef)) // OCF (match any specified) if (cObj->OCF & ocf) // Area diff --git a/src/game/C4Game.h b/src/game/C4Game.h index 623550854..2ddc8bf83 100644 --- a/src/game/C4Game.h +++ b/src/game/C4Game.h @@ -189,7 +189,7 @@ public: C4Object *CreateInfoObject(C4ObjectInfo *cinf, int32_t owner, int32_t tx=50, int32_t ty=50); C4Object *OverlapObject(int32_t tx, int32_t ty, int32_t wdt, int32_t hgt, int32_t Plane); - C4Object *FindObject(C4ID id, + C4Object *FindObject(C4Def * pDef, int32_t iX=0, int32_t iY=0, int32_t iWdt=0, int32_t iHgt=0, DWORD ocf=OCF_All, C4Object *pFindNext=NULL); diff --git a/src/gamescript/C4FindObject.cpp b/src/gamescript/C4FindObject.cpp index 546e14475..013df7087 100644 --- a/src/gamescript/C4FindObject.cpp +++ b/src/gamescript/C4FindObject.cpp @@ -87,7 +87,7 @@ C4FindObject *C4FindObject::CreateByValue(const C4Value &DataVal, C4SortObject * return new C4FindObjectExclude(Data[1].getObj()); case C4FO_ID: - return new C4FindObjectID(Data[1].getC4ID()); + return new C4FindObjectDef(Data[1].getPropList()); // #973: For all criteria using coordinates: If FindObject et al. are called in object context, offset by object center @@ -606,15 +606,14 @@ bool C4FindObjectExclude::Check(C4Object *pObj) return pObj != pExclude; } -bool C4FindObjectID::Check(C4Object *pObj) +bool C4FindObjectDef::Check(C4Object *pObj) { - return pObj->id == id; + return pObj->GetPrototype() == def; } -bool C4FindObjectID::IsImpossible() +bool C4FindObjectDef::IsImpossible() { - C4Def * pDef = C4Id2Def(id); - return !pDef || !pDef->Count; + return !def || !def->GetDef() || !def->GetDef()->Count; } bool C4FindObjectInRect::Check(C4Object *pObj) diff --git a/src/gamescript/C4FindObject.h b/src/gamescript/C4FindObject.h index 12e8c9306..5cf2eb978 100644 --- a/src/gamescript/C4FindObject.h +++ b/src/gamescript/C4FindObject.h @@ -169,13 +169,13 @@ protected: virtual bool Check(C4Object *pObj); }; -class C4FindObjectID : public C4FindObject +class C4FindObjectDef : public C4FindObject { public: - C4FindObjectID(C4ID id) - : id(id) { } + C4FindObjectDef(C4PropList * def) + : def(def) { } private: - C4ID id; + C4PropList * def; protected: virtual bool Check(C4Object *pObj); virtual bool IsImpossible(); diff --git a/src/gui/C4GameOverDlg.cpp b/src/gui/C4GameOverDlg.cpp index 0a7362741..47db92c50 100644 --- a/src/gui/C4GameOverDlg.cpp +++ b/src/gui/C4GameOverDlg.cpp @@ -61,7 +61,7 @@ C4GoalDisplay::GoalPicture::GoalPicture(const C4Rect &rcBounds, C4ID idGoal, boo { Picture.Create(C4PictureSize, C4PictureSize); // get an object instance to draw (optional; may be zero) - C4Object *pGoalObj = ::Objects.Find(idGoal); + C4Object *pGoalObj = ::Objects.Find(pDrawDef); // draw goal def! pDrawDef->Draw(Picture, false, 0, pGoalObj); } diff --git a/src/gui/C4MainMenu.cpp b/src/gui/C4MainMenu.cpp index ec7eff478..73c3814f4 100644 --- a/src/gui/C4MainMenu.cpp +++ b/src/gui/C4MainMenu.cpp @@ -804,8 +804,8 @@ bool C4MainMenu::MenuCommand(const char *szCommand, bool fIsCloseCommand) { if (!ValidPlr(Player)) return false; // observers may not look at goal/rule info, because it requires queue activation Close(true); - C4Object *pObj; C4ID idItem(szCommand+12); - if ((pObj = ::Objects.Find(idItem))) + C4Object *pObj; C4ID idItem(szCommand+12); C4Def * pDef = C4Id2Def(idItem); + if (pDef && (pObj = ::Objects.Find(pDef))) ::Control.DoInput(CID_PlrAction, C4ControlPlayerAction::ActivateGoal(::Players.Get(Player), pObj), CDT_Queue); else return false; diff --git a/src/gui/C4MouseControl.cpp b/src/gui/C4MouseControl.cpp index 0e39d7706..d4f036463 100644 --- a/src/gui/C4MouseControl.cpp +++ b/src/gui/C4MouseControl.cpp @@ -638,16 +638,16 @@ void C4MouseControl::DragNone() // check if target object allows scripted dragging if (fAllowDrag && DownTarget && (!FogOfWar || (DownTarget->Category & C4D_IgnoreFoW))) { - C4Object *drag_image_obj; C4ID drag_image_id; + C4Object *drag_image_obj; C4Def * drag_image_def; // Drag only if MD_SOURCE is set and drag image is present if ( (DownTarget->GetPropertyInt(P_MouseDrag) & C4MC_MD_DragSource) && - DownTarget->GetDragImage(&drag_image_obj, &drag_image_id)) + DownTarget->GetDragImage(&drag_image_obj, &drag_image_def)) { Drag=C4MC_Drag_Script; if(drag_image_obj) DragImageObject = drag_image_obj; - else DragImageDef = C4Id2Def(drag_image_id); + else DragImageDef = drag_image_def; DragObject = DownTarget; } diff --git a/src/landscape/C4Landscape.cpp b/src/landscape/C4Landscape.cpp index 3d53b2c63..2736e86e5 100644 --- a/src/landscape/C4Landscape.cpp +++ b/src/landscape/C4Landscape.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -929,7 +930,7 @@ bool C4Landscape::Incinerate(int32_t x, int32_t y) if (MatValid(mat)) if (::MaterialMap.Map[mat].Inflammable) // Not too much FLAMs - if (!Game.FindObject (C4ID::Flame, x - 4, y - 1, 8, 20)) + if (!Game.FindObject (C4Id2Def(C4ID::Flame), x - 4, y - 1, 8, 20)) if (Game.CreateObject(C4ID::Flame,NULL,NO_OWNER,x,y)) return true; return false; diff --git a/src/mape/cpp-handles/stub-handle.cpp b/src/mape/cpp-handles/stub-handle.cpp index 15514faa2..e253e6ff1 100644 --- a/src/mape/cpp-handles/stub-handle.cpp +++ b/src/mape/cpp-handles/stub-handle.cpp @@ -102,7 +102,7 @@ void C4Def::IncludeDefinition(C4Def*) {} C4DefList::C4DefList() {} C4DefList::~C4DefList() {} -C4Def* C4DefList::ID2Def(C4ID) {return NULL;} +C4Def* C4DefList::GetByName(const StdStrBuf &) {return NULL;} void C4DefList::Draw(C4ID, C4Facet &, bool, int32_t) {} C4Def * C4DefList::GetDef(int) {return 0;} int C4DefList::GetDefCount() {return 0;} diff --git a/src/object/C4Command.cpp b/src/object/C4Command.cpp index 8342af1dc..d2f7a076e 100644 --- a/src/object/C4Command.cpp +++ b/src/object/C4Command.cpp @@ -940,7 +940,7 @@ void C4Command::Get() // Get target specified by container and type if (!Target && Target2 && Data) - if (!(Target = Target2->Contents.Find(Data.getC4ID()))) + if (!(Target = Target2->Contents.Find(Data.getDef()))) { Finish(); return; } // No target: failure @@ -1116,7 +1116,7 @@ void C4Command::Activate() C4Object *pObj; C4ObjectLink *cLnk; if (!Target) for (cLnk=Target2->Contents.First; cLnk && (pObj=cLnk->Obj); cLnk=cLnk->Next) - if (pObj->Status && (pObj->Def->id==Data.getC4ID())) + if (pObj->Status && (pObj->Def==Data.getDef())) if (!pObj->Command || (pObj->Command->Command!=C4CMD_Exit)) { Target=pObj; break; } // No target @@ -1155,7 +1155,7 @@ void C4Command::Put() // Notice: Put command is currently using Ty as an interna // Thing to put specified by type if (!Target2 && Data) - if (!(Target2 = cObj->Contents.Find(Data.getC4ID()))) + if (!(Target2 = cObj->Contents.Find(Data.getDef()))) { Finish(); return; } // No thing to put specified @@ -1623,7 +1623,7 @@ void C4Command::Acquire() if (!Data) { Finish(); return; } // Target material in inventory: done - if (cObj->Contents.Find(Data.getC4ID())) + if (cObj->Contents.Find(Data.getDef())) { Finish(true); return; } // script overload @@ -1640,7 +1640,7 @@ void C4Command::Acquire() // Find available material C4Object *pMaterial=NULL; // Next closest - while ((pMaterial = Game.FindObject(Data.getC4ID(),cObj->GetX(),cObj->GetY(),-1,-1,OCF_Available,pMaterial))) + while ((pMaterial = Game.FindObject(Data.getDef(),cObj->GetX(),cObj->GetY(),-1,-1,OCF_Available,pMaterial))) // Object is not in container to be ignored if (!Target2 || pMaterial->Contained!=Target2) // Object is near enough @@ -1733,7 +1733,7 @@ void C4Command::Fail(const char *szFailMessage) if (szFailMessage) break; // Fail message with name of target type SCopy(LoadResStr(CommandNameID(Command)), szCommandName); - C4Def *pDef; pDef = ::Definitions.ID2Def(Data.getC4ID()); + C4Def *pDef; pDef = Data.getDef(); SCopy(pDef ? pDef->GetName() : LoadResStr("IDS_OBJ_UNKNOWN"), szObjectName); str.Format(LoadResStr("IDS_CON_FAILUREOF"), szCommandName, szObjectName); break; diff --git a/src/object/C4DefList.cpp b/src/object/C4DefList.cpp index 6ec94946f..11c89f20b 100644 --- a/src/object/C4DefList.cpp +++ b/src/object/C4DefList.cpp @@ -211,6 +211,11 @@ C4Def* C4DefList::ID2Def(C4ID id) return NULL; } +C4Def * C4DefList::GetByName(const StdStrBuf & name) +{ + return ID2Def(C4ID(name)); +} + int32_t C4DefList::GetIndex(C4ID id) { C4Def *cdef; diff --git a/src/object/C4DefList.h b/src/object/C4DefList.h index 2da5c51af..a2e9935ba 100644 --- a/src/object/C4DefList.h +++ b/src/object/C4DefList.h @@ -48,6 +48,7 @@ public: C4Def *ID2Def(C4ID id); C4Def *GetDef(int32_t Index); C4Def *GetByPath(const char *szPath); + C4Def *GetByName(const StdStrBuf &); int32_t GetDefCount(); int32_t GetIndex(C4ID id); int32_t RemoveTemporary(); diff --git a/src/object/C4Object.cpp b/src/object/C4Object.cpp index 8b7f9bc16..7401b8872 100644 --- a/src/object/C4Object.cpp +++ b/src/object/C4Object.cpp @@ -1960,13 +1960,13 @@ void C4Object::Draw(C4TargetFacet &cgo, int32_t iByPlayer, DrawMode eDrawMode, f //sprintf(szCommand,"%s %d/%d",CommandName(pCom->Command),pCom->Tx,pCom->Ty,iAngle); break; case C4CMD_Put: - sprintf(szCommand,"%s %s to %s",CommandName(pCom->Command),pCom->Target2 ? pCom->Target2->GetName() : pCom->Data ? pCom->Data.getC4ID().ToString() : "Content",pCom->Target ? pCom->Target->GetName() : ""); + sprintf(szCommand,"%s %s to %s",CommandName(pCom->Command),pCom->Target2 ? pCom->Target2->GetName() : pCom->Data ? pCom->Data.GetDataString().getData() : "Content",pCom->Target ? pCom->Target->GetName() : ""); break; case C4CMD_Buy: case C4CMD_Sell: - sprintf(szCommand,"%s %s at %s",CommandName(pCom->Command),pCom->Data.getC4ID().ToString(),pCom->Target ? pCom->Target->GetName() : "closest base"); + sprintf(szCommand,"%s %s at %s",CommandName(pCom->Command),pCom->Data.GetDataString().getData(),pCom->Target ? pCom->Target->GetName() : "closest base"); break; case C4CMD_Acquire: - sprintf(szCommand,"%s %s",CommandName(pCom->Command),pCom->Data.getC4ID().ToString()); + sprintf(szCommand,"%s %s",CommandName(pCom->Command),pCom->Data.GetDataString().getData()); break; case C4CMD_Call: sprintf(szCommand,"%s %s in %s",CommandName(pCom->Command),pCom->Text->GetCStr(),pCom->Target ? pCom->Target->GetName() : "(null)"); @@ -2628,7 +2628,7 @@ C4Object *C4Object::ComposeContents(C4ID id) // Remove components for (cnt=0; (c_id=NeededComponents.GetID(cnt)); cnt++) for (cnt2=0; cnt2AssignRemoval(); @@ -4460,17 +4460,17 @@ void C4Object::GetParallaxity(int32_t *parX, int32_t *parY) const *parY = par->GetItem(1).getInt(); } -bool C4Object::GetDragImage(C4Object **drag_object, C4ID *drag_id) const +bool C4Object::GetDragImage(C4Object **drag_object, C4Def **drag_def) const { // drag is possible if MouseDragImage is assigned C4Value parV; GetProperty(P_MouseDragImage, &parV); if (!parV) return false; // determine drag object/id - C4Object *obj=NULL; C4ID id; - if (parV.CheckConversion(C4V_Object)) obj = parV.getObj(); - else if (parV.CheckConversion(C4V_Def)) id = parV.getC4ID(); + C4Object *obj = parV.getObj(); + C4Def * def = NULL; + if (!obj) def = parV.getDef(); if (drag_object) *drag_object = obj; - if (drag_id) *drag_id = id; + if (drag_def) *drag_def = def; // drag possible, even w./o image return true; } diff --git a/src/object/C4Object.h b/src/object/C4Object.h index e5432fe5a..e00165cee 100644 --- a/src/object/C4Object.h +++ b/src/object/C4Object.h @@ -339,7 +339,7 @@ public: bool IsInLiquidCheck() const; // returns whether the Clonk is within liquid material void UpdateInLiquid(); // makes splash when a liquid is entered void GrabContents(C4Object *pFrom); // grab all contents that don't reject it - bool GetDragImage(C4Object **drag_object, C4ID *drag_id) const; // return true if object is draggable; assign drag_object/drag_id to gfx to be used for dragging + bool GetDragImage(C4Object **drag_object, C4Def **drag_id) const; // return true if object is draggable; assign drag_object/drag_id to gfx to be used for dragging protected: void SideBounds(C4Real &ctcox); // apply bounds at side; regarding bourder bound and pLayer diff --git a/src/object/C4ObjectList.cpp b/src/object/C4ObjectList.cpp index 5d322fe69..ffefedd40 100644 --- a/src/object/C4ObjectList.cpp +++ b/src/object/C4ObjectList.cpp @@ -270,13 +270,13 @@ bool C4ObjectList::Remove(C4Object *pObj) return true; } -C4Object* C4ObjectList::Find(C4ID id, int owner, DWORD dwOCF) +C4Object* C4ObjectList::Find(C4Def * def, int owner, DWORD dwOCF) { C4ObjectLink *cLnk; // Find link and object for (cLnk=First; cLnk; cLnk=cLnk->Next) if (cLnk->Obj->Status) - if (cLnk->Obj->Def->id==id) + if (cLnk->Obj->Def==def) if ((owner==ANY_OWNER) || (cLnk->Obj->Owner==owner)) if (dwOCF & cLnk->Obj->OCF) return cLnk->Obj; diff --git a/src/object/C4ObjectList.h b/src/object/C4ObjectList.h index 69d34712a..731b30f7f 100644 --- a/src/object/C4ObjectList.h +++ b/src/object/C4ObjectList.h @@ -116,7 +116,7 @@ public: const C4Object* GetObject(int Index=0) const; C4Object* GetObject(int Index=0) { return const_cast(const_cast(this)->GetObject(Index)); } - C4Object* Find(C4ID id, int iOwner=ANY_OWNER, DWORD dwOCF=OCF_All); + C4Object* Find(C4Def * def, int iOwner=ANY_OWNER, DWORD dwOCF=OCF_All); C4Object* FindOther(C4ID id, int iOwner=ANY_OWNER); const C4ObjectLink* GetLink(const C4Object *pObj) const; diff --git a/src/object/C4ObjectMenu.cpp b/src/object/C4ObjectMenu.cpp index 773021315..b45c99874 100644 --- a/src/object/C4ObjectMenu.cpp +++ b/src/object/C4ObjectMenu.cpp @@ -162,7 +162,7 @@ bool C4ObjectMenu::DoRefillInternal(bool &rfRefilled) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter - C4Object *pObj2=pTarget->Contents.Find(pDef->id, ANY_OWNER, OCF_FullCon); + C4Object *pObj2=pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Caption @@ -199,7 +199,7 @@ bool C4ObjectMenu::DoRefillInternal(bool &rfRefilled) { // easy way: only if first concat check matches // this doesn't catch all possibilities, but that will rarely matter - C4Object *pObj2 = pTarget->Contents.Find(pDef->id, ANY_OWNER, OCF_FullCon); + C4Object *pObj2 = pTarget->Contents.Find(pDef, ANY_OWNER, OCF_FullCon); if (pObj2) if (pObj2->CanConcatPictureWith(pObj)) pObj = pObj2; } // Determine whether to get or activate diff --git a/src/object/C4ObjectScript.cpp b/src/object/C4ObjectScript.cpp index 4e3dec208..c90e3f5a8 100644 --- a/src/object/C4ObjectScript.cpp +++ b/src/object/C4ObjectScript.cpp @@ -1156,7 +1156,7 @@ static C4Object *FnContents(C4Object *Obj, long index) return NULL; } -static bool FnShiftContents(C4Object *Obj, bool fShiftBack, C4ID idTarget, bool fDoCalls) +static bool FnShiftContents(C4Object *Obj, bool fShiftBack, C4Def * idTarget, bool fDoCalls) { // regular shift if (!idTarget) return !!Obj->ShiftContents(fShiftBack, fDoCalls); @@ -1186,7 +1186,7 @@ static long FnContentsCount(C4Object *Obj, C4ID id) return Obj->Contents.ObjectCount(id); } -static C4Object *FnFindContents(C4Object *Obj, C4ID c_id) +static C4Object *FnFindContents(C4Object *Obj, C4Def * c_id) { return Obj->Contents.Find(c_id); } diff --git a/src/script/C4AulDefFunc.h b/src/script/C4AulDefFunc.h index 3cd44593f..812967f3e 100644 --- a/src/script/C4AulDefFunc.h +++ b/src/script/C4AulDefFunc.h @@ -137,7 +137,7 @@ template <> struct C4ValueConv template <> struct C4ValueConv { inline static C4V_Type Type() { return C4V_PropList; } - inline static C4ID FromC4V(C4Value &v) { return v.getC4ID(); } + inline static C4ID FromC4V(C4Value &v) { C4Def * def = v.getDef(); return def ? def->id : C4ID::None; } inline static C4ID _FromC4V(C4Value &v) { return FromC4V(v); } inline static C4Value ToC4V(C4ID v) { return C4VPropList(C4Id2Def(v)); } }; @@ -186,8 +186,8 @@ template <> struct C4ValueConv template <> struct C4ValueConv { inline static C4V_Type Type() { return C4V_Def; } - inline static C4Def *FromC4V(C4Value &v) { C4PropList * p = v.getPropList(); return p ? p->GetDef() : 0; } - inline static C4Def *_FromC4V(C4Value &v) { C4PropList * p = v._getPropList(); return p ? p->GetDef() : 0; } + inline static C4Def *FromC4V(C4Value &v) { return v.getDef(); } + inline static C4Def *_FromC4V(C4Value &v) { return v._getDef(); } inline static C4Value ToC4V(C4Def *v) { return C4VPropList(v); } }; template <> struct C4ValueConv diff --git a/src/script/C4AulLink.cpp b/src/script/C4AulLink.cpp index 56e767e23..dabf8a18e 100644 --- a/src/script/C4AulLink.cpp +++ b/src/script/C4AulLink.cpp @@ -40,11 +40,11 @@ bool C4ScriptHost::ResolveAppends(C4DefList *rDefs) { // resolve local appends if (State != ASS_PREPARSED) return false; - for (std::list::iterator a = Appends.begin(); a != Appends.end(); ++a) + for (std::list::iterator a = Appends.begin(); a != Appends.end(); ++a) { - if (*a) + if (*a != "*") { - C4Def *Def = rDefs->ID2Def(*a); + C4Def *Def = rDefs->GetByName(*a); if (Def) { if (std::find(Def->Script.SourceScripts.begin(), Def->Script.SourceScripts.end(), GetScriptHost()) == Def->Script.SourceScripts.end()) @@ -55,7 +55,7 @@ bool C4ScriptHost::ResolveAppends(C4DefList *rDefs) // save id in buffer because AulWarn will use the buffer of C4IdText // to get the id of the object in which the error occurs... // (stupid static buffers...) - Warn("#appendto %s not found", a->ToString()); + Warn("#appendto %s not found", a->getData()); } } else @@ -91,9 +91,9 @@ bool C4ScriptHost::ResolveIncludes(C4DefList *rDefs) } Resolving=true; // append all includes to local script - for (std::list::reverse_iterator i = Includes.rbegin(); i != Includes.rend(); ++i) + for (std::list::reverse_iterator i = Includes.rbegin(); i != Includes.rend(); ++i) { - C4Def *Def = rDefs->ID2Def(*i); + C4Def *Def = rDefs->GetByName(*i); if (Def) { // resolve #includes in included script first (#include-chains :( ) @@ -112,7 +112,7 @@ bool C4ScriptHost::ResolveIncludes(C4DefList *rDefs) // save id in buffer because AulWarn will use the buffer of C4IdText // to get the id of the object in which the error occurs... // (stupid static buffers...) - Warn("#include %s not found", i->ToString()); + Warn("#include %s not found", i->getData()); } } IncludesResolved = true; diff --git a/src/script/C4AulParse.cpp b/src/script/C4AulParse.cpp index 45d289da7..cb5999fa4 100644 --- a/src/script/C4AulParse.cpp +++ b/src/script/C4AulParse.cpp @@ -1249,7 +1249,7 @@ void C4AulParse::Parse_Script(C4ScriptHost * scripthost) if (Type == PREPARSER) { // add to include list - Host->Includes.push_back(C4ID(StdStrBuf(Idtf))); + Host->Includes.push_back(StdCopyStrBuf(Idtf)); } Shift(); } @@ -1262,14 +1262,14 @@ void C4AulParse::Parse_Script(C4ScriptHost * scripthost) if (Type == PREPARSER) { // get id of script to include/append - C4ID Id; + StdCopyStrBuf Id; switch (TokenType) { case ATT_IDTF: - Id = C4ID(StdStrBuf(Idtf)); + Id = StdCopyStrBuf(Idtf); break; case ATT_STAR: // "*" - Id = C4ID::None; + Id = StdCopyStrBuf("*"); break; default: // -> ID expected diff --git a/src/script/C4Script.cpp b/src/script/C4Script.cpp index 6e289e009..5ec1a0cd0 100644 --- a/src/script/C4Script.cpp +++ b/src/script/C4Script.cpp @@ -67,13 +67,6 @@ StdStrBuf FnStringFormat(C4PropList * _this, C4String *szFormatPar, C4Value * Pa } // C4ID case 'i': - { - if (cPar >= ParCount) throw new C4AulExecError("format placeholder without parameter"); - C4ID id = Pars[cPar++].getC4ID(); - StringBuf.Append(id.ToString()); - cpFormat+=SLen(szField); - break; - } // C4Value case 'v': { @@ -251,11 +244,6 @@ static C4Value FnFormat(C4PropList * _this, C4Value * Pars) return C4VString(FnStringFormat(_this, Pars[0].getStr(), &Pars[1], 9)); } -static C4ID FnC4Id(C4PropList * _this, C4String *szID) -{ - return(C4ID(FnStringPar(szID))); -} - static long FnAbs(C4PropList * _this, long iVal) { return Abs(iVal); @@ -532,16 +520,12 @@ static bool FnStartCallTrace(C4PropList * _this) return true; } -static bool FnStartScriptProfiler(C4PropList * _this, C4ID idScript) +static bool FnStartScriptProfiler(C4PropList * _this, C4Def * pDef) { // get script to profile C4AulScript *pScript; - if (idScript) - { - C4Def *pDef = C4Id2Def(idScript); - if (!pDef) return false; + if (pDef) pScript = &pDef->Script; - } else pScript = &::ScriptEngine; // profile it @@ -676,7 +660,6 @@ void InitCoreFunctionMap(C4AulScriptEngine *pEngine) F(GetProperty); F(SetProperty); F(ResetProperty); - F(C4Id); F(Distance); F(Angle); F(GetChar); diff --git a/src/script/C4ScriptHost.cpp b/src/script/C4ScriptHost.cpp index 77b497a93..9033a9bf8 100644 --- a/src/script/C4ScriptHost.cpp +++ b/src/script/C4ScriptHost.cpp @@ -167,7 +167,7 @@ bool C4DefScriptHost::Parse() case C4D_Living | C4D_Foreground: Plane = 1400; break; case C4D_Object | C4D_Foreground: Plane = 1500; break; default: - Warn("Def %s (%s) has invalid category", Def->GetName(), Def->id.ToString()); + Warn("Def %s (%s) has invalid category", Def->GetName(), Def->GetDataString().getData()); gotplane = false; break; } @@ -175,7 +175,7 @@ bool C4DefScriptHost::Parse() } if (!Def->GetPlane()) { - Warn("Def %s (%s) has invalid Plane", Def->GetName(), Def->id.ToString()); + Warn("Def %s (%s) has invalid Plane", Def->GetName(), Def->GetDataString().getData()); Def->SetProperty(P_Plane, C4VInt(1)); } return r; diff --git a/src/script/C4ScriptHost.h b/src/script/C4ScriptHost.h index 6b9700f40..0a6cc47c6 100644 --- a/src/script/C4ScriptHost.h +++ b/src/script/C4ScriptHost.h @@ -48,8 +48,8 @@ protected: virtual void UnLink(); // reset to unlinked state - std::list Includes; // include list - std::list Appends; // append list + std::list Includes; // include list + std::list Appends; // append list virtual void AddEngineFunctions() {}; // add any engine functions specific to this script host void CopyPropList(C4Set & from, C4PropListStatic * to); diff --git a/src/script/C4ScriptStandalone.cpp b/src/script/C4ScriptStandalone.cpp index b035d756c..f04f60e2e 100644 --- a/src/script/C4ScriptStandalone.cpp +++ b/src/script/C4ScriptStandalone.cpp @@ -47,7 +47,7 @@ const char * C4Config::AtRelativePath(char const*s) {return s;} C4DefList Definitions; C4DefList::C4DefList() {} C4DefList::~C4DefList() {} -C4Def* C4DefList::ID2Def(C4ID id) {return NULL;} +C4Def* C4DefList::GetByName(const StdStrBuf &) {return NULL;} C4Def * C4DefList::GetDef(int) {return 0;} int C4DefList::GetDefCount() {return 0;} void C4DefList::CallEveryDefinition() {} diff --git a/src/script/C4Value.cpp b/src/script/C4Value.cpp index c1f9be11b..f36ac6348 100644 --- a/src/script/C4Value.cpp +++ b/src/script/C4Value.cpp @@ -74,6 +74,16 @@ C4Object * C4Value::_getObj() const return Data.PropList ? Data.PropList->GetObject() : NULL; } +C4Def * C4Value::getDef() const +{ + return CheckConversion(C4V_Object) ? Data.PropList->GetDef() : NULL; +} + +C4Def * C4Value::_getDef() const +{ + return Data.PropList ? Data.PropList->GetDef() : NULL; +} + C4Value C4VObj(C4Object *pObj) { return C4Value(static_cast(pObj)); } bool C4Value::FnCnvObject() const @@ -564,15 +574,6 @@ bool C4Value::operator != (const C4Value& Value2) const return !(*this == Value2); } -C4ID C4Value::getC4ID() const -{ - C4PropList * p = getPropList(); - if (!p) return C4ID::None; - C4Def * d = p->GetDef(); - if (!d) return C4ID::None; - return d->id; -} - void C4Value::LogDeletedObjectWarning(C4PropList * p) { if (p->GetPropListNumbered()) diff --git a/src/script/C4Value.h b/src/script/C4Value.h index 58f6169a9..c32dc7c1d 100644 --- a/src/script/C4Value.h +++ b/src/script/C4Value.h @@ -90,8 +90,8 @@ public: // Checked getters int32_t getInt() const { return CheckConversion(C4V_Int) ? Data.Int : 0; } bool getBool() const { return CheckConversion(C4V_Bool) ? !! Data : 0; } - C4ID getC4ID() const; C4Object * getObj() const; + C4Def * getDef() const; C4PropList * getPropList() const { return CheckConversion(C4V_PropList) ? Data.PropList : NULL; } C4String * getStr() const { return CheckConversion(C4V_String) ? Data.Str : NULL; } C4ValueArray * getArray() const { return CheckConversion(C4V_Array) ? Data.Array : NULL; } @@ -101,6 +101,7 @@ public: int32_t _getInt() const { return Data.Int; } bool _getBool() const { return !! Data.Int; } C4Object *_getObj() const; + C4Def *_getDef() const; C4String *_getStr() const { return Data.Str; } C4ValueArray *_getArray() const { return Data.Array; } C4AulFunc *_getFunction() const { return Data.Fn; }