HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Collision Missiles question

04-09-2006, 10:51 PM#1
mmx2000
1.) Do collision missiles automatically home in on their target? Or do you have to control them via angle changes.

2.) I can define separate OnImpact functions for every Collision Missile, right?

3.) Can I create a collision missile outside of the map boundaries?
EDIT: Okay so from reading through forums seems #3 is obviously impossible. Let me rephrase then:
What happens when I try to create a Collision Missile outside the map? Does it not do it, does it crash wc3, does it create it at the map border?
If options 1 or 2, is there a way I can create it at map border?

4.) If I set Collision Size to 0, will they never call the OnImpact function?

Thanks :)
04-10-2006, 08:46 AM#2
Thunder_Eye
I'm pretty sure 3) will crash the game.
04-10-2006, 08:56 AM#3
karukef
Quote:
Originally Posted by Thunder_Eye
I'm pretty sure 3) will crash the game.

It will only crash the game if the caster system doesnt check for that when creating collition missiles. So either say that you know the caster system does or doesn't check for that, otherwise you are only guessing.

1) If you actually read the comment triggers that come with the caster system you will find that you can make it have a target that it homes in on.

2) Yes of course.

4) Try that one out for yourself.
04-10-2006, 09:04 AM#4
Thunder_Eye
Oh I didn't know he was talking about CS ;P never used it myself so I'm not familiar with its functions.
04-10-2006, 04:11 PM#5
mmx2000
I am trying them out for myself, just erm, having problems getting it to run, and wanted to make sure that none of these were my problem.
Still need an answer for #3

Thanks for your replies so far :)
04-10-2006, 04:18 PM#6
Thunder_Eye
Well it depends on the CS, but I assume it has a check so It dont crash, not sure though. Ask someone more familiar with it.
04-10-2006, 07:46 PM#7
mmx2000
Quote:
Originally Posted by Thunder_Eye
Well it depends on the CS, but I assume it has a check so It dont crash, not sure though. Ask someone more familiar with it.

Well I was hoping for a reply from Vex ;)
Whichever mod moved this to the subforum, thanks, I thought one existed but didn't see where :)
04-10-2006, 10:08 PM#8
Meanie
Vex is gone i think....well anyways if it does not crash the game the unit will created within map bounds anyway so what is the problem?

And checking if the location is outside map bounds are really simple....ehm just check vex's CSMoveUnit
04-10-2006, 10:48 PM#9
mmx2000
Ah.
Okay, new question then:

In my spell, I create multiple Collision Missiles that home in on the target (as you would imagine from my question).

Now, I want each Missile to be a different color as a function of various things.
In looking at Vex's code, it seems like the model you set for your missile model gets added as a special effect to an invisible projectile unit.
Since I was trying to use SetUnitVertexColor() on this invis unit, nothing seems to happen.
Any ideas on a workaround so I can set the color of each Collision Missile dynamically?
Or in other words, is there anyway to Set the Vertex coloring of an Effect?

EDIT: Well I've searched high and low and see no way to do it. So what I'm going to try to do is C&P the CollisionMissile_Create function and modify it (as in, change the AddCaster stuff) to use a new dummy unit with a visible model rather than the Caster model.
$10 says I break Warcraft <.<

