public SRgb GetUnitGroupMinimapColour(clsUnitGroup ColourUnitGroup) { if (ColourUnitGroup.WZ_StartPos < 0) { return(new SRgb(1.0F, 1.0F, 1.0F)); } return(App.PlayerColour[ColourUnitGroup.WZ_StartPos].MinimapColour); }
public void MakeDefaultUnitGroups() { var A = 0; var NewGroup = default(clsUnitGroup); UnitGroups.Clear(); for (A = 0; A <= Constants.PlayerCountMax - 1; A++) { NewGroup = new clsUnitGroup(); NewGroup.WZ_StartPos = A; NewGroup.MapLink.Connect(UnitGroups); } ScavengerUnitGroup = new clsUnitGroup(); ScavengerUnitGroup.MapLink.Connect(UnitGroups); ScavengerUnitGroup.WZ_StartPos = -1; }
private Result ValidateMap_UnitPositions() { var Result = new Result("Validate unit positions", false); logger.Info("Validate unit positions"); //check unit positions var TileHasUnit = new bool[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y]; var tileStructureTypeBase = new StructureTypeBase[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y]; var tileFeatureTypeBase = new FeatureTypeBase[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y]; var TileObjectGroup = new clsUnitGroup[Map.Terrain.TileSize.X, Map.Terrain.TileSize.Y]; var StartPos = new XYInt(); var FinishPos = new XYInt(); var CentrePos = new XYInt(); StructureType StructureTypeType; StructureTypeBase structureTypeBase; var Footprint = new XYInt(); var UnitIsStructureModule = new bool[Map.Units.Count]; bool IsValid; foreach (var unit in Map.Units) { if (unit.TypeBase.Type == UnitType.PlayerStructure) { structureTypeBase = (StructureTypeBase)unit.TypeBase; StructureTypeType = structureTypeBase.StructureType; UnitIsStructureModule[unit.MapLink.ArrayPosition] = structureTypeBase.IsModule() | StructureTypeType == StructureType.ResourceExtractor; } } //check and store non-module units first. modules need to check for the underlying unit. foreach (var unit in Map.Units) { if (!UnitIsStructureModule[unit.MapLink.ArrayPosition]) { Footprint = unit.TypeBase.GetGetFootprintSelected(unit.Rotation); Map.GetFootprintTileRange(unit.Pos.Horizontal, Footprint, ref StartPos, ref FinishPos); if (StartPos.X < 0 | FinishPos.X >= Map.Terrain.TileSize.X | StartPos.Y < 0 | FinishPos.Y >= Map.Terrain.TileSize.Y) { var resultItem = modResults.CreateResultProblemGotoForObject(unit); resultItem.Text = string.Format("Unit off map at position {0}.", unit.GetPosText()); Result.ItemAdd(resultItem); } else { for (var y = StartPos.Y; y <= FinishPos.Y; y++) { for (var x = StartPos.X; x <= FinishPos.X; x++) { if (TileHasUnit[x, y]) { var resultItem = modResults.CreateResultProblemGotoForObject(unit); logger.Info("Bad overlap of {0} on tile {1}, {2}.", unit.TypeBase.GetDisplayTextName(), x, y); resultItem.Text = string.Format("Bad unit overlap of {0} on tile {1}, {2}.", unit.TypeBase.GetDisplayTextName(), x, y); Result.ItemAdd(resultItem); } else { logger.Debug("{0} on X:{1}, Y:{2} tile.", unit.TypeBase.GetDisplayTextName(), x, y); TileHasUnit[x, y] = true; if (unit.TypeBase.Type == UnitType.PlayerStructure) { tileStructureTypeBase[x, y] = (StructureTypeBase)unit.TypeBase; } else if (unit.TypeBase.Type == UnitType.Feature) { tileFeatureTypeBase[x, y] = (FeatureTypeBase)unit.TypeBase; } TileObjectGroup[x, y] = unit.UnitGroup; } } } } } } //check modules and extractors foreach (var unit in Map.Units) { if (UnitIsStructureModule[unit.MapLink.ArrayPosition]) { StructureTypeType = ((StructureTypeBase)unit.TypeBase).StructureType; CentrePos.X = (unit.Pos.Horizontal.X / Constants.TerrainGridSpacing); CentrePos.Y = unit.Pos.Horizontal.Y / Constants.TerrainGridSpacing; if (CentrePos.X < 0 | CentrePos.X >= Map.Terrain.TileSize.X | CentrePos.Y < 0 | CentrePos.Y >= Map.Terrain.TileSize.Y) { var resultItem = modResults.CreateResultProblemGotoForObject(unit); resultItem.Text = "Module off map at position " + unit.GetPosText() + "."; Result.ItemAdd(resultItem); } else { if (tileStructureTypeBase[CentrePos.X, CentrePos.Y] != null) { if (TileObjectGroup[CentrePos.X, CentrePos.Y] == unit.UnitGroup) { if (StructureTypeType == StructureType.FactoryModule) { if (tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureType.Factory | tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureType.VTOLFactory) { IsValid = true; } else { IsValid = false; } } else if (StructureTypeType == StructureType.PowerModule) { if (tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureType.PowerGenerator) { IsValid = true; } else { IsValid = false; } } else if (StructureTypeType == StructureType.ResearchModule) { if (tileStructureTypeBase[CentrePos.X, CentrePos.Y].StructureType == StructureType.Research) { IsValid = true; } else { IsValid = false; } } else { IsValid = false; } } else { IsValid = false; } } else if (tileFeatureTypeBase[CentrePos.X, CentrePos.Y] != null) { if (StructureTypeType == StructureType.ResourceExtractor) { if (tileFeatureTypeBase[CentrePos.X, CentrePos.Y].FeatureType == FeatureType.OilResource) { IsValid = true; } else { IsValid = false; } } else { IsValid = false; } } else if (StructureTypeType == StructureType.ResourceExtractor) { IsValid = true; } else { IsValid = false; } if (!IsValid) { var resultItem = modResults.CreateResultProblemGotoForObject(unit); resultItem.Text = "Bad module on tile " + Convert.ToString(CentrePos.X) + ", " + Convert.ToString(CentrePos.Y) + "."; Result.ItemAdd(resultItem); } } } } return(Result); }