Move the objective flag stuff to MissionUtils

This commit is contained in:
Scott_NZ
2012-09-21 00:02:09 +12:00
parent d1400ab4fa
commit 8dd7bfdb67
2 changed files with 32 additions and 15 deletions

View File

@@ -36,39 +36,35 @@ namespace OpenRA.Mods.RA.Missions
IEnumerable<string> GetObjectiveText()
{
var objectives = new List<string>();
if (HasObjective(Objectives.FindEinstein))
if (MissionUtils.HasFlag(currentObjectives, Objectives.FindEinstein))
{
objectives.Add("Find Einstein. Tanya and Einstein must survive.");
}
if (HasObjective(Objectives.WaitForHelicopter))
if (MissionUtils.HasFlag(currentObjectives, Objectives.WaitForHelicopter))
{
objectives.Add("Wait for the helicopter and extract Einstein. Tanya and Einstein must survive.");
}
return objectives;
}
bool HasObjective(Objectives o)
void DisplayObjective(string objective)
{
return (currentObjectives & o) == o;
Game.AddChatLine(Color.LimeGreen, "Objective", objective);
Sound.Play("bleep6.aud");
}
void AddObjective(Objectives o)
void DisplayHint(string objective)
{
currentObjectives |= o;
}
void RemoveObjective(Objectives o)
{
currentObjectives &= ~o;
Game.AddChatLine(Color.Yellow, "Hint", objective);
Sound.Play("bleep6.aud");
}
void DisplayObjectives()
{
foreach (var objective in GetObjectiveText())
{
Game.AddChatLine(Color.LimeGreen, "Objective", objective);
DisplayObjective(objective);
}
Sound.Play("bleep6.aud");
}
Objectives currentObjectives = Objectives.FindEinstein;
@@ -149,7 +145,7 @@ namespace OpenRA.Mods.RA.Missions
{
Sound.Play(Taunts[world.SharedRandom.Next(Taunts.Length)]);
}
if (HasObjective(Objectives.FindEinstein))
if (MissionUtils.HasFlag(currentObjectives, Objectives.FindEinstein))
{
if (AlliesControlLab())
{
@@ -166,7 +162,7 @@ namespace OpenRA.Mods.RA.Missions
MissionFailed("Einstein was killed.");
}
}
else if (HasObjective(Objectives.WaitForHelicopter))
else if (MissionUtils.HasFlag(currentObjectives, Objectives.WaitForHelicopter))
{
if (world.FrameNumber >= currentAttackWaveFrameNumber + 600)
{

View File

@@ -87,5 +87,26 @@ namespace OpenRA.Mods.RA.Missions
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == category)
.Select(a => a.Trait);
}
public static T AddFlag<T>(T flags, T flag)
{
var fs = Convert.ToInt32(flags);
var f = Convert.ToInt32(flag);
return (T)(object)(fs | f);
}
public static T RemoveFlag<T>(T flags, T flag)
{
var fs = Convert.ToInt32(flags);
var f = Convert.ToInt32(flag);
return (T)(object)(fs & ~f);
}
public static bool HasFlag<T>(T flags, T flag)
{
var fs = Convert.ToInt32(flags);
var f = Convert.ToInt32(flag);
return (fs & f) == f;
}
}
}