New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event system #39
Event system #39
Conversation
This is a great idea, however... it will need to wait until after the stable release. That said, without pushing away your wonderful work, could I convince you to try and concentrate on bug fixes for now (in both MM and MHQ) so that we can get the stable out and start adding all these good features? |
Well, now - the whole of PR #37 was essentially one big bug fix. :) This is just something I threw up in a bit of a spare time between my "real" work. There's no need to hurry this either. As I wrote, I'm not sure if it is even in the right project. It might be more useful being a part of MegaMek instead. |
To add to ralgiths comment, I would say start with the oldest bug reports on sourceforge and close any that are no longer valid. I do think at least a quarter of them have either been fixed or are by now invalid. Or if you haven't been added to those projects at least leave a message for arlith or ralgith to close them. I will have a few bug fixes up and ready by the end of the weekend I hope. Two I posted on my fork and one I posted here. |
I'm not actually in the dev team over at SF, so I can at most comment there. A whole bunch of bugs deal with how AtB does things too, and I'm sadly not nearly versed enough in that to be able to help, nor do I know who I'd need to ask to make rule clarifications for it. |
Just grab a copy of the latest AtB spreadsheet. Most of the AtB stuff in HQ is rather ad-hoc or a best guess on how to apply it to a computer simulation. neoancient wrote the atb code for HQ but hasn't had time for it. Best advice, find the rule in the atb spreadsheet and best guess on how it should be coded. Thats about all you can do really. But when in doubt post a question about it. |
@Akjosch As to AtB Bugs: They're not stable blocking. So don't worry about them for stable plugging away. Worry about bugs with official rules, game breaking errors, and the like. |
We may want to consider adding an AtB wiki entry to the MHQ wiki. It could be a central location to catalog the AtB rules and how they get implemented in MHQ. |
@Akjosch I also added you to the developer group for the MM, MML, and MHQ projects on SF. |
@arlith I think a wiki entry would be a good idea... now where is our AtB developer when we need him ;) Also, I believe that something like that (being specific to MHQ) should be on the MHQ Wiki rather than our normal policy of everything going on the MM wiki. However, that may make it harder for newbies to find... so I'd appreciate other opinions there. |
I had the MHQ wiki in mind. The same thought crossed my mind, and since this is definitely specifically MHQ, I think it should go. It would be possible to link it, I think. |
Since @arlith wanted examples, here's one for the scenario resolution. Goal: Have a scenario where Side A has to:
That's a bunch of events and two event handlers.
Now the event handlers for determining when a scenario is won/lost. They get created and registered to the event handler when a game starts, and unregistered once it's done. There's one for the 'Mechs destroyed (which can be written even more generally than in this example) and one for building destroyed.
There's also a handler for
|
Another example, story creation. Somebody gets killed by the unit. Their family swears revenge.
The code marking the person as "killed" (scenario resolution, some random event, throwing prisoners out of an airlock, ...) calls
|
How about an example of a dynamically loaded module that creates an event and manages it? |
That dynamically loaded module is just like any other bunch of classes. The most work consists in creating the framework for dynamically loading it, not in the event system. So a mod class looks something like this, with some custom annotations to make our mod classloader aware of what methods in which class to call to initialise and shutdown the mod.
And the actual event handler is as above, dealing with whatever game events we want.
The main job here is the actual mod loader, which needs to have its own class loader (to disallow any mod which includes classes in the java., javax., sun., megamek. and mekhq.* namespaces, for example), defined mod lifetime hooks (the |
…e an event unregisters itself).
Resubmitted as a MegaMek PR. |
This is a simple, stand-alone event system. Its functions are modelled after the one in MinecraftForge, though it doesn't need to meet its performance or mod loading requirements, so no ASM and class loader trickery is required.
Example usage is marking event handling instance methods somewhere. This could be a separate class, but doesn't have to be - they work anywhere.
The event classes are (to be defined) subclasses of
mekhq.event.HQEvent
. Registering the handler is simple enough:And so is firing events:
And checking if it got cancelled:
And you can have your own private EventBus too for specific needs:
Impact on other code: Exactly zero - it doesn't modify any existing class. This is meant to ease further development (in particular of the planetary and stellar events, but anywhere you need an event you can use it), and possibly moved whole into MegaMek if it is deemed a suitable replacement or enhancement of the existing systems there.