Skip to content
This repository has been archived by the owner on Sep 2, 2019. It is now read-only.

Attach Added #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions wurst/commands/UnitPropertyCommands.wurst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package UnitPropertyCommands

import YARP
import aUnit

init
execute() ->
Expand Down Expand Up @@ -97,5 +98,15 @@ init
UnitCommand.register("pitch") (context, arguments, what) ->
what.setPitch(arguments.getReal(1).asAngleDegrees())

UnitCommand.register("attach") (context, arguments, what) ->
let a = arguments.getString(1)
let b = arguments.getReal(2)
let c = arguments.getReal(3)
let d = arguments.getReal(4)
let e = arguments.getBool(5)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use better variable names.

print(a + " " + b.toString() + " " + c.toString() + " " + d.toString() + " " + e.toString())
aUnit.AttachUnit(CreateUnitByName(what.u.getOwner(), a, 0, 0, 0), null, what.u, b, c, d, 0, e)


UnitCommand.register("roll") (context, arguments, what) ->
what.setRoll(arguments.getReal(1).asAngleDegrees())
54 changes: 54 additions & 0 deletions wurst/core/AttachModify/AttachLink.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package AttachLink

import public HashSet
import public initlater aUnit

public class AttachLink


real cooldown
real cooldownReset
trigger turretTrigger
boolean dynamicFacing
boolean updateFacing
boolean isHidden
real distance
real angle
real zOffset
real offsetFix
real angleRate
real facing
real idleAngle
boolean staticAngle
aUnit host
aUnit guest
effect fx






function g_Destroy()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this? Why not ondestroy?

this.staticAngle = false
this.dynamicFacing = false
this.updateFacing = false
this.isHidden = false
this.angleRate = 0
this.idleAngle = 0

construct(unit guest, effect fx, unit host, real angle, real distance, real zOffset, bool staticAngle)
this.guest = new aUnit()
this.host = new aUnit()
this.guest.u = guest
this.fx = fx
this.host.u = host
this.angle = angle
this.distance = distance
this.zOffset = zOffset
this.staticAngle = staticAngle
print("New linked formed with..")
print("distance: " + distance.toString())
print("angle: " + angle.toString())
print("zOffset: " + zOffset.toString())
print("staticAngle: " + staticAngle.toString())
72 changes: 72 additions & 0 deletions wurst/core/AttachModify/aUnit.wurst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package aUnit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use CapitalCamelCase for package names.


import public HashSet
import public initlater AttachLink
import public Maths
import public Angle

/*

A Unit is the unit that is in the ConnectionStorage container that is periodically updated
AttachLink is the link which holds the host and guest aUnits as well as their metadata

*/
public class aUnit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use CapitalCamelCase for class names.

unit u
static HashSet<AttachLink> ConnectionStorage
HashSet<AttachLink> guestConnections
//run in miscinit
static function init_Connection_Storage(timer clock, real timeout)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lowerCamelCase for functions/methods.

ConnectionStorage = new HashSet<AttachLink>()
TimerStart(clock, timeout, true, function updateStoredConnections)

static function updateStoredConnections()
HLIterator<AttachLink> iterator = ConnectionStorage.iterator()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use let iterator = ... vs explicit type annotations.

while iterator.hasNext()
AttachLink currentLink = iterator.next()
unit guest = currentLink.guest.u
unit host = currentLink.host.u
real x = host.getX()
real y = host.getY()
real z = BlzGetLocalUnitZ(host)
real f = GetUnitFacing(host)
real xNew
real yNew
real zNew
if(currentLink.staticAngle)
xNew = x + Cos(currentLink.angle * DEGTORAD) * currentLink.distance
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the angle tuple for representing angles vs manual degrees/radians conversions. More can be found in stdlib's Angle.wurst

yNew = y + Sin(currentLink.angle * DEGTORAD) * currentLink.distance
zNew = z
else
xNew = x + Cos(currentLink.angle * DEGTORAD + f * DEGTORAD) * currentLink.distance
yNew = y + Sin(currentLink.angle * DEGTORAD + f * DEGTORAD) * currentLink.distance
zNew = z
SetUnitX(guest, xNew)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use unit.setXY(vec2) vs natives.

SetUnitY(guest, yNew)
SetUnitFlyHeight(guest, zNew, 0)

/*function update_Guests()
//update guests
HLIterator<AttachLink> iterator = guestConnections.iterator()
while iterator.hasNext()
AttachLink currentLink = iterator.next()
aUnit guest = currentLink.guest
aUnit host = currentLink.host
if(currentLink.staticAngle)
guest.u.setX(host.u.getX() + currentLink.distance * Cos(currentLink.angle * DEGTORAD))
guest.u.setY(host.u.getY() + currentLink.distance * Sin(currentLink.angle * DEGTORAD))
else
real angle = currentLink.angle + host.u.getFacingAngle().radians()
guest.u.setX(host.u.getX() + currentLink.distance * Cos(currentLink.angle * DEGTORAD + host.u.getFacingAngle().radians()))
guest.u.setY(host.u.getY() + currentLink.distance * Sin(currentLink.angle * DEGTORAD + host.u.getFacingAngle().radians())) */

static function AttachObject(unit g, effect fx, unit h, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle) returns AttachLink
if h == null or (g == null and fx == null)
return null
AttachLink rVal = new AttachLink(g,fx,h,angle,distance,zOffset,staticAngle)
ConnectionStorage.add(rVal)
return rVal


static function AttachUnit(unit guest, effect fx, unit u, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle) returns AttachLink
return AttachObject(guest, fx, u, angle, distance, zOffset, offsetFix, staticAngle)
5 changes: 4 additions & 1 deletion wurst/core/MiscInit.wurst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Command
import Spawner
import PlayerSettings
import AutoGenerated
import aUnit


function initNeutrals()
let neutral = players[bj_PLAYER_NEUTRAL_EXTRA]
Expand Down Expand Up @@ -66,4 +68,5 @@ init
initPlayerAlliances()
initSell()
initVision()
placeShops(0, 0)
placeShops(0, 0)
aUnit.init_Connection_Storage(CreateTimer(),.03125)