Crate dropping planes

This commit is contained in:
Matthew Bowra-Dean
2010-03-19 15:11:47 +13:00
parent 1fb56dd13d
commit 92442d5392
7 changed files with 203 additions and 2 deletions

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using OpenRA.Mods.RA;
using OpenRA.Traits;
namespace OpenRA.Mods.RA_NG
{
public class CrateDropInfo : ITraitInfo
{
public readonly int Minimum = 1; // Minumum number of crates
public readonly int Maximum = 255; // Maximum number of crates
public readonly int SpawnInterval = 180; // Average time (seconds) between crate spawn
public readonly float WaterChance = .2f; // Chance of generating a water crate instead of a land crate
public object Create(Actor self)
{
return new CrateDrop();
}
}
public class CrateDrop : ITick
{
List<Actor> crates = new List<Actor>();
int ticks = 0;
public void Tick(Actor self)
{
if (--ticks <= 0)
{
var info = self.Info.Traits.Get<CrateDropInfo>();
ticks = info.SpawnInterval * 25; // todo: randomize
crates.RemoveAll(x => !x.IsInWorld);
var toSpawn = Math.Max(0, info.Minimum - crates.Count)
+ (crates.Count < info.Maximum ? 1 : 0);
for (var n = 0; n < toSpawn; n++)
SpawnCrate(self, info);
}
}
void SpawnCrate(Actor self, CrateDropInfo info)
{
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
var umt = inWater ? UnitMovementType.Float : UnitMovementType.Wheel;
int count = 0, threshold = 100;
for (; ; )
{
var p = new int2(self.World.SharedRandom.Next(0, 127), self.World.SharedRandom.Next(0, 127));
if (self.World.IsCellBuildable(p, umt))
{
self.World.AddFrameEndTask(w =>
{
var crate = new Actor(w, "crate", new int2(0, 0), self.Owner);
crates.Add(crate);
var plane = w.CreateActor("BADR", w.ChooseRandomEdgeCell(), self.Owner);
plane.traits.Get<ParaDrop>().SetLZ(p);
plane.traits.Get<Cargo>().Load(plane, crate);
});
break;
}
if (count++ > threshold)
break;
}
}
}
}

View File

@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenRA.Mods.RA_NG</RootNamespace>
<AssemblyName>OpenRA.Mods.RA_NG</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CrateDrop.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
<Name>OpenRA.FileFormats</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">
<Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project>
<Name>OpenRA.Game</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Mods.RA\OpenRA.Mods.RA.csproj">
<Project>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</Project>
<Name>OpenRA.Mods.RA</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)mods/ra-ng/"
copy "$(TargetPath)" "$(SolutionDir)mods/ra-ng/"</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenRA.Mods.RA-NG")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("OpenRA.Mods.RA-NG")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3c94e0bf-6350-4703-a770-59cbc260d0a1")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -25,13 +25,13 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA
{
class ParaDropInfo : ITraitInfo
public class ParaDropInfo : ITraitInfo
{
public readonly int LZRange = 4;
public object Create(Actor self) { return new ParaDrop(); }
}
class ParaDrop : ITick
public class ParaDrop : ITick
{
readonly List<int2> droppedAt = new List<int2>();
int2 lz;

View File

@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.Cnc", "OpenRA.M
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Gl", "OpenRA.Gl\OpenRA.Gl.csproj", "{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.Mods.RA_NG", "OpenRA.Mods.RA-NG\OpenRA.Mods.RA_NG.csproj", "{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -78,6 +80,14 @@ Global
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Release|Any CPU.Build.0 = Release|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{67CF1A10-C5F6-48FA-B1A7-FE83BE4CE2CC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Release|Any CPU.Build.0 = Release|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6CA925E5-4A47-46AC-9DE3-FA341F7C94A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -5,8 +5,11 @@ Packages:
LegacyRules:
Rules:
mods/ra-ng/rules.yaml
mods/ra-ng/defense-queue.yaml
Sequences:
Assemblies:
mods/ra-ng/OpenRA.Mods.RA_NG.dll:
mods/ra/OpenRA.Mods.RA.dll:

7
mods/ra-ng/rules.yaml Normal file
View File

@@ -0,0 +1,7 @@
World:
-CrateSpawner:
CrateDrop:
Minimum: 1
Maximum: 3
SpawnInterval: 20
WaterChance: .2