Science fiction has it all wrong… AI does not become self aware, some programmer makes two (self proclaimed) improvements to an existing AI and when they clash all humans die!
I made 2 functions I was proud of.
The FIRST finds AI enemy SOB groups with a battle cruiser that is all alone and sends out a small frigate support force to help protect and a collector to start repairing it.
The SECOND was a way to add a little harassment to the human player BEFORE I released the AI to do its own attacks. As the shipyard made units I could not figure out how to automatically add those made units to a SOBgroup that I could control. I know they are in the PlayerShips0 but I wanted just the few bombers that came out to be in their own group so I could send them on a scripted mission outside of the AI’s control. What I thought was an ingenious way to do it was to select all units within 5000 radius of the shipyard and place into their own SOB group and then send that to attack the human player’s carrier (in this mission that is = to their MotherShip).
I knew it would also get other ships near by but chalked that up to some randomness which was welcomed.
Well, in the mission map there is an on going battle between an Ally AI and the enemy AI that does not endanger the human player… so I thought.
The two functions just happen to cross paths with each other and the result was:
An AI enemy’s force just came out ahead of the Ally AI force(unbeknownst to me in a galaxy far far away) and had 1 Vaygr BC alive. Support function kicks in and the shipyard creates 4 frigates and a collector and adds to the AI enemy’s SOB Group(which is still invulnerable because the human player has not “discovered” it yet).
Then the Harass Player function makes 2 bombers and selects all units within 5000 radius… whoops the 4 invulnerable frigates get put into another SOBGroup that is scheduled to attack the human player.
60 seconds later 4 frigates show up and defeat 3 battle cruisers, 4 destroyers, and then kill the human player.
In my 100’s of play throughs I never ran into this because the BC that was all alone is close to me and I “discovered” it sooner than my player did which ran the function to turn it on… aka made it’s SOB Group vulnerable and ready for human combat.
This would have been a beast to find, but luckily my player was savvy enough to send me some screen shots and I found it quicker.
QUESTIONS for the Programmers out there:
What is a good way to add newly created units to a special SOB group to control via script? I think I came up with another way just now but have not tested it. I believe if I wanted sequential waves of units I could just create in the LEVEL file 1 SOBGroup and make it deploy from the shipyard and do something and when it dies, reuse the same SOBGroup again… in lieu of actually telling the shipyard to make the units and trying to select them via proximity function.
Is there a way in game to select an AI unit and log the SOBGROUPs it belongs to, to the log?
In my limited knowledge of LUA I often use the “Rule_AddInterval ( “x”, 120 )” not only to repeat a function but ALSO as a sort of timer to run a function after a certain amount of seconds has past (120 seconds in the ex.above) and then I remove the function. Is this okay for HWRM? Or is it inefficiency in some way I am not aware?
Also about the “Rule_AddInterval” function. There are times I need to run something periodically to check on things to see if I need to adjust. I do not necessarily need to do it at an interval but thought that maybe using the “AddInterval” versus “Rule_Add” might be more friendly to the processor so the function does not actually try to run as often. Is it? I know the AddInterval has to check itself as often but the code inside does not need to run was my thought.
Lastly, Several times I got into a timing issue where one SobGroup_* function was not done running before the next line, another SobGroup_* function, was being processed and the next function ran before I was ready for it to. Is there some mechanism in LUA to make sure a line is finished before it runs another? I felt very inefficient constantly using AddInterval just to buy some time to make sure the next function ran 3-5 seconds later and then removing the AddIntercal function.