Author Topic: Another look at Geoscape AI.  (Read 16751 times)

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Another look at Geoscape AI.
« on: October 29, 2012, 10:26:06 pm »
I am trying to implement a new (event-based) system for the Geoscape AI.

The basic idea is to have a central GeoscapeAI object living attached to (pointer owned by) GeoscapeState.
Every "interesting" event in the Geoscape will post an event to the AI, which will decide what to do with it.

So far I have an AI that takes 5 files to just do the same random time-based spawning as the current code! But what I did for the long runis turn each event handler into a virtual function call on the AI, with the event as an argument. So it's very easy to add new events, just detecting them and posting them when they happen, then letting the AI take care of the details.

I will keep moving functionality from GeoscapeState into GeoscapeAI, by adding new event types and their (default) handlers. Eventually I plan to have different GeoscapeAI implementations, for the different difficulties.

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #1 on: October 29, 2012, 10:36:03 pm »
Here is the current state of things:
  • One event is generated every 30 game minutes.
  • I am still using the time-based random chance code that was in GeoscapeState for UFO spawns and Terror sites.

In the immediate (near) future I will implement events and keep current behaviour for the following:
  • Detect total destruction of UFOs.
  • Detect crash landing of UFOs.
  • Detect expiration of mission sites.
  • Detect XCOM winning / losing a mission.
  • Detect arrival of UFOs to destination.

The code is live, compiles and does not crash (minimal testing) on my 'devel' branch in GitHub. Comments in either place are more than welcome.
« Last Edit: October 29, 2012, 11:29:36 pm by karvanit »

Offline darkestaxe

  • Colonel
  • ****
  • Posts: 254
  • Emissary of the Brain
    • View Profile
Re: Another look at Geoscape AI.
« Reply #2 on: October 30, 2012, 09:03:13 pm »
Disclaimer:I probably don't understand what you're doing very well but if I understand this correctly.

that said

In the immediate (near) future I will implement events and keep current behaviour for the following:
  • Detect total destruction of UFOs.
  • Detect crash landing of UFOs.
  • Detect expiration of mission sites.
  • Detect XCOM winning / losing a mission.
  • Detect arrival of UFOs to destination.

I think modders wanting an event based AI would want events for things like xcom bases being built, ufo's being detected by xcom, ufo's being engaged by xcom craft, bases being detected (x-com or alien), research/manufacture completion, funding changes, etc.

examples:
  • Mod adds a type of artifact site mission for the aliens that the aliens only launch after x-com researches a pre-requisite.
  • Mod causes supply missions to spawn from north pole instead of south pole when an x-com base is created in Antarctica and x-com has less then 4 bases.
  • Mod causes battleships on 'alien research' missions to land next too an x-com base for 48 hours every time x-coms balance goes negative at the beginning of the month.
  • Mod causes a new terror mission to be launched every other time X-COMs funding increases at the end of a month, but with a battle-ship instead of a terrorship.
  • Mod causes all infiltration missions to take place in regions where x-com has a base (xcom has built more bases then x-com has lost).


I'm not saying anyone would actually do those exact things with a mod, but I would expect modders to want to use geoscape events other then attacks on aliens, even though a true alien AI would only need to react to things that the aliens should know about.
« Last Edit: October 30, 2012, 09:05:31 pm by darkestaxe »

Offline luke83

  • Commander
  • *****
  • Posts: 1558
    • View Profile
    • openxcommods
Re: Another look at Geoscape AI.
« Reply #3 on: October 31, 2012, 07:11:19 am »
I am watching this topic with great interest as i would love to be able to specify new mission types to be spawned at schedules that suit me, you build what you think is right and then i will ask nicely for what i think is missing :P

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #4 on: October 31, 2012, 07:23:42 am »
That is the idea, everything that happens on Geoscape also triggers an event.
I'm simply starting with existing things, to make transition smoother.

Offline michal

  • Commander
  • *****
  • Posts: 629
    • View Profile
Re: Another look at Geoscape AI.
« Reply #5 on: October 31, 2012, 08:46:41 am »
I hope SupSuper will release 0.4.5 soon, and then we will see your changes in main branch ;)

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Another look at Geoscape AI.
« Reply #6 on: November 02, 2012, 01:55:32 pm »
i'm gonna merge your geoscape ai with my branch tomorrow and see how it goes.
in the meantime, since you're developing the geoscape, may i submit my efforts for your approval?
things i've done that may be of interest to you:
- psychic training menu - working like vanilla (i think?)
- live alien capture and research - haven't done "bonus" topics for ranked aliens yet, but works to an extent
- ufopedia - working like vanilla (sort of) still needs some fixing.
- alien bases - working like vanilla, except the trigger that spawns them (need battlescape AI for this)

