예제 #1
0
        /// <summary>
        /// Transfer development rights to a given player.
        /// </summary>
        /// This method does not invoke status updates for in-world views.
        /// <param name="bp"></param>
        /// <param name="p"></param>
        protected void TransferDevelopmentRights(BuyPoint bp, Player p)
        {
            // Hack: First we always clear the parcel of existing fields, even if the old and new specializations
            // are no different
            ChangeBuyPointSpecialization(bp, AbstractGameAssetType.None, 0);

            bp.DevelopmentRightsOwner = p;

            AbstractGameAssetType allowedType = p.Role.AllowedAssets[0].Type;
            int fields = 0;

            // FIXME: Temporarily hardcoded
            switch (allowedType)
            {
            case AbstractGameAssetType.Houses:
                fields = 20;
                break;

            case AbstractGameAssetType.Crops:
                fields = 6;
                break;

            case AbstractGameAssetType.Factory:
                fields = 2;
                break;
            }

            // Morph plynth and adjust fields
            // FIXME: This should be done via event subscription
            ChangeBuyPointSpecialization(bp, allowedType, fields);
        }
        public IDictionary <AbstractGameAssetType, string[]> Forecast(Game game)
        {
            Dictionary <AbstractGameAssetType, string[]> humanForecasts
                = new Dictionary <AbstractGameAssetType, string[]>();

            int[] agatValues = (int[])Enum.GetValues(typeof(AbstractGameAssetType));
            foreach (int agatValue in agatValues)
            {
                AbstractGameAssetType type = (AbstractGameAssetType)agatValue;

                humanForecasts[type] = new string[4];

                for (int level = 1; level <= 3; level++)
                {
                    double forecast;

                    if (!Deviations.ContainsKey(type))
                    {
                        forecast = 1;
                    }
                    else if (Deviations[type][level] == null)
                    {
                        forecast = 1;
                    }
                    else if (game.CurrentRound <= Deviations[type][level].Length - 1)
                    {
                        forecast = Deviations[type][level][game.CurrentRound];
                    }
                    else
                    {
                        forecast = 1;
                    }

                    string humanForecast;
                    if (forecast >= 1.65)
                    {
                        humanForecast = "Good";
                    }
                    else if (forecast >= 1)
                    {
                        humanForecast = "Normal";
                    }
                    else if (forecast >= 0.65)
                    {
                        humanForecast = "Below Normal";
                    }
                    else
                    {
                        humanForecast = "Recession";
                    }

                    humanForecasts[type][level] = humanForecast;
                }
            }

            return(humanForecasts);
        }
예제 #3
0
        public Dictionary <UUID, Field> ChangeBuyPointSpecialization(BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            Dictionary <UUID, Field> fields = new Dictionary <UUID, Field>();

            for (int i = 0; i < numberOfFields; i++)
            {
                Field f = m_controller.ModelFactory.CreateField(bp, UUID.Random(), "Test Field");
                fields.Add(f.Uuid, f);
            }

            return(fields);
        }
