Author Topic: Coding project: Battle of the Blight  (Read 3810 times)

Offline onehand

  • Newbie
  • *
  • Posts: 19
Coding project: Battle of the Blight
« on: April 23, 2015, 02:09:37 AM »
I'm working on a LoS 4P mission, but I'm getting stuck in a few places coding-wise. In this mission no traditional weapons are used as both teams are separated by a mountain range. Instead of using direct weapons, players must "push" the blight back on the other team's side by placing Light Towers at strategic locations. The Light Towers will essentially repel the blight away from one's base and back in the opposite direction. I already have a proof of concept of this somewhat working committed to the SVN here:
/outpost2/LevelsAndMods/trunk/Levels/Battle of the Blight/



The code relies heavily on Arklon's CCF2 Alpha code (BlightHook) and patching functions.

What works:
- By making some tweaks to the overridden InfectAreaNear() member function, the blight will maintain 6 tile distance from any Light Tower. Later on I'd like to add some additional logic to override that condition if the opposing team has X more Light Towers on their side in the same y coordinate, meaning their resistance to the blight overpowers the other team's.

What doesn't work:
- I would like to remove or tweak some extra modifications made in BlightHook; particularly the ability to allow units to survive in the blight for ~5 marks, primarily because this doesn't seem to be working properly in my build. (Maybe I'm not calling all the hooks properly?) :) Units exposed to the blight stay alive indefinitely.  I tried commenting out some of the other member function patches, but that seemed to stop the blight from spawning altogether. I then tried to cobble together my own patching function from the ground up to solely patch the InfectAreaNear() function, but that also seemed to also stop the blight completely.

I removed my patching method and went back to Arklon's code, nearly all of which is still intact, but I renamed BlightHook to BlightHookBotB just to distinguish from the original. I've also placed comments on where I've added code there. The blight will still infect structures, but vehicles seem to be unaffected. After looking at this for a while now, I'm pretty stuck.

If you're interested, here's some short back story I wrote up for your reading pleasure:
Quote
   We've discovered a way to ward off the expansion of the Blight. New Terra is more or less a living, breathing organism and as it turns out, the Blight was triggered by the introduction of the various electromagnetic fields our colonies and structures have produced.  By offsetting these fields with fields of inverse polarity, the Blight will dissipate and move back in the opposite direction.
   We've retrofitted our Light Towers with electromagnetic field generators.  By placing a number of these Light Towers in a given area, we can be sure the Blight won't encroach there. The problem is, splinter factions have stolen our research plans for these devices and are making field generator variants of their own at this very moment.  We've come to know they will push the Blight back in our direction in an attempt to save their own bases, or merely in an act of retribution. As such, we've also added a component to our Light Towers which will disable enemy towers a fair distance away.
   Our communications satellite is down and we are now separated from the splinter colonies by a vast mountain range, so any land-to-land interactions or combat are no longer possible.  Our only hope is to produce a large enough electromagnetic field to push the Blight back in their direction away from us. Good luck.

Download
ml4_bob.dll
BotB-1.map
« Last Edit: April 26, 2015, 11:13:39 AM by onehand »

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6253
    • http://www.outpost2.net/~ck9
Re: Coding project: Battle of the Blight
« Reply #1 on: April 23, 2015, 06:39:47 AM »
Haven't worked with coding missions before, but I had a few thoughts with this that may or may not help you.

Have you thought about looking at how the "base code" (or rather, what we can assume of what it is) makes the blight react to sunlight (if there are functions within what has been cobbled together to deal with that)?  My thought here is that the number of light towers could potentially be used in the same way with a modified form of the function.

For units exposed to the blight, I think you will need to call to a function that deal with unit self-destruct, of course modifying it to add in your desired delay.


Now watch either ark or bomber come along and tell me that I am wrong because we do not have access to the functions I am thinking of :p
CK9 in outpost
Iamck in runescape (yes, I still play...sometimes...)
srentiln in minecraft (I like legos, and I like computer games...it was only a matter of time...) and youtube...
xdarkinsidex on deviantart

yup, I have too many screen names

Offline onehand

  • Newbie
  • *
  • Posts: 19
Re: Coding project: Battle of the Blight
« Reply #2 on: April 23, 2015, 09:28:09 AM »
Well, the blight spread itself works perfectly right now, it just doesn't kill any units.  But yeah I was wondering about that.  For instance, if I patch one member function in the Blight vtbl (in this case InfectAreaNear()), do I also then have to patch all of the related member functions (ex. SpreadTo(), SetBlight(), SetSpreadSpeed(), etc.) in order for the blight to function properly? Or can it still use the OP2 defaults for those? It seems like it doesn't like me patching just the one.

Also the BlightHook code was calling a function DoInfect(Unit) from InfectAreaNear() so I'm wondering if maybe that DoInfect function needs some tweaking to always call Unit.DoDeath() when a unit is detected in a microbe tile. In this case, I don't want any delay (just the default blight behavior in terms of the damage it does).

Although, Arklon's original descriptions of CCF2a regarding how infected units can be eventually transferred to the AI and then start attacking you did sound pretty cool, but since on this map there's no real need to have weaponized units, I'm just trying to see if I can get the default blight damage working.
« Last Edit: April 23, 2015, 02:28:40 PM by onehand »

Offline onehand

  • Newbie
  • *
  • Posts: 19
Re: Coding project: Battle of the Blight
« Reply #3 on: April 23, 2015, 07:58:47 PM »
Ok, I got the units to be destroyed upon infection by adding some code in AIProc() to always check whether a given unit is on a microbe tile. I didn't add this to InfectAreaNear() as units would only be destroyed when the blight approached them, i.e. you could safely drive into the blight if it wasn't expanding towards you. I cleaned up the BlightHookBotB code a bit too and committed the changes.

