コード例 #1
0
ファイル: Action.cs プロジェクト: bilwis/SH2RL
        /// <summary>
        /// Creates a new action for the given creature with the given parameters and cost.
        /// </summary>
        /// <param name="type">An ActionType enumeration entry describing the type of the action.</param>
        /// <param name="param">An ActionParameters object.</param>
        /// <param name="subject">The subject, which actually performs the action.</param>
        /// <param name="cost">The cost of the action.</param>
        public Action(ActionType type, ActionParameters param, Creature subject, double cost)
        {
            this.Type = type;
            this.Subject = subject;
            this.Cost = cost;

            //Check if correct parameters
            switch (Type)
            {
                case ActionType.Move:
                    if (param.GetType() != typeof(MovementActionParameters))
                        throw new Exception("Tried to construct Action of type MOVE, but parameters are not MovementActionParameters!");
                    break;
                case ActionType.Take:
                    if (param.GetType() != typeof(TakeActionParameters))
                        throw new Exception("Tried to construct Action of type TAKE, but parameters are not TakeActionParameters!");
                    break;
                case ActionType.Equip:
                    if (param.GetType() != typeof(EquipActionParameters))
                        throw new Exception("Tried to construct Action of type EQUIP, but parameters are not EquipActionParameters!");
                    break;
                case ActionType.Unequip:
                    if (param.GetType() != typeof(UnequipActionParameters))
                        throw new Exception("Tried to construct Action of type UNEQUIP, but parameters are not UnequipActionParameters!");
                    break;
            }

            this.Param = param;
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: bilwis/SH2RL
        /// <summary>
        /// Initialize a new map object.
        /// </summary>
        public Map(Creature player, WorldMap wm, MessageHandler _out, FactionManager facman, SQLiteConnection dbconn, int vp_height, int vp_width)
        {
            this.Player = player;
            this.wm = wm;
            this._out = _out;
            this.dbconn = dbconn;
            this.vp_height = vp_height;
            this.vp_width = vp_width;

            sun_level_changed = true;

            CreatureList = new Inventory<Creature>();
            ItemList = new Inventory<Item>();
            //LightSources = new Dictionary<string, LightSource>();
            this.facman = facman;

            tcod_map = new TCODMap(3 * wm.CELL_WIDTH, 3 * wm.CELL_HEIGHT);
            light_tint = new int[vp_width, vp_height];

            cells = new Cell[3, 3, 3];
            centerAndLoad(player);
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: bilwis/SH2RL
        /// <summary>
        /// This function assigns the central cell to the cell in which the player currently resides and loads all surrounding
        /// cells into memory.
        /// </summary>
        private void centerAndLoad(Creature player)
        {
            cells[1, 1, 1] = wm.GetCellFromCoordinates(player.X, player.Y, player.Z);
            cells[1, 1, 1].Load();
            currentCellId = cells[1, 1, 1].CellID;

            loaded = new bool[3, 3, 3];
            loaded[1, 1, 1] = true;

            load_after = new bool[3, 3, 3];
            load_after[1, 1, 1] = true;

            for (int x = -1; x < 2; x++)
            {
                for (int y = -1; y < 2; y++)
                {
                    for (int z = -1; z < 2; z++)
                    {
                        if (!(x == 0 && y == 0 && z == 0))
                        {
                            cells[1 + x, 1 + y, 1 + z] = wm.GetAdjacentCell(x, y, z, cells[1, 1, 1]);

                            if (cells[1 + x, 1 + y, 1 + z] == null)
                                throw new Exception("Player in border cell!");

                            if (Program.game.MULTITHREADED_LOADING)
                            {
                                load_after[1 + x, 1 + y, 1 + z] = true;

                                System.ComponentModel.BackgroundWorker bw = new System.ComponentModel.BackgroundWorker();
                                bw.DoWork += new System.ComponentModel.DoWorkEventHandler(backgroundWorker_DoWork);
                                bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

                                bw.RunWorkerAsync(cells[1 + x, 1 + y, 1 + z]);
                            }
                            else
                            {
                                cells[1 + x, 1 + y, 1 + z].Load();
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: bilwis/SH2RL
        /// <summary>
        /// This function will register the given creature with the maps creature dictionaries.
        /// </summary>
        public bool AddCreature(Creature c)
        {
            //Check if creature is within one of the loaded cells
            if (isCoordinateLoaded(c.X, c.Y, c.Z) == false)
                return false;

            //Add to dictionaries
            CreatureList.Add(c);
            return true;
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: bilwis/SH2RL
        public void InitNew(string profile_name, uint map_seed)
        {
            string path = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Game)).CodeBase);
            path = path.Remove(0, 6);
            string newPath = System.IO.Path.Combine(path, "profiles", profile_name);
            Directory.CreateDirectory(newPath);

            ProfilePath = newPath;

            InitDB(newPath);

            rand = new Random();

            facman = new FactionManager();
            Faction player_faction = new Faction("Player", "The player");
            player_faction.Init(facman);

            //Faction human_faction = new Faction("Humans", "The surviors of their self-made cathastrophe.");
            Faction test_faction = new Faction("TESTFAC", "TEST FACTION PLEASE IGNORE");
            //human_faction.Init(facman);
            test_faction.Init(facman);

            //human_faction.AddRelation(test_faction, FactionRelation.Hostile);
            test_faction.AddRelation(player_faction, FactionRelation.Hostile);

            root.setBackgroundFlag(TCODBackgroundFlag.Default);

            player = new Player(1300, 1300, 35, "Player", "A ragged and scruffy-looking individual.", '@', new Body(BODY_DEF_HUMAN), new CharStats(10, 10, 10));

            player.Init(TCODColor.yellow, Out, player_faction, new Objects.Action(ActionType.Idle, null, player, 0.0d));

            Out.SendMessage("Welcome to [insert game name here]!", Message.MESSAGE_WELCOME);
            Out.SendMessage("You wake up in a damp and shoddy shack. Or maybe a patch of dirt. Depends on the games' version.");

            //Default map parameters
            int[] parameters = new int[7];
            parameters[0] = 200; //CellWidth
            parameters[1] = 200; //CellHeight
            parameters[2] = 20; //CellDepth

            parameters[3] = 10; //CellsX
            parameters[4] = 10; //CellsY
            parameters[5] = 6; //CellsZ

            parameters[6] = 45; //GroundLevel

            wm = new WorldMap(map_seed, dbconn, parameters);
            map = new Map(player, wm, Out, facman, dbconn, MAIN_HEIGHT - 2, WINDOW_WIDTH - 2);

            RenderLoadingScreen();

            player.SetPosition(player.X, player.Y, map.DropObject(player.X, player.Y, player.Z + 1));
            map.AddCreature(player);

            //testai = new AICreature(1301, 1301, 31, "TEST", "TEST CREATURE PLEASE IGNORE", 'A', new Body(BODY_DEF_HUMAN), new CharStats(10,10,10));
            //testai.Init(TCODColor.orange, Out, test_faction, new Objects.Action(ActionType.Idle, null, testai, 0.0d), new WalkerAI(rand.Next(0, 100000000)), map);
            //testai_guid = testai.GUID;
            //map.AddCreature(testai);

            dummy = new Creature(1299, 1299, 31, "TEST", "A Training Dummy.", 'D', new Body(BODY_DEF_HUMAN), new CharStats(10, 10, 10));
            dummy.Init(TCODColor.turquoise, Out);
            map.AddCreature(dummy);

            List<FireMode> gl_fm = new List<FireMode>();
            gl_fm.Add(FireMode.Semi);
            gl_fm.Add(FireMode.Burst2);
            testgun = new Firearm(1299, 1301, 31, "Glock 17C", "A semi-automatic pistol manufactured by Austrian Glock Ges. m.b.H. Large parts of it are manufactured from extremely resilient high-strengh polymer and it chambers NATO standard 9x19mm Parabellum rounds. It has a magazine capacity of 17 rounds. The C Variant features slots cut into the barrel and slide compensating for muzzle rise and recoil. It is one of the most commonly used firearms in US law enforcement and enjoys great popularity in the gun community.", 'F', 5.0d, new Caliber(9d, 19d), GunType.Pistol, gl_fm, 17);
            testgun.Init(TCODColor.grey, Out);

            testmag = new Magazine(1301, 1299, 31, "9mm Clip", "TEST MAG PLEASE IGNORE.", 'M', 0.75d, 30, 30, new Caliber(5.56d, 45.0d), AmmoModifier.Regular);
            testmag.Init(TCODColor.brass, Out);

            Item temp = new Item(1302, 1300, 31, "Apple", "A tasty red apple. Possibly Braeburn.", 'F', 0.3d);
            temp.Init(TCODColor.red, Out);

            LightSource p_torch = new LightSource(1300, 1300, 31, 50, 10, "Torch", "A torch.", '!', 1.0d);
            p_torch.Init(TCODColor.orange, Out);

            map.AddItem(testgun);
            map.AddItem(testmag);
            map.AddItem(temp);
            map.AddItem(p_torch);

            //AICreature testai2 = new AICreature(290, 290, 15, "TEST2", "TEST CREATURE PLEASE IGNORE", 'B');
            //testai2.Init(TCODColor.orange, Out, test_faction, new Objects.Action(ActionType.Idle, null, testai, 0.0d), new WalkerAI(rand.Next(0, 10000000)), map);
            //map.AddCreature(testai2);

            //Item test_item = new Item(1299, 1299, map.DropObject(1299, 1299, 35), "Shimmering rock", "A shining polished rock which seems to change color when you look at it.", (char)'*');
            //LightSource test_item = new LightSource(1299, 1299, map.DropObject(1299, 1299, 35), 12, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*');
            //test_item_guid = test_item.GUID;
            //test_item.Init(TCODColor.red, Out);
            //test_item.Activate();
            //map.AddItem(test_item);

            LightSource test_item2 = new LightSource(1295, 1310, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item2.Init(TCODColor.blue, Out);
            test_item2.Activate();
            map.AddItem(test_item2);

            LightSource test_item3 = new LightSource(1315, 1283, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item3.Init(TCODColor.green, Out);
            test_item3.Activate();
            map.AddItem(test_item3);

            LightSource test_item4 = new LightSource(1315, 1319, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item4.Init(TCODColor.orange, Out);
            test_item4.Activate();
            map.AddItem(test_item4);

            LightSource test_item5 = new LightSource(1291, 1283, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item5.Init(TCODColor.red, Out);
            test_item5.Activate();
            map.AddItem(test_item5);

            LightSource test_item6 = new LightSource(1305, 1300, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item6.Init(TCODColor.pink, Out);
            test_item6.Activate();
            map.AddItem(test_item6);

            LightSource test_item7 = new LightSource(1291, 1293, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d);
            test_item7.Init(TCODColor.violet, Out);
            test_item7.Activate();
            map.AddItem(test_item7);
        }
コード例 #6
0
ファイル: AI.cs プロジェクト: bilwis/SH2RL
        private AIEvalResult eval(Creature c)
        {
            if (c.GUID == subject.GUID)
                return AIEvalResult.Self;

            FactionRelation fr = subject.Faction.GetRelation(c.Faction);

            if (fr == FactionRelation.Hostile)
                return AIEvalResult.Enemy;

            if (fr == FactionRelation.Friendly)
                return AIEvalResult.Friendly;

            if (fr == FactionRelation.Neutral)
                return AIEvalResult.Neutral;

            return AIEvalResult.Unknown;
        }
コード例 #7
0
ファイル: Creature.cs プロジェクト: bilwis/SH2RL
        public void AttackRanged(Creature target)
        {
            _messageHandler.SendDebugMessage("######################################");
            _messageHandler.SendDebugMessage(Name + " tries to attack " + target.Name + "!");

            BodyPart tar_part = target.Body.GetRandomBodyPart();

            _messageHandler.SendDebugMessage(Name + " targets " + target.Name + "'s " + tar_part.Name + "!");
        }