Parse MF_SOLID and MF_SPAWNCEILING for custom Things

This commit is contained in:
MascaraSnake 2017-10-10 09:17:42 +02:00
parent c5173df759
commit d731c29235
4 changed files with 151 additions and 16 deletions

View file

@ -420,8 +420,8 @@ namespace CodeImp.DoomBuilder.Config
this.arrow = (cat.Arrow != 0); this.arrow = (cat.Arrow != 0);
this.radius = o.radius; this.radius = o.radius;
this.height = o.height; this.height = o.height;
this.hangs = (cat.Hangs != 0); this.hangs = o.Hangs();
this.blocking = cat.Blocking; this.blocking = o.Blocking() ? 2 : 0;
this.errorcheck = cat.ErrorCheck; this.errorcheck = cat.ErrorCheck;
this.fixedsize = cat.FixedSize; this.fixedsize = cat.FixedSize;
this.fixedrotation = cat.FixedRotation; //mxd this.fixedrotation = cat.FixedRotation; //mxd

View file

@ -30,6 +30,39 @@ namespace CodeImp.DoomBuilder.SRB2
private List<string> objectfreeslots; private List<string> objectfreeslots;
private List<string> statefreeslots; private List<string> statefreeslots;
private List<string> spritefreeslots;*/ private List<string> spritefreeslots;*/
private IDictionary<string, int> flagValues = new Dictionary<string,int>
{
{ "MF_SPECIAL", 0x1 },
{ "MF_SOLID", 0x2 },
{ "MF_SHOOTABLE", 0x4 },
{ "MF_NOSECTOR", 0x8 },
{ "MF_NOBLOCKMAP", 0x10 },
{ "MF_AMBUSH", 0x20 },
{ "MF_PUSHABLE", 0x40 },
{ "MF_BOSS", 0x80 },
{ "MF_SPAWNCEILING", 0x100 },
{ "MF_NOGRAVITY", 0x200 },
{ "MF_AMBIENT", 0x400 },
{ "MF_SLIDEME", 0x800 },
{ "MF_NOCLIP", 0x1000 },
{ "MF_FLOAT", 0x2000 },
{ "MF_BOXICON", 0x4000 },
{ "MF_MISSILE", 0x8000 },
{ "MF_SPRING", 0x10000 },
{ "MF_BOUNCE", 0x20000 },
{ "MF_MONITOR", 0x40000 },
{ "MF_NOTHINK", 0x80000 },
{ "MF_FIRE", 0x100000 },
{ "MF_NOCLIPHEIGHT", 0x200000 },
{ "MF_ENEMY", 0x400000 },
{ "MF_SCENERY", 0x800000 },
{ "MF_PAIN", 0x1000000 },
{ "MF_STICKY", 0x2000000 },
{ "MF_NIGHTSITEM", 0x4000000 },
{ "MF_NOCLIPTHING", 0x8000000 },
{ "MF_GRENADEBOUNCE", 0x10000000 },
{ "MF_RUNSPAWNFUNC", 0x10000000 }
};
#endregion #endregion
@ -93,6 +126,7 @@ namespace CodeImp.DoomBuilder.SRB2
int mapThingNum = -1; int mapThingNum = -1;
int radius = 0; int radius = 0;
int height = 0; int height = 0;
int flags = 0;
SkipWhitespace(true); SkipWhitespace(true);
token = ReadToken(); token = ReadToken();
@ -190,6 +224,11 @@ namespace CodeImp.DoomBuilder.SRB2
if (!ReadParameter(out token, out finished)) return false; if (!ReadParameter(out token, out finished)) return false;
states[7] = token; states[7] = token;
break; break;
case "flags":
if (!ReadParameter(out token, out finished)) return false;
if (!ParseFlags(token, out flags))
LogWarning("Could not parse flags");
break;
case "spawnhealth": case "spawnhealth":
case "seesound": case "seesound":
case "reactiontime": case "reactiontime":
@ -202,7 +241,6 @@ namespace CodeImp.DoomBuilder.SRB2
case "mass": case "mass":
case "damage": case "damage":
case "activesound": case "activesound":
case "flags":
if (!ReadParameter(out token, out finished)) return false; if (!ReadParameter(out token, out finished)) return false;
break; break;
case "}": case "}":
@ -228,7 +266,7 @@ namespace CodeImp.DoomBuilder.SRB2
if (mapThingNum > 0) if (mapThingNum > 0)
{ {
SRB2Object o = new SRB2Object(name, sprite, category, states, mapThingNum, radius, height); SRB2Object o = new SRB2Object(name, sprite, category, states, mapThingNum, radius, height, flags);
if (objects.ContainsKey(objname)) if (objects.ContainsKey(objname))
objects[objname] = o; objects[objname] = o;
else else
@ -630,6 +668,27 @@ namespace CodeImp.DoomBuilder.SRB2
return true; return true;
} }
private bool ParseFlags(string input, out int output)
{
output = 0;
string[] tokens = input.Split(new char[] { '|' });
foreach (string token in tokens)
{
if (flagValues.ContainsKey(token))
{
output |= flagValues[token];
}
else
{
int val = 0;
if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out val))
return false;
output |= val;
}
}
return true;
}
protected override string GetLanguageType() protected override string GetLanguageType()
{ {
return "Lua"; return "Lua";

View file

@ -30,6 +30,39 @@ namespace CodeImp.DoomBuilder.SRB2
private List<string> objectfreeslots; private List<string> objectfreeslots;
private List<string> statefreeslots; private List<string> statefreeslots;
private List<string> spritefreeslots;*/ private List<string> spritefreeslots;*/
private IDictionary<string, int> flagValues = new Dictionary<string, int>
{
{ "MF_SPECIAL", 0x1 },
{ "MF_SOLID", 0x2 },
{ "MF_SHOOTABLE", 0x4 },
{ "MF_NOSECTOR", 0x8 },
{ "MF_NOBLOCKMAP", 0x10 },
{ "MF_AMBUSH", 0x20 },
{ "MF_PUSHABLE", 0x40 },
{ "MF_BOSS", 0x80 },
{ "MF_SPAWNCEILING", 0x100 },
{ "MF_NOGRAVITY", 0x200 },
{ "MF_AMBIENT", 0x400 },
{ "MF_SLIDEME", 0x800 },
{ "MF_NOCLIP", 0x1000 },
{ "MF_FLOAT", 0x2000 },
{ "MF_BOXICON", 0x4000 },
{ "MF_MISSILE", 0x8000 },
{ "MF_SPRING", 0x10000 },
{ "MF_BOUNCE", 0x20000 },
{ "MF_MONITOR", 0x40000 },
{ "MF_NOTHINK", 0x80000 },
{ "MF_FIRE", 0x100000 },
{ "MF_NOCLIPHEIGHT", 0x200000 },
{ "MF_ENEMY", 0x400000 },
{ "MF_SCENERY", 0x800000 },
{ "MF_PAIN", 0x1000000 },
{ "MF_STICKY", 0x2000000 },
{ "MF_NIGHTSITEM", 0x4000000 },
{ "MF_NOCLIPTHING", 0x8000000 },
{ "MF_GRENADEBOUNCE", 0x10000000 },
{ "MF_RUNSPAWNFUNC", 0x10000000 }
};
private StreamReader streamreader; private StreamReader streamreader;
private int linenumber; private int linenumber;
@ -145,6 +178,7 @@ namespace CodeImp.DoomBuilder.SRB2
int mapThingNum = -1; int mapThingNum = -1;
int radius = 0; int radius = 0;
int height = 0; int height = 0;
int flags = 0;
while (!streamreader.EndOfStream) while (!streamreader.EndOfStream)
{ {
string line = streamreader.ReadLine(); string line = streamreader.ReadLine();
@ -224,11 +258,15 @@ namespace CodeImp.DoomBuilder.SRB2
case "RAISESTATE": case "RAISESTATE":
states[7] = tokens[1]; states[7] = tokens[1];
break; break;
case "FLAGS":
if (!ParseFlags(tokens[1], out flags))
LogWarning("Could not parse flags");
break;
} }
} }
if (mapThingNum > 0) if (mapThingNum > 0)
{ {
SRB2Object o = new SRB2Object(name, sprite, category, states, mapThingNum, radius, height); SRB2Object o = new SRB2Object(name, sprite, category, states, mapThingNum, radius, height, flags);
if (objects.ContainsKey(objname)) if (objects.ContainsKey(objname))
objects[objname] = o; objects[objname] = o;
else else
@ -314,6 +352,27 @@ namespace CodeImp.DoomBuilder.SRB2
return true; return true;
} }
private bool ParseFlags(string input, out int output)
{
output = 0;
string[] tokens = input.Split(new char[] { '|' });
foreach (string token in tokens)
{
if (flagValues.ContainsKey(token))
{
output |= flagValues[token];
}
else
{
int val = 0;
if (!int.TryParse(token, NumberStyles.Integer, CultureInfo.InvariantCulture, out val))
return false;
output |= val;
}
}
return true;
}
// This reports an error // This reports an error
protected internal override void ReportError(string message) protected internal override void ReportError(string message)
{ {

View file

@ -28,6 +28,9 @@ namespace CodeImp.DoomBuilder.SRB2
{ {
#region ================== Constants #region ================== Constants
public const int MF_SOLID = 0x2;
public const int MF_SPAWNCEILING = 0x100;
#endregion #endregion
#region ================== Variables #region ================== Variables
@ -39,13 +42,14 @@ namespace CodeImp.DoomBuilder.SRB2
public readonly int mapThingNum; public readonly int mapThingNum;
public readonly int radius; public readonly int radius;
public readonly int height; public readonly int height;
public readonly int flags;
#endregion #endregion
#region ================== Constructor / Disposer #region ================== Constructor / Disposer
// Constructor // Constructor
internal SRB2Object(string name, string sprite, string category, string[] states, int mapThingNum, int radius, int height) internal SRB2Object(string name, string sprite, string category, string[] states, int mapThingNum, int radius, int height, int flags)
{ {
this.name = name; this.name = name;
this.sprite = sprite; this.sprite = sprite;
@ -54,8 +58,21 @@ namespace CodeImp.DoomBuilder.SRB2
this.mapThingNum = mapThingNum; this.mapThingNum = mapThingNum;
this.radius = radius; this.radius = radius;
this.height = height; this.height = height;
this.flags = flags;
} }
#endregion #endregion
#region ================== Methods
internal bool Blocking()
{
return (flags & MF_SOLID) == MF_SOLID;
}
internal bool Hangs()
{
return (flags & MF_SPAWNCEILING) == MF_SPAWNCEILING;
}
#endregion
} }
} }