or state machine
In the original version of rEV, the Confed Fighter Bay system was supposed to let you hold either 3 Patrol Ships or 2 Gunboats per bay expansion. This didn't work. In the course of working out the multiple fighter types methods I decided to sit down and think about this problem too. It needs a mod-3 counter for the Patrol Ships and a mod-2 counter for the Gunboats. A mod-2 counter is trivial: 1 ncb which you toggle every time you buy or sell a gunboat. The mod-3 counter is the tricky bit - the counting system must be actively working within the outfitter, so while crons could probably do the job easily enough they would not be suitable because you would have to keep advancing the date every time you buy or sell a fighter just to make them fire. But I decided it ought to be possible using some system of aborting missions as conditionals. It took me a surprisingly long time to see this solution, which I have implemented in the latest rEV beta.
Mission 1: Cycle
OnAbort: A4 A3 A2 A5
(Self-aborting. This mission is just a shortcut to cycle the counter.)
Mission 2: State 0
OnAbort: S3
Mission 3: State 1
OnAbort: S4
Mission 4: State 2
OnAbort: S5
Mission 5: Wrap
OnAbort: S2
Mission 2 will be started when you start the game, so you begin in state 0. Whenever you want to increment the counter (buy a Patrol Ship) you start Mission 1, which will abort all the other missions (to decrement just cycle it twice). The aborting has to be done in a particular order to ensure that it only increments by 1 state.
When you're in State 0: Missions 4 and 3 aren't active so nothing happens with these. Mission 2 gets aborted next which starts Mission 3, putting you into State 1. Nothing happens with mission 5 either.
When you're in State 1: Similar thing happens and we end up in State 2.
When you're in State 2: Mission 4 gets aborted which starts Mission 5. Missions 3 and 2 aren't active so nothing happens with these. Finally mission 5 gets aborted, which was just started, and this now starts mission 2 which puts us back into State 0.
This is all well and good and I set a bit to indicate which state we're in and use this to control purchasing of fighters. If you start filling a bay with one type of fighter, you can't purchase any of the other type until you fill the first bay (more or less). But it could be better. What I'd like to do is grant an outfit with each complete cycle of the counter to keep track of how many bays are in use vs how many are empty. Easy enough to grant the outfit when moving from State 0 to State 1, but we also need to be able to remove it somehow. Make a distinction between cycling forwards and cycling backwards. Since my brain already hurts from thinking about all this too much I thought I best put it out to the Dev Corner to see if some other smart person can work out a solution
(This is completely unrelated but I also made a weird discovery: AI fighters with mass >=200 will not attack until the parent's shields drop below 2/3rds)
(UPDATE)
Not sure how I missed this, but it turns out the solution to keeping track of bays is actually trivial:
First grant the outfit (a bay token) whenever moving from State 0 to State 1 (State 0's OnAbort).
Then remove the outfit whenever you decrement the counter (sell a Patrol Ship).
That's it!
Because decrementing works by cycling the counter twice, whenever you decrement from State 0 to State 2, or from State 2 to State 1, the counter has to leave State 0 at some point along the way. The outfit will be added and subsequently removed, resulting in no change. Only when you decrement from State 1 to State 0 will the outfit actually be removed (the bay is now empty so we return the token).
This not only allows the purchasing/selling system to be smoother (see Qaanol's scenario below) but it also opens the door for allowing fighters to be captured. I've updated the Multiple Ammo Types topic with a new Method 3 which explains this.
This post has been edited by Guy : 06 May 2014 - 02:03 AM