Add initial game code
This commit is contained in:
parent
f80a60e208
commit
1383997ebf
55 changed files with 1355 additions and 0 deletions
136
scripts/GameObjects/Structure.cs
Normal file
136
scripts/GameObjects/Structure.cs
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
public partial class Structure : GameObject
|
||||
{
|
||||
public Order CurrentOrder { get; protected set; }
|
||||
|
||||
public bool IsPlayer { get; private set; }
|
||||
public bool IsMobile { get; protected set; }
|
||||
public bool IsLanded { get; protected set; }
|
||||
public bool IsOrbiting { get; protected set; }
|
||||
public long Diameter { get; protected set; }
|
||||
|
||||
public AI AI { get; protected set; }
|
||||
|
||||
public List<Component> Components { get; protected set; }
|
||||
public List<GameObject> Cargo { get; protected set; }
|
||||
public List<Life> Crew { get; protected set; }
|
||||
|
||||
public Structure(string name, CoordinateVector position, GameObject parent, long diameter, bool isPlayer)
|
||||
: base(name, position, new CoordinateVector(0, 0), parent)
|
||||
{
|
||||
this.IsPlayer = isPlayer;
|
||||
this.IsMobile = false;
|
||||
this.IsLanded = false;
|
||||
this.IsOrbiting = false;
|
||||
this.Diameter = diameter;
|
||||
|
||||
this.AI = isPlayer ? null : new AI(this);
|
||||
|
||||
this.Components = new List<Component>();
|
||||
this.Cargo = new List<GameObject>();
|
||||
this.Crew = new List<Life>();
|
||||
}
|
||||
|
||||
public override void Simulate()
|
||||
{
|
||||
base.Simulate();
|
||||
|
||||
foreach (GameObject component in this.Components)
|
||||
{
|
||||
component.Simulate();
|
||||
}
|
||||
|
||||
foreach (GameObject cargoItem in this.Cargo)
|
||||
{
|
||||
cargoItem.Simulate();
|
||||
}
|
||||
|
||||
foreach (GameObject crewMember in this.Crew)
|
||||
{
|
||||
crewMember.Simulate();
|
||||
}
|
||||
|
||||
ExecuteOrder();
|
||||
}
|
||||
|
||||
public bool SetNewPlayerOrder(Order newOrder)
|
||||
{
|
||||
if (!this.IsPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.CurrentOrder = newOrder;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool ExecuteOrder()
|
||||
{
|
||||
bool finished = false;
|
||||
|
||||
if (this.CurrentOrder == null)
|
||||
{
|
||||
if (!this.IsPlayer && this.AI != null)
|
||||
{
|
||||
this.CurrentOrder = this.AI.Think();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.CurrentOrder.Category == Order.OrderCategory.TICK)
|
||||
{
|
||||
finished = ExecuteTickOrder(this.CurrentOrder as TickOrder);
|
||||
}
|
||||
|
||||
if (this.CurrentOrder.Category == Order.OrderCategory.DESTINATION)
|
||||
{
|
||||
finished = ExecuteDestinationOrder(this.CurrentOrder as DestinationOrder);
|
||||
}
|
||||
|
||||
if (finished)
|
||||
{
|
||||
this.CurrentOrder = null;
|
||||
}
|
||||
|
||||
return finished;
|
||||
}
|
||||
|
||||
protected bool ExecuteTickOrder(TickOrder tickOrder)
|
||||
{
|
||||
bool finished = false;
|
||||
|
||||
switch (tickOrder.Type)
|
||||
{
|
||||
case Order.OrderType.IDLE:
|
||||
|
||||
break;
|
||||
case Order.OrderType.ORBIT:
|
||||
|
||||
break;
|
||||
case Order.OrderType.LAND:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return finished;
|
||||
}
|
||||
|
||||
protected bool ExecuteDestinationOrder(DestinationOrder destinationOrder)
|
||||
{
|
||||
bool finished = false;
|
||||
|
||||
switch (destinationOrder.Type)
|
||||
{
|
||||
case Order.OrderType.MOVE_THRUSTERS:
|
||||
finished = this.TravelTo(destinationOrder.Destination, false);
|
||||
break;
|
||||
case Order.OrderType.MOVE_WARP:
|
||||
finished = this.TravelTo(destinationOrder.Destination, true);
|
||||
break;
|
||||
}
|
||||
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue