Esempio n. 1
0
        public void Stop()
        {
            m_world.WorldChanged -= HandleChanges;

            m_writer.Close();
            m_writer = null;
            m_world = null;
        }
Esempio n. 2
0
        public FortressGameManager(World world)
        {
            this.World = world;

            // XXX
            var env = this.World.HackGetFirstEnv();
            m_envObserver = new EnvObserver(env);
        }
Esempio n. 3
0
        public void Start(World world, string path)
        {
            m_world = world;

            var stream = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.Read);
            m_writer = new StreamWriter(stream);

            m_world.WorldChanged += HandleChanges;
        }
Esempio n. 4
0
        public static WaterGenerator Create(World world)
        {
            var builder = new ItemObjectBuilder(ItemID.Contraption, MaterialID.Diamond)
            {
                Name = "Water Generator",
                Color = GameColor.Blue,
            };

            var item = new WaterGenerator(builder);
            item.Initialize(world);
            return item;
        }
Esempio n. 5
0
        public IGame CreateGame(string gameDir, GameMode mode, GameMap map)
        {
            MyTraceContext.ThreadTraceContext = new MyTraceContext("Server");

            WorldTickMethod tickMethod;

            switch (mode)
            {
                case GameMode.Fortress:
                    tickMethod = WorldTickMethod.Simultaneous;
                    break;

                case GameMode.Adventure:
                    tickMethod = WorldTickMethod.Sequential;
                    break;

                default:
                    throw new Exception();
            }

            var world = new World(mode, tickMethod);

            Action<World> worldCreator;

            switch (map)
            {
                case GameMap.Fortress:
                    worldCreator = Fortress.MountainWorldCreator.InitializeWorld;
                    break;

                case GameMap.Adventure:
                    var dwc = new Fortress.DungeonWorldCreator(world);
                    worldCreator = dwc.InitializeWorld;
                    break;

                case GameMap.Arena:
                    throw new Exception();

                default:
                    throw new Exception();
            }

            world.Initialize(delegate
            {
                worldCreator(world);
            });

            var engine = new GameEngine(world, mode);

            InitGame(engine, gameDir);

            return engine;
        }
Esempio n. 6
0
        public Player(int userID, GameEngine engine)
        {
            this.UserID = userID;

            m_engine = engine;
            m_world = engine.World;

            m_seeAll = false;

            m_controllables = new List<LivingObject>();

            Construct();
        }
Esempio n. 7
0
        public IPRunner(World world, GameEngine engine, Player player)
        {
            m_player = player;
            m_scriptOutputStream = new MyStream(player.Send);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();

            InitRuntime(m_scriptEngine.Runtime);

            m_exprScope = m_scriptEngine.CreateScope();
            InitScope(m_exprScope, world, engine, player);

            m_scriptScope = m_scriptEngine.CreateScope();
            InitScope(m_scriptScope, world, engine, player);
        }
Esempio n. 8
0
        protected Player(int playerID, GameEngine engine)
        {
            // player ID 0 is invalid, 1 is reserved for server
            if (playerID == 0 || playerID == 1)
                throw new Exception();

            this.PlayerID = playerID;

            m_engine = engine;
            m_world = engine.World;

            m_seeAll = ServerConfig.AllPlayersSeeAll;

            m_controllables = new List<LivingObject>();

            Construct();
        }
Esempio n. 9
0
        public void InitializeWorld(World world)
        {
            var envBuilder = new EnvironmentObjectBuilder(new IntSize3(64, 64, 4), VisibilityMode.AllVisible);

            TileData td;

            int surfaceLevel = 2;

            td = new TileData() { TerrainID = TerrainID.NaturalWall, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty };
            FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 0), td);
            FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 1), td);

            td = new TileData() { TerrainID = TerrainID.NaturalFloor, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty };
            FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 2), td);

            td = new TileData() { TerrainID = TerrainID.Empty, InteriorID = InteriorID.Empty };
            FillVolume(envBuilder, new IntBox(envBuilder.Bounds.Plane, 3), td);

            td = new TileData() { TerrainID = TerrainID.NaturalWall, TerrainMaterialID = MaterialID.Granite, InteriorID = InteriorID.Empty };
            DrawRect(envBuilder, new IntRectZ(envBuilder.Bounds.Plane, 2), td);

            var env = envBuilder.Create(world);
            env.HomeLocation = new IntPoint3(envBuilder.Width / 2, 4, surfaceLevel);

            /* Add Monsters */

            CreateSheep(env, surfaceLevel);

            {
                var builder = new LivingObjectBuilder(LivingID.Wolf);
                var wolf = builder.Create(env.World);
                var ai = new Dwarrowdelf.AI.CarnivoreAI(wolf);
                wolf.SetAI(ai);

                wolf.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel));
            }

            {
                var builder = new LivingObjectBuilder(LivingID.Dragon);
                var dragon = builder.Create(env.World);
                var ai = new Dwarrowdelf.AI.MonsterAI(dragon);
                dragon.SetAI(ai);

                dragon.MoveTo(env, GetRandomSurfaceLocation(env, surfaceLevel));
            }
        }
