Game Development Community

Interacting rather than fighting?

by Dreamer · in RTS Starter Kit · 11/11/2005 (12:05 am) · 8 replies

Ok, so I've created some simple minimalistic AI controlled Units.
I've also got them able to fight.
Problem is that I want to add an option to the PlayGUI to have them Interact, just something simple like saying "Hello" or something.

So I added a new button to the PlayGUI, added an new Input Handler called Interact.
I have Interact calling a server command serverCmdInteract.
serverCmdInteract calls a clientCmdInteract response, which just pushes a message dialog on the client that says "Hello"
Boring yeah I know.
Anyways for some reason even though all the above works flawlessly, the AI and the Player start attacking eachother, the messagebox pops up fine, but then they get violent with eachother.

I've looked everywhere I can think of and I can't seem to see anywhere that serverCmdIssueAttack or CommandToServer(IssueAttack) are being called.

Am I missing something fundamental here? Is there some kind of default action that an RTSUnit undergoes when no other command is present? And if so where the heck is it?

Any Ideas on how I can stop the violence?

#1
11/11/2005 (6:41 am)
Any auto-attack has to be from your own code, -unless- your method of selecting the particular unit and bringing the interact key happens to be also having your own unit issue an attack.

I'd put in an echo statement in the issue attack stuff to see what's going on (if they are being called, by which unit, etc.).
#2
11/11/2005 (11:41 pm)
Man I'm still not seeing it.
Here's a question, in the default RTS setup, if I see an opponent I click on my player then click on the opponent, doesn't my unit go and attack his unit without issuing an additional command. If so this would probably be my issue. Or how is that handled?

*update* There does seem to be something coded somewhere that causes one unit to attack another in the event they aren't on the same team, and one is told to move to the others location.
I have completely removed serverCmdIssueAttack from the script and running a trace shows that as soon as player 1 gets within range of player 2's location shockerBlock::OnAttack is being called (my player is a shocker the AI is a rifleman).

I'm afraid I may just have to set some kind of flag and bail out of the onAttack function on it.

*update again*
I still haven't figured out what's calling it, but I can verify that if there is no CurrentCommand state on the player1 and he clicks on one of Player2's units, that OnAttack is called. This is on a stock RTS with 2 players in game. I haven't tried this yet in a true multiplayer setup.

I have at least temporarily solved the problem by setting a .isBusy flag on both player1 and AI unit when serverCmdInteract is called. Then in the OnAttack function I have it checking for the flags and clearing the .isBusy flag, so the next attempt at an attack will be successful.

It's still bugging me though, where on earth is OnAttack being called a trace(1) shows nothing at all until the function itself is called, which leads me to believe this is some hardcoded behavior, and I'm going to have to look under the hood to find my answer.
#3
11/12/2005 (3:11 am)
Tried looking for places that call onAttack? It might be that cmdInteract just calls it directly when you click on the unit.
#4
11/12/2005 (6:52 am)
Yes, the default behaviour for clicking on an enemy unit when no CurrentCommand is to attack. Look at function GuiRTSTSCtrl::onRightMouseDownUnit() in the file client/scripts/inputHandler.cs.
#5
11/13/2005 (7:02 am)
Ok Stephen you were correct onRightMouseDownUnit is or was being called, now I am just piping it to onMouseDownUnit instead.
They still want to fight.
However by placing isBusy flags in the places mentioned above and placing a call to stopAll I can stop the fight before any damage is dealt out. You can still see the initial attack animations play though.

I'm going to comment out each line in serverCmdInteract until they no longer try to fight and see if anything in there might be causing it.
#6
11/13/2005 (8:12 am)
I solved this problem quite by accident. In my serverCmdInteract I was setting %unit.setAimObject(%otherunit); so that they would turn towards eachother.
During the course of troubleshooting, I commented out that line. No more attacking, not even an attack animation.
They still turn towards eachother.
I'm suffering from a severe case of confusion, since I can see nowhere that setAimObject would cause onAttack to be called. I also now have no idea why they still turn towards one another.
Anyways, by not having the mutual setAimObject, they just say hello to one another and go on their merry way.
Thoughts?
#7
11/18/2005 (11:49 am)
In RTSUnit.cc, function RTSUnit::processTick():

// Check if goal is to attack a target
      ShapeBase* target = dynamic_cast<ShapeBase*>(&(*mAimObject));
      if(mAimObjectSet  && (!target || target->getDamageState() == ShapeBase::Enabled))
      {
         // Check that our aim object is or is derived from RTSUnit
         if(RTSUnit *target = dynamic_cast<RTSUnit*>((GameBase*)mAimObject))
         {

Basically, if the mAimObject resolves to a valid, active RTSUnit, then this code (and the stuff I snipped afterwards) has our unit attack the target.
#8
11/18/2005 (11:53 am)
Ahh ok, that explains it!
Thanks by the way.