mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -07:00
Allow boolean and u16 modifications for C++
Allow boolean modifications JavaScript Allow territory influence weight, and root, to be changed via tech. Differential Revision: https://code.wildfiregames.com/D3069 This was SVN commit r24373.
This commit is contained in:
parent
c013ee3778
commit
bf85e4ac38
4 changed files with 48 additions and 12 deletions
|
|
@ -23,9 +23,25 @@ function GetTechModifiedProperty(modifications, classes, originalValue)
|
|||
// is about as efficient, but splitting makes it easier to report errors.
|
||||
if (typeof originalValue === "string")
|
||||
return GetTechModifiedProperty_string(modifications, classes, originalValue);
|
||||
return GetTechModifiedProperty_numeric(modifications, classes, originalValue);
|
||||
if (typeof originalValue === "number")
|
||||
return GetTechModifiedProperty_numeric(modifications, classes, originalValue);
|
||||
return GetTechModifiedProperty_generic(modifications, classes, originalValue);
|
||||
}
|
||||
|
||||
function GetTechModifiedProperty_generic(modifications, classes, originalValue)
|
||||
{
|
||||
for (let modification of modifications)
|
||||
{
|
||||
if (!DoesModificationApply(modification, classes))
|
||||
continue;
|
||||
if (!modification.replace)
|
||||
warn("GetTechModifiedProperty: modification format not recognised : " + uneval(modification));
|
||||
|
||||
return modification.replace;
|
||||
}
|
||||
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
function GetTechModifiedProperty_numeric(modifications, classes, originalValue)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
|
|
@ -75,12 +75,20 @@ public:
|
|||
|
||||
virtual bool IsRoot() const
|
||||
{
|
||||
return m_Root;
|
||||
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
|
||||
if (!cmpValueModificationManager)
|
||||
return m_Root;
|
||||
|
||||
return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Root", m_Root, GetEntityId());
|
||||
}
|
||||
|
||||
virtual u16 GetWeight() const
|
||||
{
|
||||
return m_Weight;
|
||||
CmpPtr<ICmpValueModificationManager> cmpValueModificationManager(GetSystemEntity());
|
||||
if (!cmpValueModificationManager)
|
||||
return m_Weight;
|
||||
|
||||
return cmpValueModificationManager->ApplyModifications(L"TerritoryInfluence/Weight", m_Weight, GetEntityId());
|
||||
}
|
||||
|
||||
virtual u32 GetRadius() const
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
|
|
@ -30,20 +30,30 @@ class CCmpValueModificationManagerScripted : public ICmpValueModificationManager
|
|||
public:
|
||||
DEFAULT_SCRIPT_WRAPPER(ValueModificationManagerScripted)
|
||||
|
||||
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity)
|
||||
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) const
|
||||
{
|
||||
return m_Script.Call<fixed>("ApplyModifications", valueName, currentValue, entity);
|
||||
}
|
||||
|
||||
virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity)
|
||||
virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) const
|
||||
{
|
||||
return m_Script.Call<u32>("ApplyModifications", valueName, currentValue, entity);
|
||||
}
|
||||
|
||||
virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity)
|
||||
virtual u16 ApplyModifications(std::wstring valueName, u16 currentValue, entity_id_t entity) const
|
||||
{
|
||||
return m_Script.Call<u16>("ApplyModifications", valueName, currentValue, entity);
|
||||
}
|
||||
|
||||
virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) const
|
||||
{
|
||||
return m_Script.Call<std::wstring>("ApplyModifications", valueName, currentValue, entity);
|
||||
}
|
||||
|
||||
virtual bool ApplyModifications(std::wstring valueName, bool currentValue, entity_id_t entity) const
|
||||
{
|
||||
return m_Script.Call<bool>("ApplyModifications", valueName, currentValue, entity);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_COMPONENT_SCRIPT_WRAPPER(ValueModificationManagerScripted)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2012 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
|
|
@ -30,9 +30,11 @@
|
|||
class ICmpValueModificationManager : public IComponent
|
||||
{
|
||||
public:
|
||||
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) = 0;
|
||||
virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) = 0;
|
||||
virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) = 0;
|
||||
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) const = 0;
|
||||
virtual u32 ApplyModifications(std::wstring valueName, u32 currentValue, entity_id_t entity) const = 0;
|
||||
virtual u16 ApplyModifications(std::wstring valueName, u16 currentValue, entity_id_t entity) const = 0;
|
||||
virtual std::wstring ApplyModifications(std::wstring valueName, std::wstring currentValue, entity_id_t entity) const = 0;
|
||||
virtual bool ApplyModifications(std::wstring valueName, bool currentValue, entity_id_t entity) const = 0;
|
||||
|
||||
DECLARE_INTERFACE_TYPE(ValueModificationManager)
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue