예제 #1
0
        private void setClockHandlers()
        {
            //long today_h = TimeLength.pastMinutesToday().totalMinutes;
            long today_h = clock.hour;
            long today_m = today_h * Time.HOUR + clock.minutes;

            // MajorEvent occures both day and night. Generate trend making events.
            if (MajorUpdateEvent != null)
            {
                clock.unregister(MajorUpdateEvent);
            }
            MajorUpdateEvent = new ClockHandler(onMajorUpdate);
            long major = MajorUpdateStartingHour;

            while (major < today_h)
            {
                major += MajorUpdateIntervalHours;
            }
            clock.registerRepeated(MajorUpdateEvent,
                                   TimeLength.fromMinutes(major * Time.HOUR - today_m),
                                   TimeLength.fromHours(MajorUpdateIntervalHours));

            // MinorEvent dispached only in the business hours. Progresses trend only.
            if (MinorUpdateEvent != null)
            {
                clock.unregister(MinorUpdateEvent);
            }
            MinorUpdateEvent = new ClockHandler(onMinorUpdate);
            long minor = MinorUpdateStartingHour;

            while (minor < today_h)
            {
                minor += MinorUpdateIntervalHours;
            }
            clock.registerRepeated(MinorUpdateEvent,
                                   TimeLength.fromMinutes(minor * Time.HOUR - today_m),
                                   TimeLength.fromHours(MinorUpdateIntervalHours));
        }
예제 #2
0
        // don't allow instanciation from external objects
        private BankModule()
        {
            // Set clock timer
            clock.registerRepeated(
                new ClockHandler(statusClockHandler),
                TimeLength.untilTomorrow(),
                TimeLength.ONEDAY);

            clock.registerRepeated(
                new ClockHandler(statusClockHandler),
                TimeLength.untilTomorrow() +
                TimeLength.fromHours(BankConfig.openHour),
                TimeLength.ONEDAY);

            if (BankConfig.openHour % 24 != BankConfig.closeHour % 24)
            {
                clock.registerRepeated(
                    new ClockHandler(statusClockHandler),
                    TimeLength.untilTomorrow() +
                    TimeLength.fromHours(BankConfig.closeHour),
                    TimeLength.ONEDAY);
            }
        }
예제 #3
0
        /// <summary>
        /// Creates a new object and associates that with the world.
        /// </summary>
        /// <param name="w"></param>
        public LandValue(World w)
        {
            w.otherObjects["{51CD7E24-4296-4043-B58D-A654AB71F121}"] = this;

            H    = w.size.x;
            V    = w.size.y;
            q    = new float[H + 2, V + 2];
            back = new float[H + 2, V + 2];
            rho  = new float[H + 2, V + 2];

            // fill the array by 1.
            for (int h = H; h > 0; h--)
            {
                for (int v = V; v > 0; v--)
                {
                    rho[h, v] = RHO_BARE_LAND;
                }
            }

            // register the event notification so that we can update rho correctly
            w.onVoxelChanged += new VoxelChangeListener(updateRho);
            w.clock.registerRepeated(new ClockHandler(next), TimeLength.fromHours(UPDATE_FREQUENCY));
        }
예제 #4
0
        /// <summary>
        /// Creates a new commercial structurewith its left-top corner at
        /// the specified location.
        /// </summary>
        /// <param name="_type">
        /// Type of the structure to be built.
        /// </param>
        public StadiumStructure(StructureContributionImpl _type, WorldLocator wloc) : base(_type, wloc)
        {
//			this.type = _type;

            // register once a month timer for the strength/popularity decay
            World.world.clock.registerRepeated(new ClockHandler(onClock), TimeLength.fromDays(30));

            // schedule initial games
            // minutes to the next day midnight
            TimeLength b = TimeLength.fromMinutes(
                TimeLength.ONEDAY.totalMinutes
                - (World.world.clock.totalMinutes % TimeLength.ONEDAY.totalMinutes));

            // the first game is set to 14:00 that day.
            b += TimeLength.fromHours(14);

            for (int i = 0; i < Const.SCHEDULE_DAYS; i += 7)
            {
                scheduleNewGame(b);
                scheduleNewGame(b + TimeLength.fromHours(24 * 3 + 5));                  // schdule a nighter

                b += TimeLength.fromDays(7);
            }
        }
예제 #5
0
        /// <summary>
        /// Creates a new station object with its left-top corner at
        /// the specified location.
        /// </summary>
        /// <param name="_type">
        /// Type of the station to be built.
        /// </param>
        /// <param name="wloc"></param>
        public Station(StationContribution _type, WorldLocator wloc)
            : base(_type, wloc)
        {
            this.type  = _type;
            this._name = string.Format("ST{0,2:d}", iota++);
            if (wloc.world == WorldDefinition.World)
            {
                WorldDefinition.World.Stations.add(this);
                WorldDefinition.World.Clock.registerRepeated(new ClockHandler(clockHandlerHour), TimeLength.fromHours(1));
                WorldDefinition.World.Clock.registerRepeated(new ClockHandler(clockHandlerDay), TimeLength.fromHours(24));
            }
            Distance r = new Distance(REACH_RANGE, REACH_RANGE, REACH_RANGE);

            // advertise listeners in the neighborhood that a new station is available
            foreach (IEntity e in Cube.CreateInclusive(baseLocation - r, baseLocation + r).GetEntities())
            {
                IStationListener l = (IStationListener)e.QueryInterface(typeof(IStationListener));
                if (l != null)
                {
                    l.advertiseStation(this);
                }
            }
        }