First attempt; works, but has regressions in several areas

This commit is contained in:
Paul Chote
2010-05-23 17:27:40 +12:00
parent b8b3ef61aa
commit d9931af5ae
8 changed files with 131 additions and 41 deletions

View File

@@ -42,6 +42,7 @@ namespace OpenRA.FileFormats
public int PlayerCount;
public string Tileset;
public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
public Dictionary<string, ActorReference> Actors = new Dictionary<string, ActorReference>();
public List<SmudgeReference> Smudges = new List<SmudgeReference>();
public Dictionary<string, int2> Waypoints = new Dictionary<string, int2>();
@@ -52,6 +53,7 @@ namespace OpenRA.FileFormats
public Dictionary<string, MiniYaml> Voices = new Dictionary<string, MiniYaml>();
public Dictionary<string, MiniYaml> Music = new Dictionary<string, MiniYaml>();
public Dictionary<string, MiniYaml> Terrain = new Dictionary<string, MiniYaml>();
// Binary map data
public byte TileFormat = 1;
public int2 MapSize;
@@ -94,12 +96,19 @@ namespace OpenRA.FileFormats
Waypoints.Add(wp.Key, new int2(int.Parse(loc[0]), int.Parse(loc[1])));
}
// Players
foreach (var kv in yaml["Players"].Nodes)
{
var player = new PlayerReference(kv.Value);
Players.Add(player.Name, player);
}
// Actors
foreach (var kv in yaml["Actors"].Nodes)
{
string[] vals = kv.Value.Value.Split(' ');
string[] loc = vals[2].Split(',');
var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]), int.Parse(loc[1])), vals[2]);
var a = new ActorReference(vals[0], new int2(int.Parse(loc[0]), int.Parse(loc[1])), vals[1]);
Actors.Add(kv.Key, a);
}

View File

