From 9ef297b3a782a323923e1333554bdd8282060c66 Mon Sep 17 00:00:00 2001 From: joris <joris.dauphin@gmail.com> Date: Sun, 19 Feb 2012 10:18:17 +0100 Subject: [PATCH] [+]New unit-type flag "NonSolid", which allow the building to be entered by other units. The same behaviour occur if you set the building's health to 0. Patch from Cybermind --- src/include/unittype.h | 2 ++ src/unit/script_unittype.cpp | 7 ++++++- src/unit/unittype.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/include/unittype.h b/src/include/unittype.h index 9fd7058f0..1f121bd20 100644 --- a/src/include/unittype.h +++ b/src/include/unittype.h @@ -645,6 +645,7 @@ enum { TELEPORTER_INDEX, SHIELDPIERCE_INDEX, SAVECARGO_INDEX, + NONSOLID_INDEX, WALL_INDEX, NBARALREADYDEFINED }; @@ -1011,6 +1012,7 @@ public: unsigned Teleporter : 1; /// Can teleport other units. unsigned ShieldPiercing : 1; /// Can directly damage shield-protected units, without shield damaging. unsigned SaveCargo : 1; /// Unit unloads his passengers after death. + unsigned NonSolid : 1; /// Unit can be entered by other units. unsigned Wall : 1; /// Use special logic for Direction field. CVariable *Variable; /// Array of user defined variables. diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index 88240f869..ac07b9d4a 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -106,7 +106,9 @@ static const char INDESTRUCTIBLE_KEY[] = "Indestructible"; static const char TELEPORTER_KEY[] = "Teleporter"; static const char SHIELDPIERCE_KEY[] = "ShieldPiercing"; static const char SAVECARGO_KEY[] = "LoseCargo"; +static const char NONSOLID_KEY[] = "NonSolid"; static const char WALL_KEY[] = "Wall"; + // names of the variable. static const char HITPOINTS_KEY[] = "HitPoints"; static const char BUILD_KEY[] = "Build"; @@ -154,7 +156,7 @@ CUnitTypeVar::CBoolKeys::CBoolKeys() { SHOREBUILDING_KEY, CANATTACK_KEY,BUILDEROUTSIDE_KEY, BUILDERLOST_KEY,CANHARVEST_KEY,HARVESTER_KEY,SELECTABLEBYRECTANGLE_KEY, ISNOTSELECTABLE_KEY,DECORATION_KEY,INDESTRUCTIBLE_KEY,TELEPORTER_KEY,SHIELDPIERCE_KEY, - SAVECARGO_KEY, WALL_KEY}; + SAVECARGO_KEY, NONSOLID_KEY, WALL_KEY}; for (int i = 0; i < NBARALREADYDEFINED; ++i) { buildin[i].offset = i; @@ -1049,6 +1051,8 @@ static int CclDefineUnitType(lua_State *l) type->ShieldPiercing = LuaToBoolean(l, -1); } else if (!strcmp(value, "SaveCargo")) { type->SaveCargo = LuaToBoolean(l, -1); + } else if (!strcmp(value, "NonSolid")) { + type->NonSolid = LuaToBoolean(l, -1); } else if (!strcmp(value, "Wall")) { type->Wall = LuaToBoolean(l, -1); } else if (!strcmp(value, "Sounds")) { @@ -2304,6 +2308,7 @@ void UpdateUnitVariables(const CUnit &unit) type->BoolFlag[TELEPORTER_INDEX].value = type->Teleporter; type->BoolFlag[SHIELDPIERCE_INDEX].value = type->ShieldPiercing; type->BoolFlag[SAVECARGO_INDEX].value = type->SaveCargo; + type->BoolFlag[NONSOLID_INDEX].value = type->NonSolid; type->BoolFlag[WALL_INDEX].value = type->Wall; } diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index 0d8caa912..b2d59a758 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -133,7 +133,7 @@ CUnitType::CUnitType() : BuilderOutside(0), BuilderLost(0), CanHarvest(0), Harvester(0), Neutral(0), SelectableByRectangle(0), IsNotSelectable(0), Decoration(0), Indestructible(0), Teleporter(0), ShieldPiercing(0), SaveCargo(0), - Wall(0), Variable(NULL), + NonSolid(0), Wall(0), Variable(NULL), GivesResource(0), Supply(0), Demand(0), FieldFlags(0), MovementMask(0), Sprite(NULL), ShadowSprite(NULL) { @@ -289,13 +289,13 @@ void UpdateStats(int reset) } type->MovementMask |= MapFieldNoBuilding; // - // A little chaos, buildings without HP can be entered. + // A little chaos, buildings without HP or with special flag can be entered. // The oil-patch is a very special case. // - if (type->Variable[HP_INDEX].Max) { - type->FieldFlags = MapFieldBuilding; - } else { + if (type->NonSolid || !type->Variable[HP_INDEX].Max) { type->FieldFlags = MapFieldNoBuilding; + } else { + type->FieldFlags = MapFieldBuilding; } } else switch (type->UnitType) { case UnitTypeLand: // on land