森林を斜面にも設置できるようにしました。
方向性が間違っていないと判断されましたらCVSへのコミット許可をお願いします。
cvs diff AssemblyInfo.cs ForestBuilder.cs ForestVoxel.cs (ディレクトリ C:\Project\FreeTrain\FreeTrain\plugins\org.kohsuke.freetrain.land.forest\src 内)
Index: ForestBuilder.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/plugins/org.kohsuke.freetrain.land.forest/src/ForestBuilder.cs,v
retrieving revision 1.5
diff -u -r1.5 ForestBuilder.cs
--- ForestBuilder.cs 26 Jun 2003 15:02:34 -0000 1.5
+++ ForestBuilder.cs 29 Jun 2003 05:53:20 -0000
@@ -9,6 +9,7 @@
using freetrain.controllers;
using freetrain.framework.graphics;
using freetrain.framework.plugin;
+using freetrain.world.terrain;
using freetrain.views;
namespace freetrain.world.land.forest
@@ -75,11 +76,21 @@
for( int y=y1; y<=y2; y++ ) {
Location loc = new Location(x,y,z);
- if( ForestVoxel.canBeBuilt(loc) ) {
+ if( ForestVoxel.canBeBuilt(loc) )
+ {
byte[] patterns = createRandomTrees();
- if( patterns.Length!=0 )
- new ForestVoxel( loc, this, patterns );
- }
+ if( patterns.Length!=0 )
+ {
+ if( World.world[loc] is MountainVoxel )
+ {
+ MountainVoxel v = (MountainVoxel)World.world[loc];
+ World.world.remove(v);
+ new PlantedMtVoxel( this, patterns, loc, v );
+ }
+ else
+ new ForestVoxel( loc, this, patterns );
+ }
+ }
}
}
}
Index: ForestVoxel.cs
===================================================================
RCS file: /cvsroot/freetrain/FreeTrain/plugins/org.kohsuke.freetrain.land.forest/src/ForestVoxel.cs,v
retrieving revision 1.3
diff -u -r1.3 ForestVoxel.cs
--- ForestVoxel.cs 26 Jun 2003 15:02:34 -0000 1.3
+++ ForestVoxel.cs 29 Jun 2003 05:53:20 -0000
@@ -4,6 +4,7 @@
using freetrain.world.land;
using freetrain.world.rail;
using freetrain.world.structs;
+using freetrain.world.terrain;
namespace freetrain.world.land.forest
{
@@ -38,6 +39,19 @@
for( int i=0; i<patterns.Length; i+=3 )
contrib.sprites[ patterns[i+2] ].draw( surface.surface,
new Point( pt.X+patterns[i+0], pt.Y+patterns[i+1] ) );
+ }
+
+ public static new bool canBeBuilt(Location loc)
+ {
+ if( World.world.getGroundLevel(loc) != loc.z )
+ {
+ return false;
+ }
+ else if(!World.world.isReusable(loc))
+ {
+ return (World.world[loc] is MountainVoxel );
+ }
+ else return true;
}
}
}
---------------PlantedMtVoxel.cs---------------
namespace freetrain.world.land.forest
{
/// <summary>
/// PlantedMtVoxcel の概要の説明です。
/// </summary>
[Serializable]
public class PlantedMtVoxel : MountainVoxel
{
private readonly ForestBuilder contrib;
private readonly byte[] patterns;
public PlantedMtVoxel( ForestBuilder contrib, byte[] patterns, Location loc, MountainVoxel mountain ) :
base ( loc,
(byte)mountain.getHeight(Direction.NORTHEAST),
(byte)mountain.getHeight(Direction.SOUTHEAST),
(byte)mountain.getHeight(Direction.SOUTHWEST),
(byte)mountain.getHeight(Direction.NORTHWEST) )
{
this.contrib = contrib;
this.patterns = patterns;
}
public override void draw( DrawContext display, Point pt, int heightCutDiff )
{
base.draw( display, pt, heightCutDiff );
int h = getHeight(Direction.NORTHEAST)-getHeight(Direction.SOUTHWEST);
//int w = getHeight(Direction.NORTHWEST)-getHeight(Direction.SOUTHEAST);
if( h > 0)
{
for( int i=0; i<patterns.Length; i+=3 )
contrib.sprites[ patterns[i+2] ].draw( display.surface,
new Point( pt.X+patterns[i+0], pt.Y+patterns[i+1]*(h+4)/4-8 ) );
}
else
{
for( int i=0; i<patterns.Length; i+=3 )
contrib.sprites[ patterns[i+2] ].draw( display.surface,
new Point( pt.X+patterns[i+0], pt.Y+patterns[i+1]*(h+4)/4+2 ) );
}
}
}
}
---------------BulldozerEx.cs---------------
namespace freetrain.world.land.forest
{
/// <summary>
/// Removes any land voxel in the region.
/// </summary>
public class BulldozerEx : Bulldozer
{
public BulldozerEx( XmlElement e ) : base(e) {
}
/// <summary>
/// Gets the land that should be used to fill (x,y) within [x1,y1]-[x2,y2] (inclusive).
/// </summary>
public override void create( int x1, int y1, int x2, int y2, int z ) {
bulldozeEx(new Location(x1,y1,z),new Location(x2,y2,z));
}
public static void bulldozeEx( Location loc1, Location loc2 ) {
int z = loc1.z;
for( int x=loc1.x; x<=loc2.x; x++ ) {
for( int y=loc1.y; y<=loc2.y; y++ ) {
if( World.world.isReusable(x,y,z) && World.world[x,y,z]!=null )
World.world.remove(x,y,z);
else if(World.world[x,y,z] is PlantedMtVoxel)
{
PlantedMtVoxel v = (PlantedMtVoxel)World.world[x,y,z];
World.world.remove(v);
new MountainVoxel(new Location(x,y,z),
(byte)v.getHeight(Direction.NORTHEAST),
(byte)v.getHeight(Direction.SOUTHEAST),
(byte)v.getHeight(Direction.SOUTHWEST),
(byte)v.getHeight(Direction.NORTHWEST));
}
}
}
}
}
}
_______________________________________________
FreeTrain-general mailing list
FreeTrain-general@lists.sourceforge.jp
http://lists.sourceforge.jp/mailman/listinfo/freetrain-general