@@ -0,0 +1,34 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA 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.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.FileFormats
{
public class PlayerReference
{
public readonly string Name;
public readonly string Palette;
public readonly string Race;
public PlayerReference(MiniYaml my)
{
FieldLoader.Load(this, my);
}
}
}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -102,6 +102,7 @@
<Compile Include="Primitives\int2.cs" />
<Compile Include="Map\MapStub.cs" />
<Compile Include="Map\SmudgeReference.cs" />
<Compile Include="Map\PlayerReference.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -420,6 +420,9 @@ namespace OpenRA
static Stance ChooseInitialStance(Player p, Player q)
{
// HACK
return Stance.Enemy;
if (p == q) return Stance.Ally;
if (p == world.NeutralPlayer || q == world.NeutralPlayer) return Stance.Neutral;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -26,6 +26,9 @@ namespace OpenRA.Traits
public void Tick( Player owner, Cache<string, List<Actor>> buildings )
{
// HACK
return;
var effectivePrereq = prerequisites.Where( a => a.Traits.Get<BuildableInfo>().Owner.Contains( owner.Country.Race ) );
var nowHasPrerequisites = effectivePrereq.Any() &&
effectivePrereq.All( a => buildings[ a.Name ].Any( b => !b.traits.Get<Building>().Disabled ) );

View File

@@ -91,7 +91,27 @@ namespace OpenRA
Timer.Time("renderer: {0}");
WorldActor = CreateActor("World", new int2(int.MaxValue, int.MaxValue), null);
AddPlayer(NeutralPlayer = new Player(this, null)); // add the neutral player
// Add Map Players
int mapPlayerIndex = -1;
foreach (var kv in Map.Players)
{
var player = new Player(this, null);
Console.WriteLine("Creating Player {0}", kv.Key);
// Lets just pretend that i didn't do this.... Will fix later
player.GetType().GetField("Index").SetValue( player, mapPlayerIndex-- );
player.GetType().GetField("Palette").SetValue( player, kv.Value.Palette );// Todo: set Player.Color as well
player.GetType().GetField("PlayerName").SetValue( player, kv.Value.Name );
player.GetType().GetField("InternalName").SetValue( player, kv.Value.Name );
player.GetType().GetField("Country").SetValue( player, this.GetCountries().FirstOrDefault(c => kv.Value.Race == c.Name) );
AddPlayer(player);
// Todo: Obsolete usage of "World.NeutralPlayer"
if (kv.Value.Name == "Neutral")
NeutralPlayer = player;
}
Timer.Time( "worldActor: {0}" );

View File

@@ -16,6 +16,20 @@ TopLeft: 26,36
BottomRight: 118,93
Players:
PlayerReference@Neutral:
Name: Neutral
Palette: neutral
Race: allies
PlayerReference@GoodGuy:
Name: GoodGuy
Palette: player1
Race: allies
PlayerReference@Greece:
Name: Greece
Palette: player4
Race: soviet
Actors:
Actor0: brik Neutral 32,43
Actor1: brik Neutral 33,43

View File

@@ -18,39 +18,45 @@ TopLeft: 14,19
BottomRight: 60,60
Players:
PlayerReference@Neutral:
Name: Neutral
Palette: neutral
Race: allies
Actors:
Actor0: tc02 25,39 25,39
Actor1: tc01 26,40 26,40
Actor2: tc01 27,39 27,39
Actor3: tc05 30,40 30,40
Actor4: tc04 37,39 37,39
Actor5: tc04 39,37 39,37
Actor6: tc04 41,35 41,35
Actor7: t01 42,33 42,33
Actor8: t01 50,24 50,24
Actor9: t05 49,25 49,25
Actor10: t08 45,29 45,29
Actor11: tc04 43,49 43,49
Actor12: tc01 45,51 45,51
Actor13: tc01 48,52 48,52
Actor14: t03 40,42 40,42
Actor15: t03 35,40 35,40
Actor16: tc04 57,57 57,57
Actor17: tc02 58,19 58,19
Actor18: tc01 21,19 21,19
Actor19: tc02 19,20 19,20
Actor20: t08 16,22 16,22
Actor21: v12 18,22 18,22
Actor22: t05 18,55 18,55
Actor23: tc02 16,54 16,54
Actor24: t16 29,39 29,39
Actor25: t16 21,56 21,56
Actor26: mine 33,45 33,45
Actor27: mine 36,45 36,45
Actor28: mine 44,43 44,43
Actor29: mine 45,40 45,40
Actor30: mine 37,34 37,34
Actor31: mine 35,37 35,37
Actor0: tc02 Neutral 25,39
Actor1: tc01 Neutral 26,40
Actor2: tc01 Neutral 27,39
Actor3: tc05 Neutral 30,40
Actor4: tc04 Neutral 37,39
Actor5: tc04 Neutral 39,37
Actor6: tc04 Neutral 41,35
Actor7: t01 Neutral 42,33
Actor8: t01 Neutral 50,24
Actor9: t05 Neutral 49,25
Actor10: t08 Neutral 45,29
Actor11: tc04 Neutral 43,49
Actor12: tc01 Neutral 45,51
Actor13: tc01 Neutral 48,52
Actor14: t03 Neutral 40,42
Actor15: t03 Neutral 35,40
Actor16: tc04 Neutral 57,57
Actor17: tc02 Neutral 58,19
Actor18: tc01 Neutral 21,19
Actor19: tc02 Neutral 19,20
Actor20: t08 Neutral 16,22
Actor21: v12 Neutral 18,22
Actor22: t05 Neutral 18,55
Actor23: tc02 Neutral 16,54
Actor24: t16 Neutral 29,39
Actor25: t16 Neutral 21,56
Actor26: mine Neutral 33,45
Actor27: mine Neutral 36,45
Actor28: mine Neutral 44,43
Actor29: mine Neutral 45,40
Actor30: mine Neutral 37,34
Actor31: mine Neutral 35,37
Waypoints:
wp0: 29,24