2007-06-14 14:44:18 +00:00
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
2007-06-14 14:44:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
2007-06-14 12:37:46 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Text;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
2007-06-14 23:31:57 +00:00
|
|
|
#endregion
|
|
|
|
|
2007-06-14 12:37:46 +00:00
|
|
|
namespace CodeImp.DoomBuilder.Map
|
|
|
|
{
|
|
|
|
internal class Thing : IDisposable
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
public static readonly byte[] EMPTY_ARGS = new byte[5];
|
|
|
|
|
2007-06-14 12:37:46 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Map
|
2007-06-14 13:09:55 +00:00
|
|
|
private MapSet map;
|
2007-06-14 12:37:46 +00:00
|
|
|
|
|
|
|
// Sector
|
|
|
|
private Sector sector = null;
|
|
|
|
|
|
|
|
// List items
|
|
|
|
private LinkedListNode<Thing> mainlistitem;
|
|
|
|
private LinkedListNode<Thing> sectorlistitem;
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
private int type;
|
2007-06-24 18:56:43 +00:00
|
|
|
private Vector3D pos;
|
2007-06-14 12:37:46 +00:00
|
|
|
private float angle;
|
2007-06-24 18:56:43 +00:00
|
|
|
private int flags;
|
|
|
|
private int tag;
|
|
|
|
private int action;
|
|
|
|
private byte[] args;
|
2007-06-14 12:37:46 +00:00
|
|
|
|
|
|
|
// Disposing
|
|
|
|
private bool isdisposed = false;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-07-07 09:40:34 +00:00
|
|
|
public MapSet Map { get { return map; } }
|
2007-06-14 13:09:55 +00:00
|
|
|
public int Type { get { return type; } }
|
2007-06-24 18:56:43 +00:00
|
|
|
public Vector3D Position { get { return pos; } }
|
2007-06-14 12:37:46 +00:00
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
2007-10-14 15:44:55 +00:00
|
|
|
public float Angle { get { return angle; } }
|
|
|
|
public int Flags { get { return flags; } }
|
2007-06-14 12:37:46 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2007-06-24 18:56:43 +00:00
|
|
|
public Thing(MapSet map, LinkedListNode<Thing> listitem)
|
2007-06-14 12:37:46 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.map = map;
|
|
|
|
this.mainlistitem = listitem;
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diposer
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Already set isdisposed so that changes can be prohibited
|
|
|
|
isdisposed = true;
|
|
|
|
|
|
|
|
// Remove from main list
|
|
|
|
mainlistitem.List.Remove(mainlistitem);
|
|
|
|
|
|
|
|
// Remove from sector
|
|
|
|
if(sector != null) sector.DetachThing(sectorlistitem);
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
mainlistitem = null;
|
|
|
|
sectorlistitem = null;
|
|
|
|
map = null;
|
|
|
|
sector = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Management
|
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// This copies all properties to another thing
|
|
|
|
public void CopyPropertiesTo(Thing t)
|
|
|
|
{
|
|
|
|
// Copy properties
|
|
|
|
t.type = type;
|
|
|
|
t.angle = angle;
|
|
|
|
t.pos = pos;
|
|
|
|
t.flags = flags;
|
|
|
|
t.tag = tag;
|
|
|
|
t.action = action;
|
|
|
|
t.args = EMPTY_ARGS;
|
|
|
|
args.CopyTo(t.args, 0);
|
|
|
|
}
|
|
|
|
|
2007-06-14 12:37:46 +00:00
|
|
|
// This determines which sector the thing is in and links it
|
|
|
|
public void DetermineSector()
|
|
|
|
{
|
|
|
|
Sector newsector = null;
|
|
|
|
Vertex nv;
|
|
|
|
Linedef nl;
|
|
|
|
|
|
|
|
// Find the nearest vertex on the map
|
|
|
|
nv = map.NearestVertex(pos);
|
|
|
|
if(nv != null)
|
|
|
|
{
|
|
|
|
// Find the nearest linedef on the vertex
|
|
|
|
nl = nv.NearestLinedef(pos);
|
|
|
|
if(nl != null)
|
|
|
|
{
|
|
|
|
// Check what side of line we are at
|
|
|
|
if(nl.SideOfLine(pos) < 0f)
|
|
|
|
{
|
|
|
|
// Front side
|
|
|
|
if(nl.Front != null) newsector = nl.Front.Sector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Back side
|
|
|
|
if(nl.Back != null) newsector = nl.Back.Sector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently attached to a sector and sector changes?
|
|
|
|
if((sector != null) && (newsector != sector))
|
|
|
|
{
|
|
|
|
// Remove from current sector
|
|
|
|
sector.DetachThing(sectorlistitem);
|
|
|
|
sectorlistitem = null;
|
|
|
|
sector = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach to new sector?
|
|
|
|
if((newsector != null) && (newsector != sector))
|
|
|
|
{
|
|
|
|
// Attach to new sector
|
|
|
|
sector = newsector;
|
|
|
|
sectorlistitem = sector.AttachThing(this);
|
|
|
|
}
|
|
|
|
}
|
2007-06-24 18:56:43 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Changes
|
2007-06-14 12:37:46 +00:00
|
|
|
|
2007-06-24 18:56:43 +00:00
|
|
|
// This moves the thing
|
|
|
|
// NOTE: This does not update sector! (call DetermineSector)
|
|
|
|
public void Move(Vector3D newpos)
|
2007-06-14 13:09:55 +00:00
|
|
|
{
|
2007-06-24 18:56:43 +00:00
|
|
|
// Change position
|
|
|
|
pos = newpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This rotates the thing
|
|
|
|
public void Rotate(float newangle)
|
|
|
|
{
|
|
|
|
// Change angle
|
|
|
|
angle = newangle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This updates all properties
|
|
|
|
// NOTE: This does not update sector! (call DetermineSector)
|
|
|
|
public void Update(int type, Vector3D pos, float angle,
|
|
|
|
int flags, int tag, int action, byte[] args)
|
|
|
|
{
|
|
|
|
// Apply changes
|
|
|
|
this.type = type;
|
|
|
|
this.pos = pos;
|
|
|
|
this.angle = angle;
|
|
|
|
this.flags = flags;
|
|
|
|
this.tag = tag;
|
|
|
|
this.action = action;
|
|
|
|
this.args = args;
|
2007-06-14 13:09:55 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 12:37:46 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|