EDIT #2: Well I'm not sure if I succeeded or not. I managed to create a new version of CollisionMissile_Create that does indeed create the missiles as visible projectiles that can at least have their scale changed (colors not working atm, but could be because of my color function)... however, the collisions aren't being detected.
Not sure why, here's my new function code:
Collapse JASS:
function Equator_Shot_CollisionMissile_CreateLoc takes integer MissileModelUnit, location loc, real dirangle, real speed, real AngleSpeed, real MaxDist,  real height, real Collision, code OnImpact returns unit
    //Changed the 1st parameter to be a Unit rather than model-string.
    //Removed the UseNewCaster parameter. You have to use a new one since this caster is not the same as all other CS casters.
 local real x = GetLocationX(loc)
 local real y = GetLocationY(loc)
 local timer t
 local gamecache H=CSCache()
 local string k
 local integer ki
 local trigger R
 local group g
 local unit m


    if (HaveStoredInteger(H,"CasterSystem","MOVEMENT_TIMER")) then
        set g=GetTableGroup("CasterSystem","MOVEMENT_GROUP")
    else
        set t=CreateTimer()
        set g=CreateGroup()
        call SetTableObject("CasterSystem","MOVEMENT_TIMER",t)
        call SetTableObject("CasterSystem","MOVEMENT_GROUP",g)
        call TimerStart(t,CS_Cycle(),true,function CasterSystemMovementTimer)
    endif
    set ki=NewTableIndex()
    set k=I2S(ki)

    //Removed if UseNewCaster if-bracket, since you have to use a new caster.
    //Replaced the call to AddNewCaster by pasting the code from it into here, and modifying
    //the calls to GetCasterId to just use the passed UnitId MissileModelUnit
    //AddCasterFacing Code:
        set m = CreateUnit( Player(15), MissileModelUnit, 0 ,0 , dirangle)   //Added to create a Dummy unit for the Missile
        call UnitAddAbility(m, 'Aloc')
        call UnitAddAbility(m, ChangeableFlyingHeightAllowerId())
        call UnitRemoveAbility(m, ChangeableFlyingHeightAllowerId())
        set udg_currentcaster=m
    //end AddCasterFacing
    
    call StoreBoolean(H,k,"new",true)

    call StoreInteger(H,"MOVEMENT_TABLES",GetAttachmentTable(m),ki)
    call StoreBoolean(H,k,"IsCollisionMissile",true)

    //Switched call SetUnitPosition to call CS_MoveUnit to check that no unit is created out of map bounds.
    //If the position is out of bounds, its created at the map boundary.
    call CS_MoveUnit(m,x,y)
    
    call StoreReal(H,k,"speed",speed)
    call StoreReal(H,k,"aspeed",AngleSpeed)
    call StoreReal(H,k,"F",dirangle)
    call StoreReal(H,k,"maxd",MaxDist)
    call SetUnitFlyHeight(m,height,0)



    call GroupAddUnit(g,m)

    set R=CreateTrigger()
    call AttachObject(R,"m",m)
    call StoreReal(H,k,"collision",Collision)
    call SetTableObject(k,"T",R)
    call StoreInteger(H,"MOVEMENT_TABLES",GetAttachmentTable(R),ki)
    call SetTableObject(k,"fx", AddSpecialEffectTarget(null,m,"origin") )
    call SetTableObject(k,"m",m)
    call SetTableObject(k,"ac",TriggerAddAction(R,OnImpact))

 set t=null
 set g=null
 set R=null
 set udg_currentcaster=m
 set m=null
 set H=null
 return udg_currentcaster
endfunction

EDIT #3: My best guess is that what I'm trying to do is impossible. :'(
04-11-2006, 11:54 AM#10
Vexorian
SetUnitVertexColor() does work on the dummy unit, seriously, plenty of my spells depent on that.
04-11-2006, 12:08 PM#11
Blade.dk
But not all attached models are recolored, for example particle using models aren't as far as I remember.
04-11-2006, 12:28 PM#12
mmx2000
Quote:
Originally Posted by Blade.dk
But not all attached models are recolored, for example particle using models aren't as far as I remember.
Oh, really?
Well.
I guess my stuff is just Fubar :T Thanks for informing... ><
04-11-2006, 03:59 PM#13
Vexorian
Quote:
Originally Posted by Blade.dk
But not all attached models are recolored, for example particle using models aren't as far as I remember.
particles are never recolored I think not even if they are main units as far as I know
04-11-2006, 07:28 PM#14
mmx2000
Thanks :) Heh, I'm feeling I should have picked something a little less ambitious for my first JASS spell ever >.>;
04-12-2006, 06:32 AM#15
mmx2000
Problem:

Well, turns out I solved the earlier problem by noticing an error in my substring call that would set all the alpha's to 255. Hence invisible. Oops.

Now that I can see my CollisionMissiles... I can't set the color of them. I don't know why.

