using System.Collections.Generic;
namespace Ashfall.Core
{
public static class WorldFactory
{
public static WorldState Create()
{
var w = new WorldState();
w.spaces.Add(Space("world", "陨落平原 · 测试区", SpaceKind.Exterior, "", new V2(), 1, new V2(256, 256)));
w.spaces.Add(Space("lab", "遗落研究站", SpaceKind.Building, "lab", new V2(-20, 16), 2, new V2(16, 14)));
w.spaces.Add(Space("base", "前哨基地", SpaceKind.Building, "base", new V2(-20, -15), 1, new V2(18, 18)));
AddDoor(w, "lab", new V2(-20, 8), new V2(0, -5.5f));
AddDoor(w, "base", new V2(-20, -25), new V2(0, -7));
AddStairs(w, "lab", 0, new V2(6, -2), 1, new V2(6, 3));
AddFacility(w, "lab.power", "备用发电机", FacilityKind.Generator, "lab", 0, new V2(-5, 3), false);
AddFacility(w, "lab.research", "样本解析终端", FacilityKind.Research, "lab", 1, new V2(-4, 3), false);
AddFacility(w, "lab.workshop", "精密制造台", FacilityKind.Workshop, "lab", 0, new V2(0, 3), false);
AddFacility(w, "base.storage", "共享仓库", FacilityKind.Storage, "base", 0, new V2(-5, -3));
AddFacility(w, "base.workshop", "野战工作台", FacilityKind.Workshop, "base", 0, new V2(-5, 3));
AddFacility(w, "base.medical", "医疗复苏舱", FacilityKind.Medical, "base", 0, new V2(4, 3));
AddFacility(w, "base.molt", "蠕虫蜕变茧", FacilityKind.Medical, "base", 0, new V2(4, -3), true, Family.Biological);
for (int x = -8; x <= 8; x++) for (int y = -8; y <= 8; y++)
w.pieces.Add(new BuildPiece { id = w.NewId("tile"), ownerId = "base", kind = PieceKind.Floor,
location = At("base", 0, new V2(x, y)) });
w.Space("base").floors[0].playerBuilt = true;
AddTransport(w, "crawler", "拓荒履带车 · 双层实验型", Family.Mechanical, new V2(7, 0), false, 2);
AddTransport(w, "beast", "囊背驮兽 · 双层实验型", Family.Biological, new V2(28, -4), false, 2);
AddTransport(w, "ark", "天穹方舟 · 缩尺技术样机", Family.Mechanical, new V2(15, 38), true, 3);
w.warehouse.Add("metal", 180); w.warehouse.Add("ore", 100); w.warehouse.Add("biomass", 120);
w.warehouse.Add("sample", 4); w.warehouse.Add("alloy", 20); w.warehouse.Add("chitin", 20);
for (int i = 0; i < 18; i++)
{
float x = -9 + i % 6 * 5.5f, y = -34 - i / 6 * 5;
w.resources.Add(new ResourceState { id = w.NewId("resource"), itemId = i % 3 == 0 ? "biomass" : "ore",
amount = 12, location = At("world", 0, new V2(x, y)) });
}
for (int i = 0; i < 14; i++)
w.enemies.Add(new EnemyState { id = w.NewId("enemy"), location = At("world", 0, new V2(43 + i % 4 * 4, -28 + i / 4 * 4)) });
w.enemies.Add(new EnemyState { id = "boss.plain", boss = true, health = 2400, maxHealth = 2400,
location = At("world", 0, new V2(66, -17)) });
w.Space("world").floors[0].walls.Add(new WallState { id = "rock.ridge", bounds = new Box2(new V2(37, 10), new V2(5, 16)), height = 8 });
return w;
}
public static Location At(string space, int floor, V2 position) => new Location { spaceId = space, floor = floor, position = position };
public static SpaceState Space(string id, string name, SpaceKind kind, string owner, V2 anchor, int floors, V2 size)
{
var s = new SpaceState { id = id, name = name, kind = kind, ownerId = owner, worldAnchor = anchor };
for (int i = 0; i < floors; i++) s.floors.Add(new FloorState { index = i, name = (i + 1) + "F", bounds = new Box2(new V2(), size) });
return s;
}
public static void AddDoor(WorldState w, string space, V2 exterior, V2 interior)
{
w.portals.Add(new PortalState { id = space + ".enter", name = "进入" + w.Space(space).name,
from = At("world", 0, exterior), to = At(space, 0, interior) });
w.portals.Add(new PortalState { id = space + ".exit", name = "返回室外",
from = At(space, 0, interior + new V2(0, -.8f)), to = At("world", 0, exterior + new V2(0, -1.5f)) });
}
public static void AddStairs(WorldState w, string space, int from, V2 lower, int to, V2 upper)
{
w.portals.Add(new PortalState { id = w.NewId("stairs"), name = "上楼", stairs = true, seconds = .85f,
from = At(space, from, lower), to = At(space, to, upper) });
w.portals.Add(new PortalState { id = w.NewId("stairs"), name = "下楼", stairs = true, seconds = .85f,
from = At(space, to, upper + new V2(0, .9f)), to = At(space, from, lower + new V2(0, -1.3f)) });
}
public static void AddFacility(WorldState w, string id, string name, FacilityKind kind, string space, int floor, V2 position, bool powered = true, Family family = Family.Mechanical)
{
w.facilities.Add(new FacilityState { id = id, name = name, kind = kind, ownerId = w.Space(space)?.ownerId,
location = At(space, floor, position), powered = powered, family = family });
}
private static void AddTransport(WorldState w, string id, string name, Family family, V2 position, bool flying, int floors)
{
var v = new VehicleState { id = id, name = name, definitionId = flying ? "vehicle.human.7" : family == Family.Mechanical ? "vehicle.human.1" : "vehicle.brood.1",
spaceId = id + ".inside", family = family, position = position, flying = flying,
length = flying ? 26 : 14, width = flying ? 16 : 8, maxSpeed = flying ? 14 : 9 };
var s = Space(v.spaceId, name, SpaceKind.Vehicle, id, position, floors, new V2(16, 14));
s.family = family; w.spaces.Add(s); w.vehicles.Add(v);
AddDoor(w, s.id, v.DoorPosition, new V2(0, -5.3f));
foreach (var portal in w.portals) if (portal.id.StartsWith(s.id + ".")) portal.ownerId = v.id;
for (int f = 0; f < floors - 1; f++) AddStairs(w, s.id, f, new V2(6, -2), f + 1, new V2(6, 3));
v.stations.Add(new StationState { id = id + ".driver", name = "驾驶台", role = StationRole.Driver, location = At(s.id, floors - 1, new V2(-1.5f, 4)) });
v.stations.Add(new StationState { id = id + ".gunner", name = "炮手台", role = StationRole.Gunner, weaponGroup = 0, location = At(s.id, floors - 1, new V2(2.2f, 4)) });
string prefix = family == Family.Mechanical ? "mechanical" : "biological";
v.hardpoints.Add(new HardpointState { id = "primary", size = 2, group = 0, moduleId = prefix + ".light" });
v.hardpoints.Add(new HardpointState { id = "secondary", size = 1, group = 1, moduleId = prefix + ".light", arc = 160 });
v.cargo.Add("ammo", 600); v.cargo.Add("shell", 40); v.cargo.Add("biomass", 300); v.cargo.Add("metal", 100);
v.cargo.Add("module." + prefix + ".heavy", 1);
v.cargo.Add("module." + prefix + ".light", 1);
AddFacility(w, id + ".cargo", "货仓", FacilityKind.Storage, s.id, 0, new V2(-4, -3), true, family);
AddFacility(w, id + ".workshop", "维修制造台", FacilityKind.Workshop, s.id, 0, new V2(-4, 3), true, family);
AddFacility(w, id + ".medical", "补给与恢复", FacilityKind.Medical, s.id, floors - 1, new V2(-5, 0), true, family);
if (family == Family.Biological)
AddFacility(w, id + ".research", "进化解析池", FacilityKind.Research, s.id, floors - 1, new V2(0, -2), true, family);
}
}
}
using System.Collections.Generic;
namespace Ashfall.Core
{
public static class WorldFactory
{
public static WorldState Create()
{
var w = new WorldState();
w.spaces.Add(Space("world", "陨落平原 · 测试区", SpaceKind.Exterior, "", new V2(), 1, new V2(256, 256)));
w.spaces.Add(Space("lab", "遗落研究站", SpaceKind.Building, "lab", new V2(-20, 16), 2, new V2(16, 14)));
w.spaces.Add(Space("base", "前哨基地", SpaceKind.Building, "base", new V2(-20, -15), 1, new V2(18, 18)));
AddDoor(w, "lab", new V2(-20, 8), new V2(0, -5.5f));
AddDoor(w, "base", new V2(-20, -25), new V2(0, -7));
AddStairs(w, "lab", 0, new V2(6, -2), 1, new V2(6, 3));
AddFacility(w, "lab.power", "备用发电机", FacilityKind.Generator, "lab", 0, new V2(-5, 3), false);
AddFacility(w, "lab.research", "样本解析终端", FacilityKind.Research, "lab", 1, new V2(-4, 3), false);
AddFacility(w, "lab.workshop", "精密制造台", FacilityKind.Workshop, "lab", 0, new V2(0, 3), false);
AddFacility(w, "base.storage", "共享仓库", FacilityKind.Storage, "base", 0, new V2(-5, -3));
AddFacility(w, "base.workshop", "野战工作台", FacilityKind.Workshop, "base", 0, new V2(-5, 3));
AddFacility(w, "base.medical", "医疗复苏舱", FacilityKind.Medical, "base", 0, new V2(4, 3));
AddFacility(w, "base.molt", "蠕虫蜕变茧", FacilityKind.Medical, "base", 0, new V2(4, -3), true, Family.Biological);
for (int x = -8; x <= 8; x++) for (int y = -8; y <= 8; y++)
w.pieces.Add(new BuildPiece { id = w.NewId("tile"), ownerId = "base", kind = PieceKind.Floor,
location = At("base", 0, new V2(x, y)) });
w.Space("base").floors[0].playerBuilt = true;
AddTransport(w, "crawler", "拓荒履带车 · 双层实验型", Family.Mechanical, new V2(7, 0), false, 2);
AddTransport(w, "beast", "囊背驮兽 · 双层实验型", Family.Biological, new V2(28, -4), false, 2);
AddTransport(w, "ark", "天穹方舟 · 缩尺技术样机", Family.Mechanical, new V2(15, 38), true, 3);
w.warehouse.Add("metal", 180); w.warehouse.Add("ore", 100); w.warehouse.Add("biomass", 120);
w.warehouse.Add("sample", 4); w.warehouse.Add("alloy", 20); w.warehouse.Add("chitin", 20);
for (int i = 0; i < 18; i++)
{
float x = -9 + i % 6 * 5.5f, y = -34 - i / 6 * 5;
w.resources.Add(new ResourceState { id = w.NewId("resource"), itemId = i % 3 == 0 ? "biomass" : "ore",
amount = 12, location = At("world", 0, new V2(x, y)) });
}
for (int i = 0; i < 14; i++)
w.enemies.Add(new EnemyState { id = w.NewId("enemy"), location = At("world", 0, new V2(43 + i % 4 * 4, -28 + i / 4 * 4)) });
w.enemies.Add(new EnemyState { id = "boss.plain", boss = true, health = 2400, maxHealth = 2400,
location = At("world", 0, new V2(66, -17)) });
w.Space("world").floors[0].walls.Add(new WallState { id = "rock.ridge", bounds = new Box2(new V2(37, 10), new V2(5, 16)), height = 8 });
return w;
}
public static Location At(string space, int floor, V2 position) => new Location { spaceId = space, floor = floor, position = position };
public static SpaceState Space(string id, string name, SpaceKind kind, string owner, V2 anchor, int floors, V2 size)
{
var s = new SpaceState { id = id, name = name, kind = kind, ownerId = owner, worldAnchor = anchor };
for (int i = 0; i < floors; i++) s.floors.Add(new FloorState { index = i, name = (i + 1) + "F", bounds = new Box2(new V2(), size) });
return s;
}
public static void AddDoor(WorldState w, string space, V2 exterior, V2 interior)
{
w.portals.Add(new PortalState { id = space + ".enter", name = "进入" + w.Space(space).name,
from = At("world", 0, exterior), to = At(space, 0, interior) });
w.portals.Add(new PortalState { id = space + ".exit", name = "返回室外",
from = At(space, 0, interior + new V2(0, -.8f)), to = At("world", 0, exterior + new V2(0, -1.5f)) });
}
public static void AddStairs(WorldState w, string space, int from, V2 lower, int to, V2 upper)
{
w.portals.Add(new PortalState { id = w.NewId("stairs"), name = "上楼", stairs = true, seconds = .85f,
from = At(space, from, lower), to = At(space, to, upper) });
w.portals.Add(new PortalState { id = w.NewId("stairs"), name = "下楼", stairs = true, seconds = .85f,
from = At(space, to, upper + new V2(0, .9f)), to = At(space, from, lower + new V2(0, -1.3f)) });
}
public static void AddFacility(WorldState w, string id, string name, FacilityKind kind, string space, int floor, V2 position, bool powered = true, Family family = Family.Mechanical)
{
w.facilities.Add(new FacilityState { id = id, name = name, kind = kind, ownerId = w.Space(space)?.ownerId,
location = At(space, floor, position), powered = powered, family = family });
}
private static void AddTransport(WorldState w, string id, string name, Family family, V2 position, bool flying, int floors)
{
var v = new VehicleState { id = id, name = name, definitionId = flying ? "vehicle.human.7" : family == Family.Mechanical ? "vehicle.human.1" : "vehicle.brood.1",
spaceId = id + ".inside", family = family, position = position, flying = flying,
length = flying ? 26 : 14, width = flying ? 16 : 8, maxSpeed = flying ? 14 : 9 };
var s = Space(v.spaceId, name, SpaceKind.Vehicle, id, position, floors, new V2(16, 14));
s.family = family; w.spaces.Add(s); w.vehicles.Add(v);
AddDoor(w, s.id, v.DoorPosition, new V2(0, -5.3f));
foreach (var portal in w.portals) if (portal.id.StartsWith(s.id + ".")) portal.ownerId = v.id;
for (int f = 0; f < floors - 1; f++) AddStairs(w, s.id, f, new V2(6, -2), f + 1, new V2(6, 3));
v.stations.Add(new StationState { id = id + ".driver", name = "驾驶台", role = StationRole.Driver, location = At(s.id, floors - 1, new V2(-1.5f, 4)) });
v.stations.Add(new StationState { id = id + ".gunner", name = "炮手台", role = StationRole.Gunner, weaponGroup = 0, location = At(s.id, floors - 1, new V2(2.2f, 4)) });
string prefix = family == Family.Mechanical ? "mechanical" : "biological";
v.hardpoints.Add(new HardpointState { id = "primary", size = 2, group = 0, moduleId = prefix + ".light" });
v.hardpoints.Add(new HardpointState { id = "secondary", size = 1, group = 1, moduleId = prefix + ".light", arc = 160 });
v.cargo.Add("ammo", 600); v.cargo.Add("shell", 40); v.cargo.Add("biomass", 300); v.cargo.Add("metal", 100);
v.cargo.Add("module." + prefix + ".heavy", 1);
v.cargo.Add("module." + prefix + ".light", 1);
AddFacility(w, id + ".cargo", "货仓", FacilityKind.Storage, s.id, 0, new V2(-4, -3), true, family);
AddFacility(w, id + ".workshop", "维修制造台", FacilityKind.Workshop, s.id, 0, new V2(-4, 3), true, family);
AddFacility(w, id + ".medical", "补给与恢复", FacilityKind.Medical, s.id, floors - 1, new V2(-5, 0), true, family);
if (family == Family.Biological)
AddFacility(w, id + ".research", "进化解析池", FacilityKind.Research, s.id, floors - 1, new V2(0, -2), true, family);
}
}
}