You are browsing as a guest. Sign up (or log in) to start making projects!

2h 44m 24s logged

I HAVE A PLANN

For the spinal sprint toward completion. Should end up taking me to hour 70-75? Then we polish the UI and add a main menu… lacking feature I guess.

Anyways, reorganised the code base and split game manager up, created folders and fixed dependencies for everything.

There is now an event manager, which handles all of the events separately, and as you can see from this simple to-do list (should my next project be the to do list to end all to do lists with calendar integration and stuff???) that I have completed the first bit “Weighted Event system”.

So now nothing has an equal chance of happening! Also as a side effect made adding new effects a lot easier due to the nested WeightedEvents class which was similar to an idea I had in my old minecraft mod plugin and transferred the skills across the languages.

Quite nice neat code actually, that isn’t 600 lines long, so I can quickly show it to you below. It’s very applicable and I believe I have used it twice or three times in the past 4 months alone.

The declarations for the events now look like this, very centralised and easy to add/remove events and modify the weightings. Called in the Start() function.

        weightedEvents.Add(new WeightedEvent("Nothing", 20, () => { }));
        weightedEvents.Add(new WeightedEvent("Earthquake", 5, Earthquake));
        weightedEvents.Add(new WeightedEvent("Fire", 40, SetBuildingOnFire));
        weightedEvents.Add(new WeightedEvent("Virus", 20, () => { TriggerVirusOutbreak(); } ));

and the class is just simply storing the name, the weight and a weighted Event.

public class WeightedEvent
    {
        public string name;
        public int weight;
        public Action weightedEvent;

        public WeightedEvent(string name, int weight, Action weightedEvent)
        {
            this.name = name;
            this.weight = weight;
            this.weightedEvent = weightedEvent;
        }
    }

we do need to store the total weight which happens on the Start() function currently. When playRandomEvent() is called, we increase the cursor by the event’s weight until it is greater than the rolled random number between 0 and the total weight, at which point the class’ event is called.

Broke nothing in the end!

That’s great isn’t it, especially after migrating a bunch of “legacy” code. Hopefully didn’t jinx it.

1
53

Comments 0

No comments yet. Be the first!