//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.EventControl.EventTypes
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Text;
using System.Xml;
using DarkWynter.Engine.Globals;
using DarkWynter.Engine.Controllers;
using DarkWynter.Engine.Utilities;
using DarkWynter.Stream;
///
/// Instance of a TerrainEvent
/// Extends GameEvent
/// Used to raise/lower terrain programatically
///
public class TerrainEvent : GameEvent
{
///
/// Timer to set on the terrainMod
///
public int timer { get { return _timer; } set { _timer = value; } }
private int _timer;
///
/// Where to start the terrainMod
///
public Vector3 startPosition { get { return _startPosition; } set { _startPosition = value; } }
private Vector3 _startPosition;
///
/// Where to end the terrainMod
///
public Vector3 endPosition { get { return _endPosition; } set { _endPosition = value; } }
private Vector3 _endPosition;
///
/// How high for the terrainMod
///
public float modamount { get { return _modamount; } set { _modamount = value; } }
private float _modamount;
private int terrainTimer;
private float amount;
private Vector3 StartPosition;
private Vector3 EndPosition;
private int radius;
Draw drawStart;
Draw drawEnd;
///
/// Creates the TerrainEvent from XML
/// Has a model to draw for LevelEditing
///
/// XML Node
/// Radius
public TerrainEvent(XmlNode node, int rad)
: base(node)
{
this.typeID = node.Attributes["typeID"].Value;
this.timer = int.Parse(node.Attributes["timer"].Value);
Vector3 startPosition = new Vector3(
float.Parse(node.Attributes["startX"].Value),
float.Parse(node.Attributes["startY"].Value),
float.Parse(node.Attributes["startZ"].Value));
this.startPosition = startPosition;
Vector3 endPosition = new Vector3(
float.Parse(node.Attributes["endX"].Value),
float.Parse(node.Attributes["endY"].Value),
float.Parse(node.Attributes["endZ"].Value));
this.endPosition = endPosition;
this.modamount = (float.Parse(node.Attributes["modamount"].Value));
eventLimitMilli = 2000;
terrainTimer = timer;
amount = modamount;
StartPosition = startPosition;
EndPosition = endPosition;
radius = rad;
drawStart = new Draw(Enums_Stream.DrawMethod.BasicGameObject_Draw, "BasicLightingShaderMain");
drawStart.textureList = new List();
drawStart.textureList.Add(Statics_Engine.SystemSettings.content.Load("Content/_textures/fire"));
drawStart.textureList.Add(Statics_Engine.SystemSettings.content.Load("Content/_textures/fire"));
drawStart.model = Statics_Engine.SystemSettings.content.Load("Content/_models/GenericCube");
foreach (ModelMesh mesh in drawStart.model.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
// Add effect to mesh
mesh.MeshParts[i].Effect = ShaderParameters.DrawFX.effect;
}
}
drawEnd = new Draw(Enums_Stream.DrawMethod.BasicGameObject_Draw, "BasicLightingShaderMain");
drawEnd.textureList = new List();
drawEnd.textureList.Add(Statics_Engine.SystemSettings.content.Load("Content/_textures/bomb4"));
drawEnd.textureList.Add(Statics_Engine.SystemSettings.content.Load("Content/_textures/bomb4"));
drawEnd.model = Statics_Engine.SystemSettings.content.Load("Content/_models/GenericCube");
foreach (ModelMesh mesh in drawEnd.model.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
// Add effect to mesh
mesh.MeshParts[i].Effect = ShaderParameters.DrawFX.effect;
}
}
}
///
/// Sends the terrainMod as a request to MajikWand.cs for build
///
public override void FireEvent()
{
Vector3 normal = EndPosition - StartPosition;
normal.Normalize();
int borderRadius = 1;
int boarderHeight = 1;
// Create border along path
TerrainModRequest requestBorder = new TerrainModRequest(
terrainTimer,
amount + boarderHeight,
StartPosition + (normal * new Vector3(borderRadius)),
EndPosition - (normal * new Vector3(borderRadius + 2)),
radius + borderRadius,
Enums_Engine.TerrainModType.EQUALTO);
DarkWynter.Engine.Controllers.GameController.NonControllerBasedTerrainMod(requestBorder);
// Mod the terrain
TerrainModRequest request = new TerrainModRequest(
terrainTimer,
amount,
StartPosition,
EndPosition,
radius,
Enums_Engine.TerrainModType.EQUALTO);
DarkWynter.Engine.Controllers.GameController.NonControllerBasedTerrainMod(request);
//if (MajikWand.activeRequestCount == 0)
//{
isFinished = true;
//}
//else isFinished = false;
}
///
/// Adds the Terrain model to the draw list for LevelEditing
///
/// Returns the drawList
public override List Draw()
{
Vector3 position = this.startPosition * DarkWynter.Engine.Globals.Statics_Engine.TerrainSettings.terrainScaleFactor;
position.Y = 800;
// Calculate ObjectSpace(Rotation) and WorldSpace(Translation) Transformation Matrix
drawStart.matrix =
drawStart.initialTransform *
Matrix.CreateScale(300) *
Matrix.CreateTranslation(position);
position = this.endPosition * DarkWynter.Engine.Globals.Statics_Engine.TerrainSettings.terrainScaleFactor;
position.Y = 800;
// Calculate ObjectSpace(Rotation) and WorldSpace(Translation) Transformation Matrix
drawEnd.matrix =
drawEnd.initialTransform *
Matrix.CreateScale(300) *
Matrix.CreateTranslation(position);
drawList.Clear();
drawList.Add(drawStart);
drawList.Add(drawEnd);
return drawList;
}
///
/// Create XML for TerrainEvents
///
/// string
public override string ToXml()
{
string xml =
"typeID=" + this.typeID +
"timer=" + this.timer +
"modamount=" + this.modamount +
"node=" + this._lastNodeVisited+
"coins=" + this._triggerCoins+
"sanity=" + this._triggerSanity +
"startX=" + this.startPosition.X +
"startY=" + this.startPosition.Y +
"startZ=" + this.startPosition.Z +
"endX=" + this.endPosition.X +
"endY=" + this.endPosition.Y +
"endZ=" + this.endPosition.Z;
return xml;
}
}
}