Esempio n. 10
0
		public static EnvironmentObject InitializeWorld(World world, IntSize3 size)
		{
#if CACHE_TERRAIN
			var terrain = CreateOrLoadTerrain(size);
#else
			var terrain = CreateTerrain(size);
#endif

			// XXX this is where WorldPopulator creates some buildings
			var p2 = new IntVector2(terrain.Width / 2, terrain.Height / 2);
			var startLoc = terrain.GetSurfaceLocation(p2);

			var env = EnvironmentObject.Create(world, terrain, VisibilityMode.GlobalFOV, startLoc);

			//CreateWaterTest(env);

			FortressWorldPopulator.FinalizeEnv(env);

			return env;
		}
Esempio n. 11
0
        public GameEngine(World world, GameMode mode)
        {
            m_world = world;

            this.GameMode = mode;

            m_players = new List<Player>();

            m_config = new GameConfig
            {
                RequirePlayer = true,
                MaxMoveTime = TimeSpan.Zero,
                MinTickTime = TimeSpan.FromMilliseconds(50),
            };

            m_minTickTimer = new Timer(this._MinTickTimerCallback);
            m_maxMoveTimer = new Timer(this._MaxMoveTimerCallback);

            this.LastSaveID = Guid.Empty;
            this.LastLoadID = Guid.Empty;
        }
Esempio n. 12
0
        protected override void Initialize(World world)
        {
            base.Initialize(world);

            world.TickStarted += OnTickStart;
        }
Esempio n. 13
0
        protected virtual void Initialize(World world)
        {
            if (this.IsInitialized)
                throw new Exception();

            if (m_objectType == ObjectType.None)
                throw new Exception();

            this.World = world;
            this.ObjectID = world.GetNewObjectID(m_objectType);

            this.CreationTime = DateTime.Now;
            this.CreationTick = this.World.TickNumber;

            this.World.AddGameObject(this);
            this.IsInitialized = true;
            this.World.AddChange(new ObjectCreatedChange(this));
        }
Esempio n. 14
0
 public ItemObject Create(World world)
 {
     return ItemObject.Create(world, this);
 }
Esempio n. 15
0
 internal static ItemObject Create(World world, ItemObjectBuilder builder)
 {
     var ob = new ItemObject(builder);
     ob.Initialize(world);
     return ob;
 }
Esempio n. 16
0
 public LivingObject Create(World world)
 {
     return LivingObject.Create(world, this);
 }
Esempio n. 17
0
 protected override void Initialize(World world)
 {
     base.Initialize(world);
     world.AddLiving(this);
     world.TickStarting += OnTickStart;
 }
Esempio n. 18
0
 internal static LivingObject Create(World world, LivingObjectBuilder builder)
 {
     var ob = new LivingObject(builder);
     ob.Initialize(world);
     return ob;
 }
Esempio n. 19
0
        protected override void Initialize(World world)
        {
            base.Initialize(world);
            world.AddLiving(this);
            world.TickEnding += OnTickEnding;
            world.TickStarted += OnTickStarted;

            this.Trace = new MyTraceSource("Server.LivingObject",
                String.Format("{0} ({1})", this.Name ?? this.LivingInfo.Name, this.ObjectID));
        }
Esempio n. 20
0
        void InitScope(ScriptScope scope, World world, GameEngine engine, Player player)
        {
            var globals = new Dictionary<string, object>()
            {
                { "world", world },
                { "engine", engine },
                { "player", player},
                { "get", new Func<object, BaseObject>(world.IPGet) },
            };

            foreach (var kvp in globals)
                scope.SetVariable(kvp.Key, kvp.Value);

            // XXX perhaps this can also be done with C# somehow...
            m_scriptEngine.Execute("import Dwarrowdelf", scope);
        }
Esempio n. 21
0
        public static EnvironmentObject Create(World world, Dwarrowdelf.TerrainGen.TerrainData terrain, VisibilityMode visMode,
			IntVector3 startLocation)
        {
            var ob = new EnvironmentObject(terrain, visMode, startLocation);
            ob.Initialize(world);
            return ob;
        }
Esempio n. 22
0
        protected override void Initialize(World world)
        {
            base.Initialize(world);

            CommonInit(true);
        }
Esempio n. 23
0
 public InvokeList(World world)
 {
     m_world = world;
 }
Esempio n. 24
0
 public DungeonGameManager(World world)
 {
     this.World = world;
 }