Outpost Universe Forums

Projects & Development => Outpost 2 Programming & Development => Topic started by: spirit1flyer on November 23, 2005, 01:27:22 PM

Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 23, 2005, 01:27:22 PM
I am trying some code that hacker posted some time back but for some odd reason my AI units just head to the top corner. I tried changing
Code: [Select]
fighters.AddGuardedRect(MAP_RECT(99,99,99,99)); 

to another place but it does not change a thing?
here is the code
Code: [Select]
Unit VF;
TethysGame::CreateUnit(VF, mapVehicleFactory, LOCATION(57,22), 1, mapNone, 0); FightGroup fighters = CreateFightGroup(Player[1]);
BuildingGroup producer = CreateBuildingGroup(Player[1]);
producer.TakeUnit(VF); producer.RecordVehReinforceGroup(fighters, 0); fighters.SetTargCount(mapLynx, mapMicrowave, 2);
fighters.AddGuardedRect(MAP_RECT(99,99,99,99));
fighters.DoGuardRect(); // guard
Title: Units Want To Go Off The Map?
Post by: Mcshay on November 23, 2005, 03:21:10 PM
I'm guessing it is looking for a square, and not a point? (make it 99,99,100,100 instead).
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 23, 2005, 03:37:10 PM
I tried that, they still headed to the corner.   I even tried making all the numbers negative but it did not work, they still headed to the top left corner.
Title: Units Want To Go Off The Map?
Post by: Hooman on November 23, 2005, 04:26:31 PM
I know a lot of the groups need to have a rect set or that will happen. Have you tried SetRect?

The units will go there when they have nothing to do. Like if a Convec is waiting for a kit to be built at the SF, or if cargo trucks can't return to the smelter because you can't hold anymore ore. In that case, they'll go to where the rect for that group is set, and wait there. By default, it's probably (0, 0, 0, 0). Hence why they would move to the top left corner.

Also, the rect coordinates aren't inclusive of all edges. So something like (99, 99, 99, 99) will have no interior. I believe it includes the top and left sides of the rect, and excludes the bottom and right sides. You also want to make sure there is room for all the units in that rect, or funny things may happen. When I did that before, they all just fought over the same space and kept pushing each other out of the way.

So, make the rect bigger, and put it somewhere useful where you want units to hang out. And try using SetRect on the group containing the units if no other way  to specify a rect works.
 
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 23, 2005, 05:02:05 PM
I tried making it like this
Code: [Select]
fighters.SetRect(0, 0, 0, 0);
but it told me my favorite error :P

'FightGroup::SetRect' : function does not take 4 arguments

what do you suggest I do?
 
Title: Units Want To Go Off The Map?
Post by: Hooman on November 23, 2005, 05:27:32 PM
It takes a RECT struct/class as an argument, not the four corners of the rect. Just need extra parentheses and a class name.

Code: [Select]
fighters.SetRect(MAP_RECT(0, 0, 0, 0));
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 23, 2005, 06:30:24 PM
okay I have spent the last hour watching units go here and there in some wierd dance  :ph34r:  could you help me get them to stand still in one spot? like say right outside of the VF? or explain in grave detail how I should use this code that creates dancing of crazyness?
 
Title: Units Want To Go Off The Map?
Post by: Hooman on November 23, 2005, 08:38:23 PM
Did you try calling SetRect before or after calling AddGuardedRect?

I think this is the point where Eddy steps in. He's probably used these classes and functions more than other people have.
 
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 23, 2005, 09:07:28 PM
I placed it in the code after  AddGuardedRect

 I am now going to try changing that to see if it helps. but I don't really know what I am doing

Edit:  nope just as random as before
Title: Units Want To Go Off The Map?
Post by: Hooman on November 23, 2005, 10:09:09 PM
Well like I said. Time for Eddy to jump in.  :blush:  
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 24, 2005, 01:46:38 PM
The problem is not the SetRect. But, as i said: this is not your problem. The real 'bug' of your code is in the group handling. The way you have your BuildingGroup set up, the new units are not assigned to a default group. Change your code to this:
Code: [Select]
  Unit VF;
  TethysGame::CreateUnit(VF, mapVehicleFactory, LOCATION(57,22), 1, mapNone, 0);
  FightGroup fighters = CreateFightGroup(Player[1]);
  BuildingGroup producer = CreateBuildingGroup(Player[1]);
  producer.TakeUnit(VF);
  producer.RecordVehReinforceGroup(fighters, 0);
  fighters.SetTargCount(mapLynx, mapMicrowave, 2);

// modification:
    fighters.DoGuardRect();
    fighters.SetRect(MAP_RECT(99,99,101,101));
    fighters.AddGuardedRect(MAP_RECT(80,80,120,120));  // just added as example, see below
The "bug" in Outpost 2 group coding, is that when calling DoGuardRect ALL previously stored Rects are removed (in essence: it calls ClearGuarderdRects).
Also, if the region to be guarded is the same as the SetRect region, you do not explicitly have to add it, because SetRect implicitly calls AddGuardedRect to add itself to the list of rects.

Reply if it still doesn't work.
See also: http://wiki.opu.org.uk/AI_Coding (http://wiki.opu.org.uk/AI_Coding)
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 25, 2005, 10:12:16 AM
any idea why it froze on me Eddy?

is it something with the map?   like a problem I had when I first tried moving units in my earlyer code?
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 25, 2005, 10:16:43 AM
wait a minute!  the game froze ?
what map did you use? a standard op2 map, or one that you've created?

and when does it freeze. (coz there was a mapping bug, using the old mapper)
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 25, 2005, 10:29:18 AM
Quote
wait a minute! the game froze ?
what map did you use? a standard op2 map, or one that you've created?

and when does it freeze. (coz there was a mapping bug, using the old mapper)

it freezes right after the unit is made.   I can move units before its made though
I am using a standard OP2 map. I think its the one in the first eden mission.
 
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 25, 2005, 10:38:03 AM
i hope you DO realise you're using player[1] - which is in fact player #2!

and i must confess, i didn't test the code i gave you. I just typed it up from memory
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 25, 2005, 10:40:33 AM
I have player[1] and player[0]   I know what I am doing there.   I think


Edit: I should be player 0 when it loads  I am trying to get it to make a unit for the computer
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 25, 2005, 10:43:11 AM
correct - when this is a single-player dll, you'd use player[0] for the human player, and any other is AI
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 25, 2005, 10:45:01 AM
I thought so.     So whats wrong with the code?
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 25, 2005, 11:35:00 AM
send me the code (source files) - i'll look into it:  renegades@eddy-b.com
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 27, 2005, 06:14:20 PM
have you turned up anything yet Eddy?


spirit


btw   were those the files you wanted?
Title: Units Want To Go Off The Map?
Post by: Eddy-B on November 27, 2005, 06:22:07 PM
i need YOUR versions of the extra files, like op2helper, basebuilder... i tried compiling, but i need to edit a lot to have it compile at all..
Title: Units Want To Go Off The Map?
Post by: spirit1flyer on November 27, 2005, 06:35:32 PM
didn't I send you op2helper, basebuilder already? other then those 2 I don't know what files you need.


spirit