예제 #4
0
        public IDictionary <AbstractGameAssetType, double[]> Generate(Game game)
        {
            IDictionary <AbstractGameAssetType, double[]> activityByAgat
                = new Dictionary <AbstractGameAssetType, double[]>();

            int[] agatValues = (int[])Enum.GetValues(typeof(AbstractGameAssetType));
            foreach (int agatValue in agatValues)
            {
                AbstractGameAssetType type = (AbstractGameAssetType)agatValue;
                double[] levelValues       = new double[4];

                if (Deviations.ContainsKey(type))
                {
                    double[][] levelDeviations = Deviations[type];

                    for (int i = 1; i < levelDeviations.Length; i++)
                    {
//                        m_log.InfoFormat(
//                            "[WATER WARS]: Fetching deviation for {0} at level [{1}], round [{2}]",
//                            type, i, game.CurrentRound);

                        if (levelDeviations[i] == null)
                        {
                            levelValues[i] = 1;
                        }
                        else if (levelDeviations[i].Length - 1 >= game.CurrentRound)
                        {
                            levelValues[i] = levelDeviations[i][game.CurrentRound];
                        }
                        else
                        {
                            levelValues[i] = 1;
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= 3; i++)
                    {
                        levelValues[i] = 1;
                    }
                }

                activityByAgat[type] = levelValues;
            }

            return(activityByAgat);
        }
예제 #5
0
        public Dictionary <UUID, Field> ChangeBuyPointSpecialization(
            BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            Dictionary <UUID, Field> fields = new Dictionary <UUID, Field>();

            for (int i = 1; i <= numberOfFields; i++)
            {
                Field f = m_controller.ModelFactory.CreateField(bp, UUID.Random(), string.Format("Field {0}", i));
                fields[f.Uuid] = f;
            }

            lock (m_buyPointViews)
                GetBuyPointView(bp.Uuid).ChangeSpecialization(type, fields.Values.ToList());

            return(fields);
        }
예제 #6
0
        protected void ChangeBuyPointSpecialization(BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            IDictionary <UUID, Field> oldFields = bp.Fields;

            lock (oldFields)
            {
                List <Field> oldFieldsList = new List <Field>(oldFields.Values);

                foreach (Field f in oldFieldsList)
                {
                    // HACK: This is a nasty approach to maintaining referential integrity.  Nulling the buy point
                    // on the field also removes it from the buypoint list.
                    f.BuyPoint = null;
                }
            }

            m_controller.Dispatcher.ChangeBuyPointSpecialization(bp, type, numberOfFields);
        }
예제 #7
0
        public AbstractGameAsset(
            string name, UUID uuid, AbstractGameAssetType type, Vector3 position, int level, int minLevel, int maxLevel)
            : base(uuid, type, name)
        {
            // Don't set field to None, since this causes a loop with Field.BuyPoint = BuyPoint.None
            // We don't need Field.None here anyway, since there is never a situation conceptually or practically where
            // a game asset exists without some field (i.e. we set it before it is used anywhere).
            //            Field = Field.None;
            Position = position;
            MinLevel = minLevel;
            MaxLevel = maxLevel;
            Level = level;

            InitialTimesToLive = new int[MaxLevel + 1];
            for (int l = MinLevel; l <= MaxLevel; l++)
                InitialTimesToLive[l] = INFINITE_TIME_TO_LIVE;
            TimeToLive = INFINITE_TIME_TO_LIVE;
        }
예제 #8
0
        public AbstractGameAsset(
            string name, UUID uuid, AbstractGameAssetType type, Vector3 position, int level, int minLevel, int maxLevel)
            : base(uuid, type, name)
        {
            // Don't set field to None, since this causes a loop with Field.BuyPoint = BuyPoint.None
            // We don't need Field.None here anyway, since there is never a situation conceptually or practically where
            // a game asset exists without some field (i.e. we set it before it is used anywhere).
//            Field = Field.None;
            Position = position;
            MinLevel = minLevel;
            MaxLevel = maxLevel;
            Level    = level;

            InitialTimesToLive = new int[MaxLevel + 1];
            for (int l = MinLevel; l <= MaxLevel; l++)
            {
                InitialTimesToLive[l] = INFINITE_TIME_TO_LIVE;
            }
            TimeToLive = INFINITE_TIME_TO_LIVE;
        }
예제 #9
0
 public AbstractGameModel(UUID uuid, AbstractGameAssetType type, string name)
     : base(uuid, name)
 {
     Game = Game.None;
     Type = type;
 }
예제 #10
0
        public Dictionary<UUID, Field> ChangeBuyPointSpecialization(
             BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            Dictionary<UUID, Field> fields = new Dictionary<UUID, Field>();
            for (int i = 1; i <= numberOfFields; i++)
            {
                Field f = m_controller.ModelFactory.CreateField(bp, UUID.Random(), string.Format("Field {0}", i));
                fields[f.Uuid] = f;
            }

            lock (m_buyPointViews)
                GetBuyPointView(bp.Uuid).ChangeSpecialization(type, fields.Values.ToList());

            return fields;
        }
예제 #11
0
 public AbstractGameModel(UUID uuid, AbstractGameAssetType type, string name) : base(uuid, name)
 {
     Game = Game.None;
     Type = type;           
 }
예제 #12
0
        /// <summary>
        /// Change the specialization presentation of this buy point view
        /// </summary>
        /// <param name="assetType"></param>
        /// <param name="fields">Fields for which field views need to be created</param>
        public Dictionary<UUID, FieldView> ChangeSpecialization(AbstractGameAssetType assetType, List<Field> fields)
        {
            Dictionary<UUID, FieldView> fvs = new Dictionary<UUID, FieldView>();

            string morphItemName = m_veSceneObjectNames[assetType];
            ChangeSceneObject(m_itemStoreView, morphItemName);
            m_bp.Name = morphItemName;

            if (assetType != AbstractGameAssetType.None)
            {
                Vector3 p1, p2;
                WaterWarsUtils.FindSquareParcelCorners(m_bp.Location.Parcel, out p1, out p2);

            //                m_log.InfoFormat("[WATER WARS]: Found corners of parcel at ({0}),({1})", p1, p2);

                int shortDimension = (int)Math.Floor(Math.Sqrt(fields.Count));
                int longDimension = (int)Math.Ceiling((float)fields.Count / shortDimension);
            //                m_log.InfoFormat("[WATER WARS]: Would space as [{0}][{1}]", shortDimension, longDimension);

                // XXX: For now, we're always going to short space the fields on the x axis
                // This shouldn't be a problem if all our regions are square but might start to look a bit odd if they
                // were different rectangular sizes

                // Adjust dimensions to leave a gap around the edges for the buypoint
                p1.X += 5;
                p1.Y += 5;
                p2.X -= 5;
                p2.Y -= 5;

                float xSpacing = (p2.X - p1.X) / (float)shortDimension;
                float ySpacing = (p2.Y - p1.Y) / (float)longDimension;

                List<Vector3> placementPoints = new List<Vector3>();

            //                for (int y = y1; y < y2; y += ySpacing)
            //                {
            //                    for (float x = x1; x < x2; x += xSpacing)
            //                    {
            //                        placementPoints.Add(new Vector3(x, y, (float)heightHere + 0.1f));
            //                    }
            //                }

                for (int y = 0; y < longDimension; y++)
                {
                    for (float x = 0; x < shortDimension; x++)
                    {
                        Vector3 spacing = new Vector3(x * xSpacing, y * ySpacing, 2f);
                        placementPoints.Add(p1 + spacing);
                    }
                }

                m_fieldViewScale = new Vector3(xSpacing, ySpacing, 0.1f);
                Vector3 placementAdjustment = new Vector3(xSpacing / 2, ySpacing / 2, 0);

                int i = 0;
                foreach (Vector3 v in placementPoints)
                {
                    FieldView fv = CreateFieldView(fields[i++], v + placementAdjustment);
                    fvs.Add(fv.RootPart.UUID, fv);
                }
            }
            else
            {
                lock (m_fieldViews)
                {
                    foreach (FieldView fv in m_fieldViews.Values)
                        fv.Close();

                    m_fieldViews.Clear();
                }
            }

            return fvs;
        }
예제 #13
0
        /// <summary>
        /// Change the specialization presentation of this buy point view
        /// </summary>
        /// <param name="assetType"></param>
        /// <param name="fields">Fields for which field views need to be created</param>
        public Dictionary <UUID, FieldView> ChangeSpecialization(AbstractGameAssetType assetType, List <Field> fields)
        {
            Dictionary <UUID, FieldView> fvs = new Dictionary <UUID, FieldView>();

            string morphItemName = m_veSceneObjectNames[assetType];

            ChangeSceneObject(m_itemStoreView, morphItemName);
            m_bp.Name = morphItemName;

            if (assetType != AbstractGameAssetType.None)
            {
                Vector3 p1, p2;
                WaterWarsUtils.FindSquareParcelCorners(m_bp.Location.Parcel, out p1, out p2);

//                m_log.InfoFormat("[WATER WARS]: Found corners of parcel at ({0}),({1})", p1, p2);

                int shortDimension = (int)Math.Floor(Math.Sqrt(fields.Count));
                int longDimension  = (int)Math.Ceiling((float)fields.Count / shortDimension);
//                m_log.InfoFormat("[WATER WARS]: Would space as [{0}][{1}]", shortDimension, longDimension);

                // XXX: For now, we're always going to short space the fields on the x axis
                // This shouldn't be a problem if all our regions are square but might start to look a bit odd if they
                // were different rectangular sizes

                // Adjust dimensions to leave a gap around the edges for the buypoint
                p1.X += 5;
                p1.Y += 5;
                p2.X -= 5;
                p2.Y -= 5;

                float xSpacing = (p2.X - p1.X) / (float)shortDimension;
                float ySpacing = (p2.Y - p1.Y) / (float)longDimension;

                List <Vector3> placementPoints = new List <Vector3>();

//                for (int y = y1; y < y2; y += ySpacing)
//                {
//                    for (float x = x1; x < x2; x += xSpacing)
//                    {
//                        placementPoints.Add(new Vector3(x, y, (float)heightHere + 0.1f));
//                    }
//                }

                for (int y = 0; y < longDimension; y++)
                {
                    for (float x = 0; x < shortDimension; x++)
                    {
                        Vector3 spacing = new Vector3(x * xSpacing, y * ySpacing, 2f);
                        placementPoints.Add(p1 + spacing);
                    }
                }

                m_fieldViewScale = new Vector3(xSpacing, ySpacing, 0.1f);
                Vector3 placementAdjustment = new Vector3(xSpacing / 2, ySpacing / 2, 0);

                int i = 0;
                foreach (Vector3 v in placementPoints)
                {
                    FieldView fv = CreateFieldView(fields[i++], v + placementAdjustment);
                    fvs.Add(fv.RootPart.UUID, fv);
                }
            }
            else
            {
                lock (m_fieldViews)
                {
                    foreach (FieldView fv in m_fieldViews.Values)
                    {
                        fv.Close();
                    }

                    m_fieldViews.Clear();
                }
            }

            return(fvs);
        }
예제 #14
0
        public Dictionary<UUID, Field> ChangeBuyPointSpecialization(BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            Dictionary<UUID, Field> fields = new Dictionary<UUID, Field>();

            for (int i = 0; i < numberOfFields; i++)
            {
                Field f = m_controller.ModelFactory.CreateField(bp, UUID.Random(), "Test Field");
                fields.Add(f.Uuid, f);
            }

            return fields;
        }
예제 #15
0
        protected void ChangeBuyPointSpecialization(BuyPoint bp, AbstractGameAssetType type, int numberOfFields)
        {
            IDictionary<UUID, Field> oldFields = bp.Fields;

            lock (oldFields)
            {
                List<Field> oldFieldsList = new List<Field>(oldFields.Values);

                foreach (Field f in oldFieldsList)
                {
                    // HACK: This is a nasty approach to maintaining referential integrity.  Nulling the buy point
                    // on the field also removes it from the buypoint list.
                    f.BuyPoint = null;
                }
            }

            m_controller.Dispatcher.ChangeBuyPointSpecialization(bp, type, numberOfFields);
        }
예제 #16
0
        /// <summary>
        /// Initialize the controller
        /// </summary>
        /// <param name="attachToVe">If true then the game is attached to the virtual environment</param>
        public void Initialise(bool attachToVe)
        {
            AttachedToVe = attachToVe;

            ModelFactory = new ModelFactory(this);
            Game         = ModelFactory.CreateGame(UUID.Random(), "Game1");

            Commands          = new WaterWarsCommands(this);
            Resolver          = new OpenSimResolver(this);
            ViewerWebServices = new ViewerWebServices(this);
            HudManager        = new HudViewManager(this);
            Events            = new WaterWars.Events.Events(this);
            Feeds             = new WaterWars.Feeds.Feeds(this);
            GameDateManager   = new GameDateManager(this);
            RoundManager      = new RoundManager(this);
            StageTimer        = new StageTimer(this);

            RainfallGenerator.Initialize(EventManager);
            WaterDistributor.Initialize(EventManager);

            if (null != Persister)
            {
                Persister.Initialize(this);
            }

            if (null != m_recorder)
            {
                m_recorder.Initialize(this);
            }

            // This has to be called before we establish a game state so that the persisted game object
            // can first be created
            EventManager.TriggerSystemInitialized();

            new RegistrationState(this).Activate();

            if (AttachedToVe)
            {
                Groups = new OpenSimGroupsMediator(this);

                CheckVeRequirements();

                foreach (Scene scene in Scenes)
                {
                    // Stop players deleting or editing objects they 'own'
                    scene.Permissions.OnRezObject += delegate(int objectCount, UUID owner, Vector3 objectPosition, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(owner));
                    };
                    scene.Permissions.OnDeleteObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnTakeObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnTakeCopyObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnEditObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };
                    scene.Permissions.OnMoveObject += delegate(UUID objectID, UUID userID, Scene myScene) {
                        return(Groups.IsPlayerAnAdmin(userID));
                    };

                    EntityBase[] entities = scene.Entities.GetAllByType <SceneObjectGroup>();

                    // Pass 1 - pick up the game manager view (first level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        //                    m_log.InfoFormat(
                        //                        "[WATER WARS]: Pass 1 - processing {0} {1} at {2} in existing scene",
                        //                        so.Name, so.LocalId, so.AbsolutePosition);

                        // This is messy, but there's actually only one game manager from which objects can come.
                        if (so.Name == GameManagerView.IN_WORLD_NAME)
                        {
                            GameManagerView = new GameManagerView(this, scene);
                            GameManagerView.Initialize(so);
                            Dispatcher.RegisterGameManagerView(GameManagerView);
                        }
                        else if (
                            so.Name == StepBuiltDecorator.IN_WORLD_NAME ||
                            so.Name == WaterAllocationDecorator.IN_WORLD_NAME)
                        {
                            // FIXME: Temporarily, just delete our one decorator by name.
                            // Eventually, the decorators will need to be re-registered with their game asset view.
                            so.Scene.DeleteSceneObject(so, false);
                        }
                    }
                }

                if (GameManagerView == null)
                {
                    throw new Exception(
                              string.Format(
                                  "Could not find GameManagerView named {0} in any of the scenes.  ABORTING.",
                                  GameManagerView.IN_WORLD_NAME));
                }

                foreach (Scene scene in Scenes)
                {
                    m_log.InfoFormat("[WATER WARS]: Processing buypoints on scene {0}", scene.RegionInfo.RegionName);

                    // We'll keep track of these so that we can use them in pass 3
                    Dictionary <UUID, BuyPointView> buyPointViews = new Dictionary <UUID, BuyPointView>();

                    EntityBase[] entities = scene.Entities.GetAllByType <SceneObjectGroup>();

                    // Pass 2 - pick up the buy points (second level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
                            //                    m_log.InfoFormat(
                            //                        "[WATER WARS]: Pass 2 - processing {0} {1} at {2} in existing scene",
                            //                        so.Name, so.LocalId, so.AbsolutePosition);

                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Parcel)
                                {
                                    // We're using in-world buy point positioning to register them - not taking these from an
                                    // internal database and pushing them back up to the ve
                                    //
                                    // FIXME: The below might be old advice since I have now changed things such that
                                    // we can specify the uuid upfront
                                    //
                                    // We can't incorporate the first update buy point call within bpv.Initialize() because it
                                    // won't yet have registered with the dispatcher (which forms an intermediate layer between the
                                    // game logic and the view code).
                                    // We can't register with the dispatcher before initializing the view because no UUID will yet
                                    // exist for the dispatcher to record.
                                    // It might be possible to simplify this if we adapt OpenSim to allow us to specify the UUID
                                    // up-front.  But other VE systems may not allow this.
                                    BuyPoint     bp  = Resolver.RegisterBuyPoint(so);
                                    BuyPointView bpv = GameManagerView.CreateBuyPointView(so, bp);
                                    buyPointViews.Add(bpv.Uuid, bpv);
                                    State.UpdateBuyPointStatus(bp);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }

                    // Pass 3 - pick up the fields and game assets (third level of the hierarchy)
                    foreach (EntityBase e in entities)
                    {
                        SceneObjectGroup so = (SceneObjectGroup)e;

                        try
                        {
                            IConfig config = GetPrimConfig(so);

                            if (config != null)
                            {
                                AbstractGameAssetType modelType = GetModelTypeFromPrimConfig(config);

                                if (modelType == AbstractGameAssetType.Field)
                                {
                                    Field        f   = Resolver.RegisterField(so);
                                    BuyPointView bpv = null;
                                    if (buyPointViews.TryGetValue(f.BuyPoint.Uuid, out bpv))
                                    {
                                        bpv.CreateFieldView(so);
                                    }
                                    else
                                    {
                                        throw new Exception(
                                                  string.Format(
                                                      "Could not find BuyPointView for field {0}, parcel {1} at {2}",
                                                      f.Name, f.BuyPoint.Name, f.BuyPoint.Location.LocalPosition));
                                    }
                                }
                                else if (
                                    modelType == AbstractGameAssetType.Crops ||
                                    modelType == AbstractGameAssetType.Houses ||
                                    modelType == AbstractGameAssetType.Factory)
                                {
                                    // For now, just delete any existing game assets immediately.
                                    so.Scene.DeleteSceneObject(so, false);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_log.Error(
                                string.Format(
                                    "[WATER WARS]: Could not register {0} at {1} in {2}, ",
                                    so.Name, so.AbsolutePosition, so.Scene.RegionInfo.RegionName),
                                ex);
                        }
                    }
                }

                HudManager.Initialise();

                // Register in-game objects as they are created
                //m_scene.EventManager.OnObjectBeingAddedToScene += OnObjectAddedToScene;

                // At the moment, reset the game immediately on restarting so that we have a blank slate
                State.ResetGame();

//                string statePath = Path.Combine(WaterWarsConstants.STATE_PATH, WaterWarsConstants.STATE_FILE_NAME);
//                if (File.Exists(statePath))
//                    RestoreGame(statePath);
            }
        }