Emulating mortar fire: targeting

Started by warren, August 21, 2015, 08:50:00 PM

Previous topic - Next topic

warren

As requested. Barely tested, no guarantees.

$Range:10

:proximityTest
  <-Range dup mul ->r2 #let Range be a global variable ~=10
  -1 ->targX
  -1 ->targY
  0 ->deepest

  <-Range 1 add <-Range neg do #scan the area
    <-Range 1 add <-Range neg do
      I dup mul J dup mul add <-r2 lt if #circle bound checking

        I CurrentX add ->x #shift origin to self
        J CurrentY add ->y
        <-x 0 gte <-y 0 gte and <-x MapWidth lt and <-y MapHeight lt and if #map bound checking
          <-x <-y GetCreeper ->temp
          <-temp <-deepest gt if #compare to best and replace if better
             <-x ->targX
             <-y ->targY
             <-temp ->deepest
          endif
        endif

      endif
    loop
  loop

<-targX <-targY #return the best or -1 -1 if none


driesemol

#1
Thanks a lot! The code looks very promising.
I'm gonna test it soon and we'll see if it works :)

EDIT: it seems to work! i'm gonna try to make a fully functional mortar now :) what i have already:
# mortaraim.crpl
# author: driesemol
# start: 22/08/2015

$Range:10
$MaxAmmo:15

once
Self CONST_COUNTSFORVICTORY False SetUnitAttribute
Self CONST_NULLIFIERDAMAGES False SetUnitAttribute
Self CONST_CREATEPZ False SetUnitAttribute
Self CONST_MAXAMMO <-MaxAmmo SetUnitAttribute
Self CONST_CONNECTABLE True SetUnitAttribute
Self CONST_CANREQUESTAMMO True SetUnitAttribute
Self CONST_REQUESTPACKETS True SetUnitAttribute
Self CONST_PACKETREQUESTDELAY 10 SetUnitAttribute
Self CONST_SHOWAMMOBAR True SetUnitAttribute
Self CONST_AMMO 0 SetUnitAttribute
endonce

Self CONST_AMMO GetUnitAttribute ->Ammo

#attack,

<-Ammo 3 gte if
@proximityTest ->AttackY ->AttackX
<-AttackX -1 neq <-AttackY -1 neq and if
<-AttackX <-AttackY 9999 4 3500000 0 DamageCreeper
Self CONST_AMMO <-Ammo 3 sub SetUnitAttribute
90 Delay
endif
endif

# mortaraim, made by WARREN

:proximityTest
  <-Range dup mul ->r2 #let Range be a global variable ~=10
  -1 ->targX
  -1 ->targY
  0 ->deepest

  <-Range 1 add <-Range neg do #scan the area
    <-Range 1 add <-Range neg do
      I dup mul J dup mul add <-r2 lt if #circle bound checking

        I CurrentX add ->x #shift origin to self
        J CurrentY add ->y
        <-x 0 gte <-y 0 gte and <-x MapWidth lt and <-y MapHeight lt and if #map bound checking
          <-x <-y GetCreeper ->temp
          <-temp <-deepest gt if #compare to best and replace if better
             <-x ->targX
             <-y ->targY
             <-temp ->deepest
          endif
        endif

      endif
    loop
  loop

<-targX <-targY #return the best or -1 -1 if none