Author Topic: Getting The Ai To Build Mines  (Read 7296 times)

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« on: May 06, 2010, 10:23:46 AM »
I want my AI to build a second colony with mines, smelters and working mining groups.
But somehow my code causes the game to crash instantly after starting the dll:
Code: [Select]
BuildMines = CreateBuildingGroup(Player[1]);
MAP_RECT MinerBox(63+31, 54-1, 67+31, 58-1);
BuildMines.SetRect(MinerBox);
BuildMines.TakeUnit(Miner);
BuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
BuildMines.RecordBuilding(LOCATION(61+31, 61-1), mapCommonOreMine, mapNone);
If there's already a mine, it works.
Code: [Select]
RebuildMines = CreateBuildingGroup(Player[1]);
MAP_RECT MinerBox(63+31, 54-1, 67+31, 58-1);
RebuildMines.SetRect(MinerBox);
RebuildMines.TakeUnit(Miner);
RebuildMines.TakeUnit(COMine);
RebuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
RebuildMines.SetTargCount(mapCommonOreMine, mapNone, 1);

RebuildMines.RecordBuilding(LOCATION(61+31, 61-1), mapCommonOreMine, mapNone);
But I don't want to create all AI mines at the beginning of the game.
« Last Edit: May 06, 2010, 10:26:23 AM by Flashy »
Praise the mighty light towers!!!

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Getting The Ai To Build Mines
« Reply #1 on: May 06, 2010, 10:44:31 AM »
I know I'm not the one to respond, and this might be a very stupid idea, but have you tried using the rebuild code to get the initial build working?  I know that sometimes in PHP, I can't get an initiation function to work but the loop check that is supposed to depend on it works without it (as if it had been successful).  Maybe the same concept will work?
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 Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #2 on: May 06, 2010, 12:54:34 PM »
Add this line to the first one and tell me if it works:
Code: [Select]
RebuildMines.SetTargCount(mapCommonOreMine, mapNone, 1);
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #3 on: May 06, 2010, 01:22:09 PM »
It still crashes.
Praise the mighty light towers!!!

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Getting The Ai To Build Mines
« Reply #4 on: May 06, 2010, 01:27:09 PM »
Comment out everything from that part you know causes the crash and add it back one instruction at a time.

Using this procedure, locate which instructions/ lines cause the crash exactly.
« Last Edit: May 06, 2010, 01:27:32 PM by Hidiot »
"Nothing from nowhere, I'm no one at all"

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #5 on: May 06, 2010, 03:39:52 PM »
Err, hang on...

You aren't also creating a Mining Group to mine ore from the mine that doesn't exist yet, are you?

Also make sure that after the mine is constructed, you find it and assign it as COMine before telling a mining group to mine from COMine.  OP2 really doesn't like it when you tell it to use units that don't exist.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Getting The Ai To Build Mines
« Reply #6 on: May 07, 2010, 01:05:17 AM »
If it crashes, post a crash address. If I know what instruction it crashes at, I can check to see why. It'll either be listed as an instruction address, or perhaps the value of EIP in a detailed crash report.


Also, I assume there is other code in your project. Are you sure this is the code that is causing the crash?
 

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #7 on: May 07, 2010, 11:09:11 AM »
that's strange. I've created mines at the beginning, but it still crashes untill i delete the rebuildmines code.
Praise the mighty light towers!!!

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #8 on: May 07, 2010, 12:24:31 PM »
Yeah, just post all your code...
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #9 on: May 07, 2010, 01:28:20 PM »
Got it to work! But don't ask me how...
Praise the mighty light towers!!!

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #10 on: May 07, 2010, 02:40:47 PM »
How?  No, I'm not joking.  Other people may want/need to know in the future.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #11 on: May 07, 2010, 03:10:02 PM »
I had to create the mines. But this is good because it helps to prevent the player from building on AI mine beacons.
Praise the mighty light towers!!!

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Getting The Ai To Build Mines
« Reply #12 on: May 07, 2010, 03:23:36 PM »
so your saying if i kill my enemy off i cant take there base because there are no usable mines? that makes no sense.
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Getting The Ai To Build Mines
« Reply #13 on: May 07, 2010, 03:34:32 PM »
that's not what he's saying at all...how the hell do you get that from what he said?

When the game starts, the coding automatically has the AI mines in place on those beacons rather than trying to get the AI to build mines on those spots becase the code kept failing for doing that.
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 evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Getting The Ai To Build Mines
« Reply #14 on: May 07, 2010, 04:04:21 PM »
i should shut up now (lol i never shut up) but sense you asked he said
Quote
   I had to create the mines. But this is good because it helps to prevent the player from building on AI mine beacons.
that is where i got
Quote
so your saying if i kill my enemy off i cant take there base because there are no usable mines? that makes no sense.
Now do you see my understanding?
« Last Edit: May 07, 2010, 04:05:20 PM by evecolonycamander »
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #15 on: May 07, 2010, 04:20:25 PM »
Quote
I had to create the mines. But this is good because it helps to prevent the player from building on AI mine beacons.
Uhh, that's... not really a solution so much as giving up...
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Getting The Ai To Build Mines
« Reply #16 on: May 07, 2010, 04:33:27 PM »
now that im not the only one who sees the isue
other then my poor internet grammar and spelling. isue is spelled wrong isn't it
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #17 on: May 07, 2010, 06:11:23 PM »
Off-topic, but yes.  Issue.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline CK9

  • Administrator
  • Hero Member
  • *****
  • Posts: 6226
    • http://www.outpost2.net/~ck9
Getting The Ai To Build Mines
« Reply #18 on: May 07, 2010, 08:03:41 PM »
it is giving up, but it is one way to solve a coding error.

