Handling weapon arcs on rotating turrets

Handling weapon arcs on rotating turrets

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Handling weapon arcs on rotating turrets

Post by Guessmyname » 24 Apr 2011, 20:56

I've run into a slight snag when scripting mechs. By and large, most have weapons on either side of their body, which can only aim 180-ish degrees left/right respectively. The problem arises in that the body of the mech - which these weapons are attached to - can rotate independent of the legs, which is where the unit is actually facing. It's easier to explain in pictures...

Image
This is a generic mech layout. The green arrow is the facing of the mech, the red arcs the range the weapons can aim in, and the yellow arcs the firearcs as Spring would handle them. Here, the body is aligned to the facing, so there is no problem. But when this happens...

Image
...we have a problem. In the worst case scenario, the body can be pointed backwards, which effectively means the weapons can only aim through themselves.

I'm going for a more tactical game, with few units (20-30 per player would be considered 'a lot'), so a) expensive scripts to work around this aren't an issue and b) it's worth it when you have small numbers of units, that those units not act dumb.

With a 360 independent body, the unit should be able to aim with at least one of it's weapons in any orientation. The idea is this:

Against the unit's primary target (ie if the player has placed an attack order on something or whatever it's AI holds as the most dangerous target - how does default target priority work, by the way?), the unit will evaluate which is the most appropriate weapon against that target, and rotate it's body to bring it's arc of fire to bear. The other weapon can then target whatever else happens to be in its cone of fire. I'd like to expand on that (ie rotating the body so that both weapons can aim as best they can), but that's the key part. To this end, I have a few questions:
  • How does the unit AI evaluate targets normally?
  • Is there a way to force a weapon to try and pick a different target? (I think there is, I just can't remember how)
  • What would be the best way to do target evaluation; unitscript or a gadget?
  • Is there a reference of Spring specific lua functions anywhere? I mean for things 'Spring.GetUnitHealth(unitID)' etc
  • What restrictions are there on what can be inside of a unit's lua script compared to a gadget?
0 x

User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

Re: Handling weapon arcs on rotating turrets

Post by yuritch » 24 Apr 2011, 22:20

Targeting constants for unit scripts (as used in COB scripts, lua would be a bit different):

Code: Select all

#define CHANGE_TARGET             98;
set CHANGE_TARGET to 1;
This should cause weapon1 to abandon its current target and look for a new one. AFAIK if there is only 1 target in range, it may not work. This constant is used by AA gun scripts in S44.

Code: Select all

#define SET_WEAPON_UNIT_TARGET   106;
get WEAPON_UNIT_TARGET(weaponNum, unitID, userTarget)
This should cause weaponNum to target a unit whose ID is given as second argument. Not sure what the third param does, never actually used this.
0 x

User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Handling weapon arcs on rotating turrets

Post by knorke » 24 Apr 2011, 23:46

# How does the unit AI evaluate targets normally?
it somehow assigns target weights, based on distance and unit cost and maybe other factors. I think there are tags to make units prefer close or far away units? Not much docu on all this.
* Is there a reference of Spring specific lua functions anywhere? I mean for things 'Spring.GetUnitHealth(unitID)' etc
wiki, ie http://springrts.com/wiki/Lua_SyncedRead http://springrts.com/wiki/Lua_SyncedCtrl
(can also be used in unit script)
* What restrictions are there on what can be inside of a unit's lua script compared to a gadget?
callins like (gadget:UnitDestroyed) only work in gadget, unit specific callins like script.startMoving only work in unit scripts. But gadget and unit scripts can talk to each other (in both directions) so they can notify each other of such events. (answers page for examples)
Also units can not draw graphics because they do not have the DrawScreen etc callin.
* What would be the best way to do target evaluation; unitscript or a gadget?
depends on what you want to do
* Is there a way to force a weapon to try and pick a different target? (I think there is, I just can't remember how)
there is a discussion about this on the answers page, did not really find a solution and somebody thought it was not possible due to bug. (did not work on user targers?)
0 x

User avatar
Guessmyname
Posts: 3301
Joined: 28 Apr 2005, 21:07

Re: Handling weapon arcs on rotating turrets

Post by Guessmyname » 25 Apr 2011, 06:54

The idea is that:

The unit acquires a 'primary target' - this is what it decides is the biggest threat for whatever reason, or is the location/unit the player has ordered it to attack. Unit evaluates the target and picks the most appropriate weapon.* Unit then aims with this weapon, rotating stuff around as necessary, whilst the other weapons that cannot reach the primary target just hits targets of opportunity appearing in their arc.

*Probably using unit categories; if I add a dictionary in the customparams section of weaponscripts with 'unit categories = weight' in order of effectiveness; tally all the weights for the categories the target is in, lowest score wins as the 'most effective weapon'
0 x

Post Reply

Return to “Game Development”

cron