Getting an extremely wierd phenomenon:
Basically, Have this code to set up each missile:
Collapse JASS:
set i = 1
    loop
        exitwhen (i > NumberOfShots)
        
        //Get a distance value for the orb.
        set tempdistance = GetRandomReal(MinimumDistance, DistancePerLevel * GetUnitAbilityLevel(CastingUnit, SpellAbilityId) )
        //Calculate it's location
        set temploc = PolarProjectionBJ(GetUnitLoc(TargetUnit), tempdistance, Angle * i)
        //Create the orb
        set MiniOrb = CollisionMissile_CreateLoc(MiniOrbModel, temploc, ((Angle * i) + 180.0), MoveSpeed, 200.0, 20000.0, Equator_Shot_FlyingHeight(), false, CollisionSize, function Equator_Shot_OrbHit)
        call CollisionMissile_SetTarget(MiniOrb, TargetUnit)    //Tell the missile to target the TargetUnit
        call RemoveLocation(temploc)
        call SetUnitScale(MiniOrb, MiniOrbScale, MiniOrbScale, MiniOrbScale)
        //Set Orb Color:
        if (DefaultColors == true) then
            set MiniOrbColorString = Equator_Shot_RainbowColor(i)
        else
            set MiniOrbColorString = Equator_Shot_MiniOrbColor()
        endif
        set MiniOrbRed = S2I(SubString(MiniOrbColorString, 0, 3))
        set MiniOrbGreen = S2I(SubString(MiniOrbColorString, 3, 6))
        set MiniOrbBlue = S2I(SubString(MiniOrbColorString, 6, 9))
        set MiniOrbAlpha = S2I(SubString(MiniOrbColorString, 9, 12))
        call SetUnitVertexColor(MiniOrb, MiniOrbRed, MiniOrbGreen, MiniOrbBlue, MiniOrbAlpha)

        //Attach Information to Orb
        call AttachInt(MiniOrb, "OrbNumber", i)
        call AttachReal(MiniOrb, "x", GetUnitX(MiniOrb))
        call AttachReal(MiniOrb, "y", GetUnitY(MiniOrb))
        call AttachInt(MiniOrb, "CastingPlayerNumber", GetConvertedPlayerId(CastingPlayer))
        call AttachObject(MiniOrb, "TargetUnit", TargetUnit)
        call AttachObject(MiniOrb, "CastingUnit", CastingUnit)
        call AttachObject(MiniOrb, "BigOrb", BigOrb)
        call AttachString(MiniOrb, "MiniOrbColorString", MiniOrbColorString)
        
        //increment loop    
        set i = i + 1
    endloop

Assuming that the defaultcolorsystem is enabled, it calls this function:
EDIT: I see in testing that I made a logic error with trying to make ColorCounter go 1,2,3,4,5,6,7,1,2,3,4,5,6,etc. If you could fix that (Modulo for some reason seems out of my brains capacity to understand atm ><) that would be nice too^^;
Collapse JASS:
function Equator_Shot_RainbowColor takes integer OrbNumber returns string

    
    local integer NumberOfShots = Equator_Shot_NumberOfShots()
    local string tempstring = "000000000000"
    local integer ColorCounter
    
    //ColorCounter Maintenance   
    if (OrbNumber <= 7) then
        set ColorCounter = OrbNumber
    else
        set ColorCounter = ModuloInteger(OrbNumber, 7)
    endif
    
    //Supply appropriate color
    if (ColorCounter == 1) then //Red
        set tempstring = "255000000000"
    elseif (ColorCounter == 2) then //Orange
        set tempstring = "255125000000"
    elseif (ColorCounter == 3) then //Yellow
        set tempstring = "255255000000"
    elseif (ColorCounter == 4) then //Green
        set tempstring = "000255000000"
    elseif (ColorCounter == 5) then //Teal
        set tempstring = "000255255000"
    elseif (ColorCounter == 6) then //Blue
        set tempstring = "000000255000"
    elseif(ColorCounter == 7) then //Purple
        set tempstring = "255000255000"
    endif
    
    return tempstring
endfunction

However... all the missiles turn out the same color (seems like its "white").

Now... I USED to have code that (unfortunately i dont have anymore) attempted to calculate spots on a gradient chart for each orb to be more a more smoothly planned color progression on a rainbow. The code didn't work and failed miserably, giving me wierd values that were negative, etc.
HOWEVER: when i had that code... some missiles would be colored. obviously not the colors i wanted, but they were there nonetheless.

Since changing the rainbowcolor function, I have not been able to affect the color of the CollisionMissiles. I've no idea why. The code that assigned the missiles their color (the first loop) remained unchanged.
I tried setting negative values to colors to see what would happen. Did nothing.

I cannot reproduce what I did to make colors appear on my missiles.

What am I doing wrong?