If I took the time to code an ai, I would make it just desstroy any player mining sites that were built on designated ai build sites even if it took me a year to do it right
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 Sirbomber

  • Hero Member
  • *****
  • Posts: 3238
Getting The Ai To Build Mines
« Reply #19 on: May 07, 2010, 10:19:26 PM »
That'd be the way to do it CK9.  Blindly assuming the game will be set up exactly the way your AI needs it to be is kinda dumb, especially when dealing with an unpredictable human player.
"As usual, colonist opinion is split between those who think the plague is a good idea, and those who are dying from it." - Outpost Evening Star

Outpost 2 Coding 101 Tutorials

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #20 on: May 08, 2010, 06:12:50 AM »
I think I found a way without creating the mines, and im currently testing it.

EDIT: Yes, it works.
« Last Edit: May 08, 2010, 06:45:23 AM by Flashy »
Praise the mighty light towers!!!

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Getting The Ai To Build Mines
« Reply #21 on: May 08, 2010, 07:30:24 AM »
can you post code? im a new person when it comes to coding and need all the help i can get.
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline Flashy

  • Sr. Member
  • ****
  • Posts: 391
Getting The Ai To Build Mines
« Reply #22 on: May 08, 2010, 07:44:57 AM »
This is my solution
// Above initproc
Code: [Select]
BuildingGroup Colony2RebuildMines;
int MiningGroupEstablished = 0;
IUnit Colony2CommonOreSmelter;
IUnit Colony2CommonOreMine;
MAP_RECT Colony2MiningBox(259-1, 174-1, 263-1, 178-1);
MAP_RECT Colony2MinerBox(257-1, 182-1, 261-1, 186-1);
In initproc
Code: [Select]
Colony2RebuildMines = CreateBuildingGroup(Player[numAI]);
Colony2RebuildMines.SetRect(Colony2MinerBox);
Colony2RebuildMines.SetTargCount(mapRoboMiner, mapNone, 1);
Colony2RebuildMines.SetTargCount(mapCommonOreMine, mapNone, 1);
Colony2RebuildMines.RecordBuilding(LOCATION(266-1,  180-1), mapCommonOreMine, mapNone);
in aiproc
Code: [Select]
    //Find common smelter if it was built
if(MiningGroupsEstablished == 0)
{
    if(Colony2CommonOreSmelter.IsLive() == 0)
    {
IUnit NewCommonSmelter;
     InRectEnumerator Rectenum437(MAP_RECT(259-1, 178-1, 264-1, 182-1));
     //Search the area near the common smelter for a new one
        if(Rectenum437.GetNext(NewCommonSmelter) == 1)
        {
            if(NewCommonSmelter.GetType() == mapCommonOreSmelter)
            {
             switch(NewCommonSmelter.GetBusy())
                {
                    case ctMoDevelop:
                    case ctMoUnDevelop:
                    case ctMoDismantle:
                        break;
                    default://If it's not being built, or destroyed, take it
                        Colony2CommonOreSmelter = NewCommonSmelter;
                        break;
                }
                    
            }
        }
}
}


    //Find common mine if it was built
if(MiningGroupsEstablished == 0)
{
    if(Colony2CommonOreMine.IsLive() == 0)
    {
IUnit NewCommonMine;
     InRectEnumerator Rectenum439(MAP_RECT(264-1, 179-1, 267-1, 181-1));
     //Search the area near the common mine
        if(Rectenum439.GetNext(NewCommonMine) == 1)
        {
            if(NewCommonMine.GetType() == mapCommonOreMine)
            {
             switch(NewCommonMine.GetBusy())
                {
                    case ctMoDevelop:
                    case ctMoUnDevelop:
                    case ctMoDismantle:
                        break;
                    default://If it's not being built, or destroyed, take it
                        Colony2CommonOreMine = NewCommonMine;
                        break;
                }
                    
            }
        }
}
}

// Initialize mining group
if((MiningGroupsEstablished == 0) && (Colony2CommonOreSmelter.IsLive() == 1) && (Colony2CommonOreMine.IsLive() == 1))
{
Colony2CommonMining.Setup(Colony2CommonOreMine, Colony2CommonOreSmelter, Colony2MiningBox);
Colony2CommonMining.SetTargCount(mapCargoTruck, mapNone, 3);
Colony2RebuildMines.TakeUnit(Colony2CommonOreMine);
MiningGroupsEstablished = 1; // This will prevent the code from creating possible loops with odd results
}
Did I forget something?
« Last Edit: May 08, 2010, 07:49:55 AM by Flashy »
Praise the mighty light towers!!!

Offline evecolonycamander

  • Hero Member
  • *****
  • Posts: 602
Getting The Ai To Build Mines
« Reply #23 on: May 08, 2010, 10:39:28 PM »
okey once i under stand this ill get back to you on this... untill then some one edited my last post with out leaving a tag. it had originally said
Quote
   can you post code? im a new person when it comes to coding and need all the help i can get.
and now if you look at it new person was changed. the only way that i can think of it being one is by deleting the post and re-posting it as me. sorry  i know this is way of topic and all but ive seen another member complain about it. and no one care or beleaved him(not even me)

sorry the spelling and grammer is bad but spellcheck an the d butten arnt acting proper
''The blight cant get us up here!''
-famous last words
--------------o0o--------------
Outpost 2: EoM project status: Re-planning

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Getting The Ai To Build Mines
« Reply #24 on: May 08, 2010, 10:42:11 PM »
Perhaps you simply activated the bad word replace filter. The thing that *'s out certain letters in bad words can be used to completely replace words. As in "new person". :P