Now on to more Light Tower logic

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4566
Re: Coding project: Battle of the Blight
« Reply #4 on: April 23, 2015, 08:55:56 PM »
Neat.

Why do you want units to be able to drive through the blight without being destroyed right away? Do you want the game to remember units are infected after touching the blight, or do you want it possible to drive in and back out quickly and safely?

If you're replacing the function pointer in a virtual function table (most likely), then the other functions will continue to use the default implementation. If you're replacing the pointer to the virtual function table itself (less likely), then the new table needs to have pointers to all needed functions. They can certainly just point to the original functions as a default without issue.

To replace the pointer to the virtual function table, you'll need an appropriate replacement table of the correct size, which means knowing how many virtual functions exist. You can copy the old table into a new table, and replace the pointer for the function you're overriding. A more advanced way, is to declare a subclass of the exiting class (or a reverse engineered description of it), and only override the method you want to replace. This will cause the compiler to generate a new virtual function table. The compiler would need to know how to fill in all the entries though, which either means some trickery to get it to somehow recognize an existing virtual function table (or make it think it does), or replacing all the functions so it doesn't need to know the address of the original functions.

Offline onehand

  • Newbie
  • *
  • Posts: 19
Re: Coding project: Battle of the Blight
« Reply #5 on: April 26, 2015, 10:47:17 AM »
From the BlightHook code it seemed like just the function pointer was getting replaced and not the virtual function table itself, but previous testing I did seemed to indicate otherwise. However, the blight damage is now working after making that call to microbe the unit in AIProc().

Also, I now have the Light Tower logic essentially done and I think the map is ready for some play testing.  :)  Here's what the map terrain looks like:



It's a modified version of Allied Siege.

And here's an example on how Light Towers can "battle":




While a tower is active, it will maintain a microbe-free area around it with a radius of 8 tiles. Blue lost the leftmost tower because green had 3 towers within range of it. By stacking Light Towers, you can effectively disable an enemy light tower up to 56 y-coordinate tiles away (roughly half the map). You only need at least one more tower in your grouping than the enemy has within that range to disable theirs. Light Towers can be grouped horizontally too (ex. Blue's 2 towers on the right) but they must be adjacent (within 2 x-coordinate tiles).  Towers grouped vertically do not need to be within 2 y-coordinate tiles of each other; they only need to be within the 56 vertical tile range of the target tower. If both players have only 1 tower each (or the same number of towers) within range of each other, neither tower gets infected/disabled.

Given the range of 56 tiles, if you wanted to disable towers around an enemy's base (which will generally be near the top or bottom map edges) you would need to place your towers closer to the center mountain range since the map is 128 tiles in height.  Although, this means that your towers along the mountainside can also be targeted by towers from an enemy base!

You can also eradicate or "push back" the blight from tiles where it has already spread by placing a tower near the blight edge, but you must have daylight for the microbes to dissipate.

I suppose the game could end in a stalemate if all players only built towers around their immediate bases, but that'd be no fun right? :)  I'm also wondering whether all players could completely stop the blight...  Peace on New Terra?

The 4P teamplay is Top vs. Bottom (and you can also play it with two players).  If you want to give it a try, I've attached the DLL and .map file to the 1st post on this thread.  I've also committed the latest version of the code to the SVN if you want to check that out. The blight is triggered at mark 100 and spawns near the center of the map.

EDIT: Added a feature where if your tower(s) are currently overpowered/disabled by enemy towers, they will be in the "Disabled" status in the command pane. Much easier to anticipate where the blight might encroach and where you need additional tower stacking. The DLL above is updated.
« Last Edit: April 28, 2015, 03:42:09 PM by onehand »

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 392
Re: Coding project: Battle of the Blight
« Reply #6 on: April 28, 2015, 01:31:28 PM »
You had my attention when you said "Light Towers"

I like the general idea of the map, and the modifications seem to be very in-depth, good work.
Praise the mighty light towers!!!

Offline onehand

  • Newbie
  • *
  • Posts: 19
Re: Coding project: Battle of the Blight
« Reply #7 on: April 28, 2015, 02:06:28 PM »
Thanks! I was hoping you would see it Flashy. ;D

Now I want to play it with some folks although I've been having trouble hosting lately due to port visibility issues with my ISP.

Offline Leviathan

  • Hero Member
  • *****
  • Posts: 4112
Re: Coding project: Battle of the Blight
« Reply #8 on: May 20, 2015, 06:01:52 PM »
Very good sir! Great to see people working on projects. I will be on IRC to test it with ya :)

Offline Drakmar

  • Sr. Member
  • ****
  • Posts: 251
Re: Coding project: Battle of the Blight
« Reply #9 on: June 26, 2015, 06:35:05 PM »
Looks interesting!

Offline Vagabond

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 744
Re: Coding project: Battle of the Blight
« Reply #10 on: January 29, 2018, 10:49:27 PM »
I played a 2 player round with this scenario.

Everything seemed to work right. I like that the light towers flash disabled when they are overpowered by their opponents. No bugs noticed.

Exploring the new mechanic was initially fun, but the game languished after that. We each kept building light towers to counter the opponent. While we could disable some, since the blight will not enter the lighted area, neighboring light towers would protect the disabled ones allowing time to shore up that section. So it appeared to be a stalemate that we eventually just ended mutually.

I guess some interesting mechanics could happen end game when you have maxed out your buildings and how you handle stuffing large numbers of convecs with light towers before going over the limit. But we didn't play that far.

Thanks for making it.

-Brett