or should i fork it and do it that way?
« Last Edit: November 02, 2012, 02:05:49 pm by Warboy1982 »

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #7 on: November 02, 2012, 06:48:10 pm »
I am setting up the ruleset right now, the code in GitHub will compile but won't really do anything different.
I had planned to implement the alien missions in the following order:
  • Research
  • Harvest: once Research type is done, this is just more ruleset data.
  • Abduct: once Research type is done, this is just more ruleset data.
  • Terror
  • Base
  • Supply
  • Retaliation
  • Inflitration

So I will try to pull in your alien base parts after I finish Terror missions.
Working in a single feature at a time makes for cleaner merges and better pull requests, so I don't want to clutter my development branch with stuff that should rightfully be different features. I'll get the rest after they go upstream.

You are of cource free to fork, but I don't think it's worth it right now.

PS: Isn't Ufopedia working already fine in upstream?
PS2: Could you prepare a branch with your alien base changes only? Branching either from upstream or my devel branch is fine.

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #8 on: November 05, 2012, 02:03:54 pm »
I am doing a much better / cleaner reimplementation so expect my devel branch to become reset and lose history!

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Another look at Geoscape AI.
« Reply #9 on: November 06, 2012, 08:15:58 am »
aw dangit, and i literally JUST finished getting it all in :(
gonna fork your project later today and add bases if i can figure out how github works.

Offline Fenyő

  • Colonel
  • ****
  • Posts: 423
    • View Profile
Re: Another look at Geoscape AI.
« Reply #10 on: November 06, 2012, 10:13:53 pm »
...if i can figure out how github works.
It is possible it will take several hours. :)
(and not because of your abilities :) )

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #11 on: November 07, 2012, 03:04:57 am »
Real-Life(tm) has caught up with me, the rewrite may take some time,
Until I do get back on it, here is a sample of the rules for missions, to get your comments / suggestions (numbers are fake) (numbered lists are sequences, unordered lists are maps):
  • mission: STR_ALIEN_RESEARCH
  • races:
      • afterMonth; 0
      • racChance:
        • STR_SECTOID: 60
        • STR_SNAKEMAN: 10
        • STR_FLOATER: 30
    • chances for next period
  • waves:
      • ufo: STR_SMALL_SCOUT
      • minTime: 120
      • maxTime: 240
      • flightPattern: [ 0 0 0 1 0 0 1 ]
    • next wave
Flightpattern is a sequence of numbers, to be interpreted by the mission object (0 = waypoint, 1 = land for now).
« Last Edit: November 07, 2012, 08:47:03 am by karvanit »

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #12 on: November 07, 2012, 08:36:48 am »
The proper event skeleton is now under the (rewritten) devel branch on my GitHub. It's going to have a stable history from now on, sorry for any inconvenience.
(Still working on the AI stuff.)

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Another look at Geoscape AI.
« Reply #13 on: November 07, 2012, 09:18:14 am »
how about something like this:
Code: [Select]
  - type: STR_ALIEN_BASE
    scoutList:
      - STR_SMALL_SCOUT
      - STR_MEDIUM_SCOUT
      - STR_LARGE_SCOUT
      - STR_BATTLESHIP
    minScouts: 1
    maxScouts: 3
    minScoutTime: 120
    maxScoutTime: 240
    scoutFlightPattern: [ 0 0 0 1 0 0 1 ]
    missionShip:
      - STR_BATTLESHIP
    minMissionTime: 80
    maxMissionTime: 300
    missionFlightPattern: [ 0 1 2 0 ]
    spawnOnComplete: STR_ALIEN_BASE
    points: 100
    month1:
      STR_SECTOID: 30
      STR_SNAKEMAN: 20
      STR_MUTON: 0
      STR_ETHEREAL: 0
      STR_FLOATER: 50
    month2:
      etc.

i could probably have all that being read from the YML in usable format by later tonight if you'd like?
quick explanation:
scoutlist: the alien AI should keep track of how mad it is at the player, the more mad, the bigger the scout.
flight pattern: 2 is "mission complete" - spawn the event in the spawnOnComplete field (ie terror site or alien base) and apply points to the alien activity score.
the rest should explain itself.
« Last Edit: November 07, 2012, 09:21:11 am by Warboy1982 »

Offline karvanit

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Another look at Geoscape AI.
« Reply #14 on: November 07, 2012, 11:16:30 am »
I was reading the mission info from https://ufopaedia.org. My understanding is that no actual escalation of scouts is happening, you just move back the time of the next spawn. Could you (or anyone interested really) check at https://ufopaedia.org and get  a more definite answer?

My way of storing the race choices for each mission allows changing at different intervals, not just fixed. Easier to extend.

I like you idea of '3' meaning 'mission complete, do whatever the spawnOnComplete says'. It's easier to extend than my idea.

Another question: Are the waypoints in vanilla in the same region as the mission or all around the map? Or any other pattern?