Add EditorPlacementLimit property

Limits the number of object instances that can be placed of a given def.
qteditor
Sven Eberhardt 2016-08-06 02:36:53 -04:00
parent c15a821a51
commit fc24969899
5 changed files with 19 additions and 1 deletions

View File

@ -44,6 +44,7 @@ IDS_CNS_CONTENTS=Inhalt:
IDS_CNS_CREATE=Erzeugen
IDS_CNS_CREATESTATUS=Platzierung: %s
IDS_CNS_CREATOR=Objekte erstellen
IDS_CNS_CREATORTOOMANYINSTANCES=Fehler beim Erstellen: Von diesem Objekttyp koennen maximal %d Objekte platziert werden.
IDS_CNS_DEFINITIONS=Definitionen
IDS_CNS_DESCRIPTION=Beschreibung
IDS_CNS_DROPNODEF=Ungültiges oder nicht geladenes Objekt: %s

View File

@ -44,6 +44,7 @@ IDS_CNS_CONTENTS=Contents:
IDS_CNS_CREATE=Create
IDS_CNS_CREATESTATUS=Place new %s
IDS_CNS_CREATOR=Create objects
IDS_CNS_CREATORTOOMANYINSTANCES=Error creating object: Maximum instance count of %d reached for this object type.
IDS_CNS_DEFINITIONS=Definitions
IDS_CNS_DESCRIPTION=Description
IDS_CNS_DROPNODEF=Object invalid or not loaded: %s

View File

@ -1353,6 +1353,20 @@ void C4ControlEMMoveObject::Execute() const
break;
case EMMO_Create:
{
// Check max object count
C4ID iddef = C4ID(StringParam);
C4Def *def = C4Id2Def(iddef);
if (!def) return;
int32_t placement_limit = def->GetPropertyInt(P_EditorPlacementLimit);
if (placement_limit)
{
if (Game.ObjectCount(iddef) >= placement_limit)
{
// Too many objects
::Console.Message(FormatString(LoadResStr("IDS_CNS_CREATORTOOMANYINSTANCES"), int(placement_limit)).getData());
return;
}
}
// Create object outside or contained
// If container is desired but not valid, do nothing (don't create object outside instead)
C4Object *container = NULL;
@ -1366,7 +1380,7 @@ void C4ControlEMMoveObject::Execute() const
// Qt editor: Object creation is done through creator; centered creation is usually more convenient
create_centered = true;
#endif
C4Object *obj = ::Game.CreateObject(C4ID(StringParam), nullptr, NO_OWNER, fixtoi(tx), fixtoi(ty), 0, create_centered);
C4Object *obj = ::Game.CreateObject(iddef, nullptr, NO_OWNER, fixtoi(tx), fixtoi(ty), 0, create_centered);
if (container && obj && container->Status && obj->Status) obj->Enter(container);
if (obj && obj->Status) obj->Call(P_EditorInitialize); // specific initialization when placed in editor
}

View File

@ -290,6 +290,7 @@ C4StringTable::C4StringTable()
P[P_Description] = "Description";
P[P_AllowEditing] = "AllowEditing";
P[P_EditorInitialize] = "EditorInitialize";
P[P_EditorPlacementLimit] = "EditorPlacementLimit";
P[DFA_WALK] = "WALK";
P[DFA_FLIGHT] = "FLIGHT";
P[DFA_KNEEL] = "KNEEL";

View File

@ -514,6 +514,7 @@ enum C4PropertyName
P_Description,
P_AllowEditing,
P_EditorInitialize,
P_EditorPlacementLimit,
// Default Action Procedures
DFA_WALK,
DFA_FLIGHT,