diff --git a/wurst/commands/UnitPropertyCommands.wurst b/wurst/commands/UnitPropertyCommands.wurst index 43e82b1..5c662b2 100644 --- a/wurst/commands/UnitPropertyCommands.wurst +++ b/wurst/commands/UnitPropertyCommands.wurst @@ -1,6 +1,7 @@ package UnitPropertyCommands import YARP +import aUnit init execute() -> @@ -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) + 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()) \ No newline at end of file diff --git a/wurst/core/AttachModify/AttachLink.wurst b/wurst/core/AttachModify/AttachLink.wurst new file mode 100644 index 0000000..34b8736 --- /dev/null +++ b/wurst/core/AttachModify/AttachLink.wurst @@ -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() + 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()) diff --git a/wurst/core/AttachModify/aUnit.wurst b/wurst/core/AttachModify/aUnit.wurst new file mode 100644 index 0000000..066559a --- /dev/null +++ b/wurst/core/AttachModify/aUnit.wurst @@ -0,0 +1,72 @@ +package aUnit + +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 + unit u + static HashSet ConnectionStorage + HashSet guestConnections + //run in miscinit + static function init_Connection_Storage(timer clock, real timeout) + ConnectionStorage = new HashSet() + TimerStart(clock, timeout, true, function updateStoredConnections) + + static function updateStoredConnections() + HLIterator iterator = ConnectionStorage.iterator() + 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 + 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) + SetUnitY(guest, yNew) + SetUnitFlyHeight(guest, zNew, 0) + + /*function update_Guests() + //update guests + HLIterator 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) diff --git a/wurst/core/MiscInit.wurst b/wurst/core/MiscInit.wurst index f55294d..951a876 100644 --- a/wurst/core/MiscInit.wurst +++ b/wurst/core/MiscInit.wurst @@ -5,6 +5,8 @@ import Command import Spawner import PlayerSettings import AutoGenerated +import aUnit + function initNeutrals() let neutral = players[bj_PLAYER_NEUTRAL_EXTRA] @@ -66,4 +68,5 @@ init initPlayerAlliances() initSell() initVision() - placeShops(0, 0) \ No newline at end of file + placeShops(0, 0) + aUnit.init_Connection_Storage(CreateTimer(),.03125) \ No newline at end of file