forked from Mirrors/openclonk
Make C4Object::Name a property
Every proplist can have a name, so move the code there.stable-5.2
parent
c4b68c771d
commit
9a9a7fec62
|
@ -78,9 +78,6 @@ class C4GameObjects : public C4NotifyingObjectList
|
|||
|
||||
void DeleteObjects(); // delete all objects and links
|
||||
|
||||
void ClearDefPointers(C4Def *pDef); // clear all pointers into definition
|
||||
void UpdateDefPointers(C4Def *pDef); // restore any cleared pointers after def reload
|
||||
|
||||
bool ValidateOwners();
|
||||
bool AssignInfo();
|
||||
};
|
||||
|
|
|
@ -110,7 +110,6 @@ class C4Object: public C4PropList
|
|||
C4Object();
|
||||
~C4Object();
|
||||
C4ID id;
|
||||
StdStrBuf Name;
|
||||
int32_t RemovalDelay; // NoSave //
|
||||
int32_t Owner;
|
||||
int32_t Controller;
|
||||
|
@ -332,7 +331,6 @@ class C4Object: public C4PropList
|
|||
FIXED GetSpeed();
|
||||
C4PhysicalInfo *GetPhysical(bool fPermanent=false);
|
||||
bool TrainPhysical(C4PhysicalInfo::Offset mpiOffset, int32_t iTrainBy, int32_t iMaxTrain);
|
||||
const char *GetName();
|
||||
void SetName (const char *NewName = 0);
|
||||
int32_t GetValue(C4Object *pInBase, int32_t iForPlayer);
|
||||
void DirectCom(BYTE byCom, int32_t iData);
|
||||
|
|
|
@ -104,8 +104,6 @@ class C4ObjectList
|
|||
void SetOCF();
|
||||
void GetIDList(C4IDList &rList, int32_t dwCategory=C4D_All);
|
||||
void ClearInfo(C4ObjectInfo *pInfo);
|
||||
void ClearDefPointers(C4Def *pDef); // clear all pointers into definition
|
||||
void UpdateDefPointers(C4Def *pDef); // restore any cleared pointers after def reload
|
||||
|
||||
typedef int SortProc(C4Object *, C4Object *);
|
||||
|
||||
|
|
|
@ -21,13 +21,19 @@ class C4PropList {
|
|||
void AddRef(C4Value *pRef);
|
||||
void DelRef(const C4Value *pRef, C4Value * pNextRef);
|
||||
void AssignRemoval();
|
||||
const char *GetName() { return "FIXME"; }
|
||||
const char *GetName();
|
||||
virtual void SetName (const char *NewName = 0);
|
||||
|
||||
bool GetProperty(C4String * k, C4Value & to);
|
||||
void SetProperty(C4String * k, C4Value & to);
|
||||
C4String * GetPropertyStr(C4PropertyName k);
|
||||
int32_t GetPropertyInt(C4PropertyName k);
|
||||
void SetProperty(C4String * k, const C4Value & to);
|
||||
void ResetProperty(C4String * k);
|
||||
|
||||
C4PropList();
|
||||
virtual ~C4PropList();
|
||||
private:
|
||||
|
||||
protected:
|
||||
C4Value *FirstRef; // No-Save
|
||||
|
||||
C4Set<C4Property> Properties;
|
||||
|
|
|
@ -160,9 +160,9 @@ inline unsigned int C4Set<C4String *>::Hash<C4String *>(C4String * e)
|
|||
return e->Hash;
|
||||
}
|
||||
|
||||
enum {
|
||||
P_PROTOTYPE,
|
||||
P_NAME,
|
||||
enum C4PropertyName {
|
||||
P_Prototype,
|
||||
P_Name,
|
||||
P_LAST };
|
||||
|
||||
// There is only one Stringtable in Game.ScriptEngine
|
||||
|
|
|
@ -1061,7 +1061,7 @@ void C4ControlMessage::Execute() const
|
|||
{
|
||||
if (Game.C4S.Head.Film == C4SFilm_Cinematic)
|
||||
{
|
||||
StdStrBuf sMessage; sMessage.Format("<%s> %s", pPlr->Cursor->Name.getData(), szMessage);
|
||||
StdStrBuf sMessage; sMessage.Format("<%s> %s", pPlr->Cursor->GetName(), szMessage);
|
||||
uint32_t dwClr = pPlr->Cursor->Color;
|
||||
if (!dwClr) dwClr = 0xff;
|
||||
GameMsgObjectDw(sMessage.getData(), pPlr->Cursor, dwClr|0xff000000);
|
||||
|
|
|
@ -1487,8 +1487,6 @@ BOOL C4DefList::Reload(C4Def *pDef, DWORD dwLoadWhat, const char *szLanguage, C4
|
|||
// backup graphics names and pointers
|
||||
// GfxBackup-dtor will ensure that upon loading-failure all graphics are reset to default
|
||||
C4DefGraphicsPtrBackup GfxBackup(&pDef->Graphics);
|
||||
// clear any pointers into def (name)
|
||||
Game.Objects.ClearDefPointers(pDef);
|
||||
#endif
|
||||
// Clear def
|
||||
pDef->Clear(); // Assume filename is being kept
|
||||
|
@ -1504,8 +1502,6 @@ BOOL C4DefList::Reload(C4Def *pDef, DWORD dwLoadWhat, const char *szLanguage, C4
|
|||
Game.ScriptEngine.ReLink(this);
|
||||
#endif
|
||||
#ifdef C4ENGINE
|
||||
// update definition pointers
|
||||
Game.Objects.UpdateDefPointers(pDef);
|
||||
// restore graphics
|
||||
GfxBackup.AssignUpdate(&pDef->Graphics);
|
||||
#endif
|
||||
|
|
|
@ -865,20 +865,6 @@ void C4GameObjects::FixObjectOrder()
|
|||
// objects fixed!
|
||||
}
|
||||
|
||||
void C4GameObjects::ClearDefPointers(C4Def *pDef)
|
||||
{
|
||||
// call in sublists
|
||||
C4ObjectList::ClearDefPointers(pDef);
|
||||
InactiveObjects.ClearDefPointers(pDef);
|
||||
}
|
||||
|
||||
void C4GameObjects::UpdateDefPointers(C4Def *pDef)
|
||||
{
|
||||
// call in sublists
|
||||
C4ObjectList::UpdateDefPointers(pDef);
|
||||
InactiveObjects.UpdateDefPointers(pDef);
|
||||
}
|
||||
|
||||
void C4GameObjects::ResortUnsorted()
|
||||
{
|
||||
C4ObjectLink *clnk=First; C4Object *cObj;
|
||||
|
|
|
@ -160,7 +160,7 @@ BOOL C4Object::Init(C4Def *pDef, C4Object *pCreator,
|
|||
LastEnergyLossCausePlayer=NO_OWNER;
|
||||
Info=pInfo;
|
||||
Def=pDef;
|
||||
if (Info) Name = pInfo->Name; else Name = pDef->Name;
|
||||
if (Info) SetName(pInfo->Name);
|
||||
Category=Def->Category;
|
||||
Def->Count++;
|
||||
if (pCreator) pLayer=pCreator->pLayer;
|
||||
|
@ -1236,8 +1236,6 @@ BOOL C4Object::ChangeDef(C4ID idNew)
|
|||
SetDir(0); // will drop any outdated flipdir
|
||||
if (pSolidMaskData) { pSolidMaskData->Remove(true, false); delete pSolidMaskData; pSolidMaskData=NULL; }
|
||||
Def->Count--;
|
||||
// change the name to the name of the new def, if the name of the old def was in use before
|
||||
if (Name.getData() == Def->Name.getData()) Name = pDef->Name;
|
||||
// Def change
|
||||
Def=pDef;
|
||||
id=pDef->id;
|
||||
|
@ -2065,18 +2063,13 @@ FIXED C4Object::GetSpeed()
|
|||
return cobjspd;
|
||||
}
|
||||
|
||||
const char* C4Object::GetName()
|
||||
{
|
||||
return Name.getData();
|
||||
}
|
||||
|
||||
void C4Object::SetName(const char* NewName)
|
||||
{
|
||||
if(!NewName)
|
||||
if (Info) Name = Info->Name; else Name = Def->Name;
|
||||
void C4Object::SetName(const char * NewName)
|
||||
{
|
||||
if(!NewName && Info)
|
||||
C4PropList::SetName(Info->Name);
|
||||
else
|
||||
Name.Copy(NewName);
|
||||
}
|
||||
C4PropList::SetName(NewName);
|
||||
}
|
||||
|
||||
int32_t C4Object::GetValue(C4Object *pInBase, int32_t iForPlayer)
|
||||
{
|
||||
|
@ -2661,12 +2654,12 @@ void C4Object::CompileFunc(StdCompiler *pComp)
|
|||
|
||||
// Write the name only if the object has an individual name, use def name as default for reading.
|
||||
// (Info may overwrite later, see C4Player::MakeCrewMember)
|
||||
if (pComp->isCompiler())
|
||||
/*if (pComp->isCompiler())
|
||||
pComp->Value(mkNamingAdapt(Name, "Name", Def->Name));
|
||||
else if (!Name.isRef())
|
||||
// Write the name only if the object has an individual name
|
||||
// 2do: And what about binary compilers?
|
||||
pComp->Value(mkNamingAdapt(Name, "Name"));
|
||||
pComp->Value(mkNamingAdapt(Name, "Name"));*/
|
||||
|
||||
pComp->Value(mkNamingAdapt( Number, "Number", -1 ));
|
||||
pComp->Value(mkNamingAdapt( Status, "Status", 1 ));
|
||||
|
@ -3155,7 +3148,6 @@ void C4Object::ClearInfo(C4ObjectInfo *pInfo)
|
|||
{
|
||||
if (Info==pInfo)
|
||||
{
|
||||
if (Info) if (Name.getData() == Info->Name) Name = Def->Name;
|
||||
Info=NULL;
|
||||
}
|
||||
}
|
||||
|
@ -5574,7 +5566,7 @@ BOOL C4Object::GrabInfo(C4Object *pFrom)
|
|||
// set info
|
||||
Info = pFrom->Info; pFrom->ClearInfo (pFrom->Info);
|
||||
// set name
|
||||
if(Name.isRef()) Name = Info->Name;
|
||||
if(!Properties.Has(Strings.P[P_Name])) SetName(Info->Name);
|
||||
// retire from old crew
|
||||
Info->Retire();
|
||||
// set death status
|
||||
|
@ -6007,7 +5999,7 @@ bool C4Object::CanConcatPictureWith(C4Object *pOtherObject)
|
|||
if (!(allow_picture_stack & APS_Name))
|
||||
{
|
||||
// check name, so zagabar's sandwiches don't stack
|
||||
if (Name.getData() != pOtherObject->Name.getData()) if (Name != pOtherObject->Name) return false;
|
||||
if (GetName() != pOtherObject->GetName()) return false;
|
||||
}
|
||||
if (!(allow_picture_stack & APS_Overlay))
|
||||
{
|
||||
|
|
|
@ -658,28 +658,6 @@ void C4ObjectList::ClearInfo(C4ObjectInfo *pInfo)
|
|||
cLnk->Obj->ClearInfo(pInfo);
|
||||
}
|
||||
|
||||
void C4ObjectList::ClearDefPointers(C4Def *pDef)
|
||||
{
|
||||
// clear all pointers into definition
|
||||
C4ObjectLink *cLnk;
|
||||
for (cLnk=First; cLnk; cLnk=cLnk->Next)
|
||||
if (cLnk->Obj->Def == pDef)
|
||||
{
|
||||
cLnk->Obj->Name.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void C4ObjectList::UpdateDefPointers(C4Def *pDef)
|
||||
{
|
||||
// restore any cleared pointers after def reload
|
||||
C4ObjectLink *cLnk;
|
||||
for (cLnk=First; cLnk; cLnk=cLnk->Next)
|
||||
if (cLnk->Obj->Def == pDef)
|
||||
{
|
||||
cLnk->Obj->SetName(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
C4Object* C4ObjectList::Enumerated(C4Object *pObj)
|
||||
{
|
||||
int iPtrNum;
|
||||
|
|
|
@ -1184,7 +1184,7 @@ BOOL C4Player::MakeCrewMember(C4Object *pObj, bool fForceInfo, bool fDoCalls)
|
|||
|
||||
// Set object info
|
||||
pObj->Info = cInf;
|
||||
if(pObj->Name.isRef()) pObj->Name = cInf->Name;
|
||||
pObj->SetName(cInf->Name);
|
||||
}
|
||||
|
||||
// Add to crew
|
||||
|
|
|
@ -40,6 +40,28 @@ C4PropList::~C4PropList()
|
|||
while (FirstRef) FirstRef->Set(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char * C4PropList::GetName()
|
||||
{
|
||||
C4String * s = GetPropertyStr(P_Name);
|
||||
if (!s) return "";
|
||||
return s->GetCStr();
|
||||
}
|
||||
|
||||
void C4PropList::SetName(const char* NewName)
|
||||
{
|
||||
if(!NewName)
|
||||
ResetProperty(Strings.P[P_Name]);
|
||||
else
|
||||
{
|
||||
C4Value v = C4VString(NewName);
|
||||
SetProperty(Strings.P[P_Name], v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<> template<>
|
||||
unsigned int C4Set<C4Property>::Hash<C4String *>(C4String * e)
|
||||
{
|
||||
|
@ -59,6 +81,12 @@ unsigned int C4Set<C4Property>::Hash<C4Property>(C4Property p)
|
|||
}
|
||||
bool C4PropList::GetProperty(C4String * k, C4Value & to)
|
||||
{
|
||||
// The prototype is special
|
||||
if (k == Strings.P[P_Prototype])
|
||||
{
|
||||
to = C4VPropList(prototype);
|
||||
return true;
|
||||
}
|
||||
if (Properties.Has(k))
|
||||
{
|
||||
to.SetRef(&Properties.Get(k).Value);
|
||||
|
@ -71,8 +99,41 @@ bool C4PropList::GetProperty(C4String * k, C4Value & to)
|
|||
return false;
|
||||
}
|
||||
|
||||
void C4PropList::SetProperty(C4String * k, C4Value & to)
|
||||
C4String * C4PropList::GetPropertyStr(C4PropertyName n)
|
||||
{
|
||||
C4String * k = Strings.P[n];
|
||||
if (Properties.Has(k))
|
||||
{
|
||||
return Properties.Get(k).Value.getStr();
|
||||
}
|
||||
if (prototype)
|
||||
{
|
||||
return prototype->GetPropertyStr(n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t C4PropList::GetPropertyInt(C4PropertyName n)
|
||||
{
|
||||
C4String * k = Strings.P[n];
|
||||
if (Properties.Has(k))
|
||||
{
|
||||
return Properties.Get(k).Value.getInt();
|
||||
}
|
||||
if (prototype)
|
||||
{
|
||||
return prototype->GetPropertyInt(n);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void C4PropList::SetProperty(C4String * k, const C4Value & to)
|
||||
{
|
||||
if (k == Strings.P[P_Prototype] && to.GetType() == C4V_PropList)
|
||||
{
|
||||
prototype = to.GetData().PropList;
|
||||
return;
|
||||
}
|
||||
if (Properties.Has(k))
|
||||
{
|
||||
Properties.Get(k).Value = to;
|
||||
|
@ -82,6 +143,9 @@ void C4PropList::SetProperty(C4String * k, C4Value & to)
|
|||
C4Property p = { k, to };
|
||||
Properties.Add(p);
|
||||
}
|
||||
if (k == Strings.P[P_PROTOTYPE])
|
||||
prototype = to.getPropList();
|
||||
}
|
||||
|
||||
void C4PropList::ResetProperty(C4String * k)
|
||||
{
|
||||
Properties.Remove(k);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ void C4String::DecRef()
|
|||
|
||||
C4StringTable::C4StringTable()
|
||||
{
|
||||
P[P_PROTOTYPE] = RegString("Prototype");
|
||||
P[P_Prototype] = RegString("Prototype");
|
||||
P[P_Name] = RegString("Name");
|
||||
for (unsigned int i = 0; i < P_LAST; ++i) P[i]->IncRef();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue