Author Topic: Units Want To Go Off The Map?  (Read 4196 times)

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« 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
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Mcshay

  • Administrator
  • Sr. Member
  • *****
  • Posts: 404
Units Want To Go Off The Map?
« Reply #1 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).

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #2 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.
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Units Want To Go Off The Map?
« Reply #3 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.
 

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #4 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?
 
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Units Want To Go Off The Map?
« Reply #5 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));

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #6 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?
 
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Units Want To Go Off The Map?
« Reply #7 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.
 

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #8 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
« Last Edit: November 23, 2005, 10:03:34 PM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Units Want To Go Off The Map?
« Reply #9 on: November 23, 2005, 10:09:09 PM »
Well like I said. Time for Eddy to jump in.  :blush:  

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #10 on: November 24, 2005, 01:46:38 PM »
The problem is not the SetRect.
  • If you define a SetRect of (99,99,99,99) the created unit(s) should start moving towards that point, and keep circling around it, coz it's an empty region. If you want it to be 1 point, use (99,99,100,100), as the bottom and right edges are not included in the rect. If you create more than 1 unit, you still have the same problem, as all those units will want to stay on that 1 spot. I found it to work better to assign a region, that is AT LEAST large enough to fit all units of the group. In this case you are creating a group of 2 lynx so make the region at least 2 tiles. SetRect(MAP_RECT(99,99,101,101)) creates a 2x2 region at location (68,100), remember the (31,-1) offset!
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
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #11 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?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #12 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)
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #13 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.
 
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #14 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
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #15 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
« Last Edit: November 25, 2005, 10:42:10 AM by spirit1flyer »
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #16 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
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #17 on: November 25, 2005, 10:45:01 AM »
I thought so.     So whats wrong with the code?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #18 on: November 25, 2005, 11:35:00 AM »
send me the code (source files) - i'll look into it:  renegades@eddy-b.com
« Last Edit: November 25, 2005, 11:35:14 AM by Eddy-B »
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #19 on: November 27, 2005, 06:14:20 PM »
have you turned up anything yet Eddy?


spirit


btw   were those the files you wanted?
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter

Offline Eddy-B

  • Hero Member
  • *****
  • Posts: 1186
    • http://www.eddy-b.com
Units Want To Go Off The Map?
« Reply #20 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..
Rule #1:  Eddy is always right
Rule #2: If you think he's wrong, see rule #1
--------------------

Outpost : Renegades - Eddy-B.com - Electronics Pit[/siz

Offline spirit1flyer

  • Hero Member
  • *****
  • Posts: 621
Units Want To Go Off The Map?
« Reply #21 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
"Until you stalk and overrun You can't devour anyone"


Loyal Xfir supporter