//TESH.scrollpos=0
//TESH.alwaysfold=0
// =====================================================================================================
// * Spell - Shimmering Portal
// by Dark Dragon
//
//
// Installation:
//
// (1) Install "DD Library" to your map if you have not done so already from my previous spells
// (2) Copy "Shimmering Portal" trigger to your map
// (3) Copy "Shimmering Portal" and "Portal (Dummy)" to your map
// (4) Edit spell to your will in object editor and here below in trigger editor
// (5) Enjoy!
// =====================================================================================================
//! zinc
library ShimmeringPortal requires DDLib
{
// =============================================================
// *** Spell editable constants ***
// =============================================================
// ==========================================================================
//
// *** Primary Spell Constants ***
//
// ==========================================================================
// ----------------------------------------------------------------
// *** The id of shimmering portal spell
constant integer SPELL_ID = 'SPrt';
// ----------------------------------------------------------------
// *** The id of shimmering portal dummy
constant integer PORTAL_ID = 'port';
// ----------------------------------------------------------------
// *** The length of portal, shrinking the value will force units to enter closer to center of portal
constant real PORTAL_LENGTH = 450.;
// ----------------------------------------------------------------
// *** Width of portal, units will enter the portal more far away if value is increased,
// decreassing this value too much can make unit pass portal faster than check interval can scan, thous causing spell to bug
constant real PORTAL_WIDTH = 110.;
// ----------------------------------------------------------------
// *** Units that are teleported to target portal, will walk away from there position offseted by random value between this (min and max)
constant real UNIT_PORT_WALK_OFFSET_MIN = 200.;
constant real UNIT_PORT_WALK_OFFSET_MAX = 350.;
// ----------------------------------------------------------------
// *** The offset of first portal near caster
constant real FIRST_PORTAL_OFFSET = 300.;
// ----------------------------------------------------------------
// *** The minimum casting range for shimmering portal spell
constant real SECOND_PORTAL_MIN_RANGE = 1000.;
// ----------------------------------------------------------------
// *** Time it takes to destroy portal after it expires or last unit exits
constant real DESTROY_PORTAL_DELAY = .7;
// ----------------------------------------------------------------
// *** The warning message, displayed in red color, and sound played with it, volume is in percentage
constant string PORTAL_WARNING_MESSAGE = "Warning: Too close cast of Shimmering portal!";
constant string PORTAL_WARNING_SOUND_FILE = "Sound\\Interface\\Error.wav";
constant real PORTAL_WARNING_SOUND_VOLUME = 90.;
// ----------------------------------------------------------------
// *** The duration of warning message
constant real PORTAL_WARNING_MESSAGE_DURATION = 5.;
// ----------------------------------------------------------------
// *** This is animation of dummy portal, birth duration must be equeal to spell channel time
constant string PORTAL_ANIM_BIRTH = "birth";
constant string PORTAL_ANIM_DEATH = "death";
constant string PORTAL_ANIM_STAND = "stand";
constant real PORTAL_ANIM_BIRTH_DURATION = 7.5;
// ----------------------------------------------------------------
// *** How often to scan for units entry, greater value slows down CPU, while too low can cause units entered to not be registerd
constant real PORT_CHECK_INTERVAL = .1;
// ----------------------------------------------------------------
// *** Prevents units that are teleported to target portal to be teleported back, causing infinite loop of teleporting,
// this timing says that any unit will not be able to use any portals (MUI included)
constant real UNIT_NEXT_PORT_DELAY = 2.;
// ----------------------------------------------------------------
// *** Portal custom sounds files and volume in percentage
constant real SOUND_MAX_DISTANCE = 3500.;
constant string PORTAL_BIRTH_SOUND_FILE = "Sound\\Ambient\\DoodadEffects\\ShimmeringPortalBirth.wav";
constant real PORTAL_BIRTH_SOUND_VOLUME = 95.;
constant string PORTAL_DEATH_SOUND_FILE = "Sound\\Ambient\\DoodadEffects\\ShimmeringPortalDeath.wav";
constant real PORTAL_DEATH_SOUND_VOLUME = 95.;
constant string PORTAL_ENTRANCE_SOUND_FILE = "Sound\\Ambient\\DoodadEffects\\ShimmeringPortalEntrance.wav";
constant real PORTAL_ENTRANCE_SOUND_VOLUME = 95.;
constant string PORTAL_AMBIENCE_SOUND_FILE = "Sound\\Ambient\\DoodadEffects\\CityScapeMagicRunesLoop1.wav";
constant real PORTAL_AMBIENCE_SOUND_VOLUME = 100.;
// ==========================================================================
//
// *** Minimap Ping Constants ***
//
// ==========================================================================
// ----------------------------------------------------------------
// *** Do use minimap ping system for portals?
constant boolean PORTAL_USE_MINIMAP_PING = true;
// ----------------------------------------------------------------
// *** How often to ping minimap
constant real PORTAL_MINIMAP_PING_INTERVAL = 4.5;
// ----------------------------------------------------------------
// *** How long to ping minimap
constant real PORTAL_MINIMAP_PING_DURATION = 3.;
// ----------------------------------------------------------------
// *** The color of minimap ping
constant integer PORTAL_MINIMAP_PING_RED = 180;
constant integer PORTAL_MINIMAP_PING_GREEN = 23;
constant integer PORTAL_MINIMAP_PING_BLUE = 240;
// ==========================================================================
//
// *** Camera pan Constants ***
//
// ==========================================================================
// ----------------------------------------------------------------
// *** Camera pan is triggered when there are no more player units in area around source portal
constant boolean DO_CAMERA_PAN = true;
// ----------------------------------------------------------------
// *** This is the radius of camera scanning, where it will search for player units
constant real CAMERA_PAN_AREA_SCAN = 700.;
// ----------------------------------------------------------------
// *** The time it takes after last unit enters the portal to pan the camera
constant real CAMERA_PAN_DELAY = 1.5;
// ==========================================================================
//
// *** After Image Constants ***
//
// ==========================================================================
// ----------------------------------------------------------------
// *** Do use after imaging, will show transparent unit entering the portal
constant boolean USE_UNIT_AFTER_IMAGING = true;
// ----------------------------------------------------------------
// *** The time image lasts
constant real UNIT_AFTER_IMAGE_DURATION = .85;
// ----------------------------------------------------------------
// *** Animation speed of image, 1. is 100. percent
constant real UNIT_AFTER_IMAGE_TIMESCALE = .5;
// ----------------------------------------------------------------
// *** The color of image
constant integer UNIT_AFTER_IMAGE_RED = 128;
constant integer UNIT_AFTER_IMAGE_GREEN = 128;
constant integer UNIT_AFTER_IMAGE_BLUE = 128;
// ----------------------------------------------------------------
// *** The starting transparency in percentage of image, 100. is fully visible
constant real UNIT_AFTER_IMAGE_TRANSPARENCY_MIN = 60.;
constant real UNIT_AFTER_IMAGE_TRANSPARENCY_MAX = 70.;
// =================================================================================
//
// *** Enable custom selection, units that are teleported to target portal get
// selected by owning player if they where selected when they entered source portal
constant boolean DO_UNIT_SELECTION_JOB = true;
// ----------------------------------------------------------------
// *** How often to check should units be selected, that is did all units enter source portal
constant real SELECTION_CHECK_INTERVAL = .5;
// ----------------------------------------------------------------
// *** non-Editable, do not change ***
//constant integer BLIZZARD_MAX_SOUND_INSTANCES = 4;
constant key CASTER_FACING_KEY;
constant key UNIT_PORT_KEY;
constant key CASTER_PORTS_KEY;
constant key UNIT_SELECTED_KEY;
constant key UNIT_SELECTION_GROUPING_KEY;
// -------------------------------------------
// *** Portal level constants
// -------------------------------------------
// Portal duration in seconds
function PORTAL_DURATION(integer level) -> real {
real dur[];
dur[1] = 10.;
dur[2] = 15.;
dur[3] = 20.;
return dur[level];
}
// Portal units transition time in seconds
function PORTAL_TRANSITION_TIME(integer level) -> real {
real trans_tim[];
trans_tim[1] = 5.;
trans_tim[2] = 4.;
trans_tim[3] = 2.;
return trans_tim[level];
}
// Portal max units pass
function PORTAL_MAX_PASS(integer level) -> integer {
integer max_pass[];
max_pass[1] = 3;
max_pass[2] = 7;
max_pass[3] = 15;
return max_pass[level];
}
// ----------------------------------------
// **** Unit filter for portal
function PortFilter(unit filter_unit, player cast_player) -> boolean {
return !IsUnitType(filter_unit, UNIT_TYPE_DEAD) &&
!IsUnitType(filter_unit, UNIT_TYPE_STRUCTURE) &&
!IsUnitType(filter_unit, UNIT_TYPE_ANCIENT) &&
!IsUnitType(filter_unit, UNIT_TYPE_POLYMORPHED) &&
!IsUnitType(filter_unit, UNIT_TYPE_FLYING) &&
!DDIsUnitWard(filter_unit) &&
IsUnitAlly(filter_unit, cast_player);
}
// ==================================================================================================
// -------------- --------------
// *** End constant spell modification, start spell code ***
// -------------- --------------
// ==================================================================================================
/// Check if target unit is in rectangle, x, y and degrees depend on portal, while length and width are constants
function IsUnitInRectangle(unit u, real x, real y, real degrees) -> boolean {
real ux = GetUnitX(u), uy = GetUnitY(u);
real minx = x-(PORTAL_LENGTH*.5), miny = y-(PORTAL_WIDTH*.5); // Min and max x,y from normal rect
real maxx = x+(PORTAL_LENGTH*.5), maxy = y+(PORTAL_WIDTH*.5);
real range = SquareRoot(Pw_2(x-ux) + Pw_2(y-uy)); // Distance between center of rect and target unit
real radians = Atan2(uy-y, ux-x); // Angle between center of rect and target unit
/// convert unit angle to rect normal
ux = x + range * Cos(radians-(degrees*bj_DEGTORAD));
uy = y + range * Sin(radians-(degrees*bj_DEGTORAD));
return (ux > minx && ux < maxx) && (uy > miny && uy < maxy);
}
// --------------------------------------------------------
// Since portals are rects under angle, proper movement/teleportation from one portal to another has to be calculated
// sx = source rectangle x
// tx = target rectangle x
function TranslateUnitFromRectangleToRectangle( unit u,
real sx, real sy, real sdegrees,
real tx, real ty, real tdegrees)
{
real ux = GetUnitX(u), uy = GetUnitY(u);
real range = SquareRoot(Pw_2(sx-ux) + Pw_2(sy-uy)); // Distance between center of source rect and target unit
real tradians_shift = -Atan2(uy-sy, ux-sx) + (tdegrees+sdegrees+180.)*bj_DEGTORAD; // Target angle between center of source rect and target unit shifted to target rect
/*
BJDebugMsg(R2S(sdegrees));
BJDebugMsg(R2S(tdegrees));
BJDebugMsg(R2S(-Atan2(uy-sy, ux-sx)*bj_RADTODEG));
BJDebugMsg(R2S(tradians_shift*bj_RADTODEG));
*/
/// convert unit to target rect
ux = tx + range * Cos(tradians_shift);
uy = ty + range * Sin(tradians_shift);
// ** Set unit position and shift his angle to cause portal unit shattering, so that units are more organised
// * Unit will continue moving in direction of his shift facing when ported
SetUnitX(u, ux); SetUnitY(u, uy);
SetUnitFacing(u, -GetUnitFacing(u) + (tdegrees+sdegrees));
}
// ========================================================================
// *** After imaging code
struct unitimage {
private {
unit u;
real trans;
real t_spd;
static constant player IMAGE_OWNER = Player(15);
}
public static method CreateAfterImage(unit target, real x, real y) {
thistype this = allocate();
real fac = GetUnitFacing(target);
u = CreateUnit(IMAGE_OWNER, GetUnitTypeId(target), 0., 0., fac);
UnitAddAbility(u, 'Aloc');
SetUnitPathing(u, false);
//PauseUnit(u, true);
SetUnitTimeScale(u, UNIT_AFTER_IMAGE_TIMESCALE);
SetUnitX(u, x - 90. * Cos(fac*bj_DEGTORAD)); SetUnitY(u, y - 90. * Sin(fac*bj_DEGTORAD));
SetUnitVertexColor(u, UNIT_AFTER_IMAGE_RED, UNIT_AFTER_IMAGE_GREEN, UNIT_AFTER_IMAGE_BLUE, 255);
//SetUnitAnimation(u, UNIT_AFTER_IMAGE_ANIMATION);
//QueueUnitAnimation(u, UNIT_AFTER_IMAGE_ANIMATION);
SetUnitMoveSpeed(u, 1.);
IssuePointOrder(u, "move", x + 100. * Cos(fac*bj_DEGTORAD), y + 100. * Sin(fac*bj_DEGTORAD));
SetUnitColor(u, GetPlayerColor(GetOwningPlayer(target)));
trans = GetRandomReal(UNIT_AFTER_IMAGE_TRANSPARENCY_MIN, UNIT_AFTER_IMAGE_TRANSPARENCY_MAX);
t_spd = DD_INTERVAL*trans/UNIT_AFTER_IMAGE_DURATION;
DDStartTim(DD_INTERVAL, true, this, function() {
thistype this = DDTimData();
trans -= t_spd;
SetUnitVertexColor(u, UNIT_AFTER_IMAGE_RED, UNIT_AFTER_IMAGE_GREEN, UNIT_AFTER_IMAGE_BLUE, R2I(trans*2.55));
if (trans <= 0.) {
RemoveUnit(u);
u = null;
destroy();
DDQuitTim();
}
});
}
}
// ========================================================================
// *** Primary portal code
struct portal {
private {
unit p;
real x, y, degrees;
real tx, ty, tdegrees;
integer lvl;
integer cpass; // current unit passed through portal
timer t;
rect pr; // pick rect
portal lnk;
sound amb;
integer trans_units; // number of units being transiting at a time
real cpass_timeout;
static constant real DIAGONAL = SquareRoot((PORTAL_LENGTH*PORTAL_LENGTH) + (PORTAL_WIDTH*PORTAL_WIDTH));
static constant real ALPHA = Atan(PORTAL_WIDTH/PORTAL_LENGTH);
//static sound SList[];
//static integer SN = 0;
//static player TempP = null;
static boolean TempBool = false;
// *** selection vars ***
static group SctG = CreateGroup();
static timer SctT = CreateTimer();
}
private static method Min4x(real a, real b, real c, real d) -> real {
if (a < b && a < c && a < d)
return a;
else if (b < c && b < d)
return b;
else if (c < d)
return c;
return d;
}
private static method Max4x(real a, real b, real c, real d) -> real {
if (a > b && a > c && a > d)
return a;
else if (b > c && b > d)
return b;
else if (c > d)
return c;
return d;
}
private static method RectangleToRect(real x, real y, real rrad) -> rect {
real x1 = x + (DIAGONAL * Cos(rrad+ALPHA)*.5),
x2 = x + (DIAGONAL * Cos(rrad-ALPHA)*.5),
x3 = x + (DIAGONAL * Cos(rrad+bj_PI+ALPHA)*.5),
x4 = x + (DIAGONAL * Cos(rrad+bj_PI-ALPHA)*.5);
real y1 = y + (DIAGONAL * Sin(rrad+ALPHA)*.5),
y2 = y + (DIAGONAL * Sin(rrad-ALPHA)*.5),
y3 = y + (DIAGONAL * Sin(rrad+bj_PI+ALPHA)*.5),
y4 = y + (DIAGONAL * Sin(rrad+bj_PI-ALPHA)*.5);
return Rect(Min4x(x1, x2, x3, x4), Min4x(y1, y2, y3, y4),
Max4x(x1, x2, x3, x4), Max4x(y1, y2, y3, y4));
}
// ----------------------------------
// * Constructor
static method create(player p, integer lvl, real x, real y, real degrees, real tx, real ty, real tdegrees) -> thistype {
thistype this = allocate();
this.p = CreateUnit(p, PORTAL_ID, x, y, degrees+90.);
PauseUnit(this.p, true);
SetUnitAnimation(this.p, PORTAL_ANIM_BIRTH);
QueueUnitAnimation(this.p, PORTAL_ANIM_STAND);
this.x = x;
this.y = y;
this.degrees = degrees;
this.tx = tx;
this.ty = ty;
this.tdegrees = tdegrees;
this.lvl = lvl;
this.cpass = 0;
this.trans_units = 0;
this.pr = RectangleToRect(x, y, bj_DEGTORAD*degrees);
this.cpass_timeout = PORTAL_TRANSITION_TIME(lvl);
//test();
return this;
}
// ----------------------------------
// * Destructor
method destroy() {
if (t != null) {
PauseTimer(t);
DDRecycleTim(t);
t = null;
}
StopSound(amb, true, true);
KillUnit(p);
RemoveRect(pr);
p = null;
pr = null;
amb = null;
deallocate();
}
// ------------------------------------------
private method PlayPortalEntranceSound() {
DDGenericSound(PORTAL_ENTRANCE_SOUND_FILE, PORTAL_ENTRANCE_SOUND_VOLUME, x, y, SOUND_MAX_DISTANCE, 1.);
/*if (GetSoundIsPlaying(SList[SN]))
StopSound(SList[SN], true, false);
SList[SN] = CreateSound(PORTAL_ENTRANCE_SOUND_FILE, false, true, true, 10, 10, "DefaultEAXON");
SetSoundVolume(SList[SN], R2I(PORTAL_ENTRANCE_SOUND_VOLUME*1.27));
SetSoundPosition(SList[SN], x, y, 0.);
StartSound(SList[SN]);
KillSoundWhenDone(SList[SN]);
SN = ModuloInteger(SN + 1, BLIZZARD_MAX_SOUND_INSTANCES);*/
}
// ------------------------------------------
public method PlayPortalDeathSound() {
DDGenericSound(PORTAL_DEATH_SOUND_FILE, PORTAL_DEATH_SOUND_VOLUME, x, y, SOUND_MAX_DISTANCE, 1.);
//PlayBasicSound.evaluate(PORTAL_DEATH_SOUND_FILE, true, PORTAL_DEATH_SOUND_VOLUME, x, y, null);
}
// ------------------------------------------
private method PlayPortalAmbienceSound() {
if (amb == null) {
amb = CreateSound(PORTAL_AMBIENCE_SOUND_FILE, true, true, true, 10, 10, "DoodadsEAX");
SetSoundVolume(amb, R2I(PORTAL_AMBIENCE_SOUND_VOLUME*1.27));
SetSoundPosition(amb, x, y, 0.);
SetSoundDistanceCutoff(amb, 3500.);
StartSound(amb);
}
}
// *** Checks if player units are around source portal
private method IsSrcPortalClear(player p) -> boolean {
//TempP = p;
TempBool = false;
// *** Check if there are any remaining units
DDGroupFilterArea(x, y, CAMERA_PAN_AREA_SCAN, GetPlayerId(p), function() -> boolean {
TempBool = TempBool || (GetUnitAbilityLevel(GetFilterUnit(), 'Aloc') == 0 && PortFilter(GetFilterUnit(), Player(DDGFilterData())));
return false;
});
return !TempBool;
}
// ------------------------------------------
private method DoSelectJob(unit u, boolean select) {
player p = GetOwningPlayer(u);
if (!select) {
DDSet(u, UNIT_SELECTED_KEY, 0);
if (IsUnitSelected(u, p)) {
DDSet(u, UNIT_SELECTED_KEY, 1);
SelectUnit(u, false);
if (IsUnitInGroup(u, SctG))
GroupRemoveUnit(SctG, u);
}
} else {
if (DDGet(u, UNIT_SELECTED_KEY) == 1) {
if (IsSrcPortalClear(p)) {
if (GetLocalPlayer() == p)
SelectUnit(u, true);
} else {
// *** more units are awaiting to be ported delay the selection
//BJDebugMsg(GetUnitName(FirstOfGroup(SctG)));
if (FirstOfGroup(SctG) == null) {
TimerStart(SctT, SELECTION_CHECK_INTERVAL, true, function() {
//integer i;
// ------------------------------------
// *** reset player portal clear vars
//for(i=0; i < 0xD; i+=1)
// SctPClr[i] = 0;
// ------------------------------------
// *** loop through units ***
ForGroup(SctG, function() {
unit u = GetEnumUnit();
player p = GetOwningPlayer(u);
portal pt = DDGet(u, UNIT_SELECTION_GROUPING_KEY);
//integer pid = GetPlayerId(p);
// *** here we do not use just 0 and 1, but 0, 1 and 2, to optimize the code
// *** requiering only min calls of "IsSrcPortalClear"
/*
if (SctPClr[pid] == 0) {
SctPClr[pid] = 1;
if (IsSrcPortalClear(p))
SctPClr[pid] = 2;
}
*/
// *** if portal is clear, do selection now
if (pt.IsSrcPortalClear(p) || IsUnitType(pt.p, UNIT_TYPE_DEAD)) {
if (GetLocalPlayer() == p)
SelectUnit(u, true);
GroupRemoveUnit(SctG, u);
}
u = null;
});
// *** pause timer???
if (FirstOfGroup(SctG) == null) {
PauseTimer(SctT);
}
});
}
DDSet(u, UNIT_SELECTION_GROUPING_KEY, this);
GroupAddUnit(SctG, u);
}
}
}
}
// ------------------------------------------
private method AttemptCameraPan(player p) {
p_integer pi;
// *** If no more units remains do pan camera
if (IsSrcPortalClear(p)) {
pi = p_integer.create();
pi[0] = lnk;
pi[1] = GetPlayerId(p);
DDStartTim(CAMERA_PAN_DELAY, false, pi, function() {
p_integer pi = DDTimData();
if (GetLocalPlayer() == Player(pi[1]))
SetCameraPosition(portal(pi[0]).x, portal(pi[0]).y);
pi.destroy();
});
}
}
// --------------------------------------------
// *** Periodic port timer system
//
public method StartPortSys() {
t = DDStartTim(PORT_CHECK_INTERVAL, true, this, static method()
{
thistype this = DDTimData();
real elapsed = DDTimTick()*PORT_CHECK_INTERVAL;
integer i = 0;
real dur = PORTAL_DURATION(lvl);
real trans_time = PORTAL_TRANSITION_TIME(lvl);
integer max_pass = PORTAL_MAX_PASS(lvl);
p_integer pi;
// ------------------------------------------------------
// *** Add the code for minimap ping if wanted
static if (PORTAL_USE_MINIMAP_PING) {
if (ModuloInteger(R2I(elapsed*10.), R2I(PORTAL_MINIMAP_PING_INTERVAL*10.)) == 1)
if (GetLocalPlayer() == GetOwningPlayer(p)) {
PingMinimapEx(x, y, PORTAL_MINIMAP_PING_DURATION, PORTAL_MINIMAP_PING_RED, PORTAL_MINIMAP_PING_GREEN, PORTAL_MINIMAP_PING_BLUE, false);
PingMinimapEx(tx, ty, PORTAL_MINIMAP_PING_DURATION, PORTAL_MINIMAP_PING_RED, PORTAL_MINIMAP_PING_GREEN, PORTAL_MINIMAP_PING_BLUE, false);
}
}
// ------------------------------------------------------
// --------------------
// *** Can port?, elapsed must be between bortal finish birth and from that point + portal duration
// *** number of passed units between linked portals must be lower than constant specifies depending on level
if (elapsed > PORTAL_ANIM_BIRTH_DURATION && elapsed < dur+PORTAL_ANIM_BIRTH_DURATION &&
cpass+lnk.cpass < max_pass)
{
PlayPortalAmbienceSound();
// --------------------------------------------------
// *** pick all units to be ported ***
DDGroupFillMemRect(pr, this, static method() -> boolean {
portal this = DDMemUnitData();
// *** Unit is in rectangle and whas not ported reacently
if (IsUnitInRectangle(GetFilterUnit(), x, y, degrees) && DDGet(GetFilterUnit(), UNIT_PORT_KEY) == 0)
return PortFilter(GetFilterUnit(), GetOwningPlayer(p));
return false;
});
// --------------------------------------------------
// *** Port all units in portal area ***
while(i < DDMemUnitN()) {
if (!IssueImmediateOrder(DDMemUnit(i), "stop"))
debug BJDebugMsg("Portal: Fail to stop unit!");
static if (DO_UNIT_SELECTION_JOB)
DoSelectJob(DDMemUnit(i), false);
static if (USE_UNIT_AFTER_IMAGING)
unitimage.CreateAfterImage(DDMemUnit(i), GetUnitX(DDMemUnit(i)), GetUnitY(DDMemUnit(i)));
TranslateUnitFromRectangleToRectangle(DDMemUnit(i), x, y, degrees, tx, ty, tdegrees);
ShowUnit(DDMemUnit(i), false);
PlayPortalEntranceSound();
trans_units += 1;
lnk.trans_units += 1;
static if (DO_CAMERA_PAN)
AttemptCameraPan(GetOwningPlayer(DDMemUnit(i)));
DDSet(DDMemUnit(i), UNIT_PORT_KEY, 1);
// ---------------------------------------------------------
// *** Transition time
pi = p_integer.create();
pi[0] = New_pUnit(DDMemUnit(i));
pi[1] = this.lnk;
pi[2] = this;
DDStartTim(trans_time, false, pi, static method() {
p_integer pi = DDTimData();
p_unit pu = pi[0];
real dist = GetRandomReal(UNIT_PORT_WALK_OFFSET_MIN, UNIT_PORT_WALK_OFFSET_MAX);
real fac = GetUnitFacing(pu[0]);
portal(pi[1]).trans_units -= 1;
portal(pi[2]).trans_units -= 1;
portal(pi[1]).PlayPortalEntranceSound();
ShowUnit(pu[0], true);
IssuePointOrder(pu[0], "move", GetUnitX(pu[0]) + dist * Cos(fac*bj_DEGTORAD),
GetUnitY(pu[0]) + dist * Sin(fac*bj_DEGTORAD));
// *** Make unit to be able to port again ***
TimerStart(GetExpiredTimer(), UNIT_NEXT_PORT_DELAY, false, static method() {
p_integer pi = DDTimData();
p_unit pu = pi[0];
DDSet(pu[0], UNIT_PORT_KEY, 0);
pi.destroy();
pu.destroy();
DDQuitTim();
});
static if (DO_UNIT_SELECTION_JOB) {
thistype(pi[2]).DoSelectJob(p_unit(pi[0])[0], true);
}
});
// ---------------------------------------------------------
cpass += 1;
i += 1;
}
}
// *** Portal end if max pass reached or
if ((elapsed > PORTAL_ANIM_BIRTH_DURATION + dur /*+ trans_time*/) || (cpass + lnk.cpass >= max_pass)) {
/*
if (cpass + lnk.cpass >= max_pass)
cpass_timeout -= PORT_CHECK_INTERVAL;
else
cpass_timeout = 0.;
*/
//debug BJDebugMsg(I2S(trans_units));
if (/*cpass_timeout <= 0. ||*/ trans_units == 0) {
DDStartTim(DESTROY_PORTAL_DELAY, false, this, function() {
portal this = DDTimData();
PlayPortalDeathSound();
t = null;
this.destroy();
DDQuitTim();
});
DDQuitTim();
}
}
});
}
// *** links with other portal
method operator link=(portal p) { lnk = p; }
method operator Elapsed() -> real { return DDCTimTick(t)*PORT_CHECK_INTERVAL; }
}
// ================================================================================
//
// *** Extra spell functions ***
//
// ================================================================================
// ------------------------------------------
// *** Rounds positive integer
function Round(real x) -> integer {
if (x-I2R(R2I(x)) > .5)
return R2I(x)+1;
return R2I(x);
}
function onInit() {
trigger t = CreateTrigger();
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST);
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT);
TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_ENDCAST);
TriggerAddCondition(t, function() -> boolean {
// ----------------------------------------
// *** Locals ***
unit u;
sound s;
player p;
integer lvl;
real ux, uy;
real tx, ty;
real x, y, rads;
p_real fac;
p_integer pt;
// ----------------------------------------
// *** Condition ***
if (GetSpellAbilityId() != SPELL_ID)
return false;
// ----------------------------------------
// *** Actions ***
// ====================================================================
// *** Start cast event ***
// ====================================================================
if (GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_CAST) {
u = GetTriggerUnit();
if (IsUnitInRangeXY(u, GetSpellTargetX(), GetSpellTargetY(), SECOND_PORTAL_MIN_RANGE)) {
IssuePointOrder(u, "move", GetUnitX(u) + 50. * Cos(GetUnitFacing(u)*bj_DEGTORAD), GetUnitY(u) + 50. * Sin(GetUnitFacing(u)*bj_DEGTORAD));
DisplayTimedTextFromPlayer(GetOwningPlayer(u), 0., 0., PORTAL_WARNING_MESSAGE_DURATION, "|cffff0020"+PORTAL_WARNING_MESSAGE+"|r");
if (GetLocalPlayer() == GetOwningPlayer(u)) {
s = CreateSound(PORTAL_WARNING_SOUND_FILE, false, false, false, 10, 10, "");
SetSoundVolume(s, R2I(PORTAL_WARNING_SOUND_VOLUME*1.27));
StartSound(s);
KillSoundWhenDone(s);
s = null;
}
//PlayBasicSound(PORTAL_WARNING_SOUND_FILE, false, PORTAL_WARNING_SOUND_VOLUME, 0., 0., GetOwningPlayer(u));
DDSet(u, CASTER_FACING_KEY, 0);
} else
DDSet(u, CASTER_FACING_KEY, New_pReal(GetUnitFacing(u)));
u = null;
return false;
}
// ====================================================================
// *** End cast event ***
// ====================================================================
if (GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_ENDCAST) {
u = GetTriggerUnit();
// *** Fail to cast spell?
pt = DDGet(u, CASTER_PORTS_KEY);
if (pt == 00) {
u = null;
return false;
}
// *** End spell if portal whas not channeled fully
// * Use round and increase precission by 10x, meaning that cast times like 7.64 will be 7.6, as real values are unsafe to be compared
if (Round(portal(pt[0]).Elapsed*10.) < Round(PORTAL_ANIM_BIRTH_DURATION*10.)) {
portal(pt[0]).PlayPortalDeathSound();
portal(pt[1]).PlayPortalDeathSound();
portal(pt[0]).destroy();
portal(pt[1]).destroy();
}
pt.destroy();
u = null;
return false;
}
// ====================================================================
// ====================================================================
// *** Start cast effect event ***
// ====================================================================
u = GetTriggerUnit();
p = GetOwningPlayer(u);
lvl = GetUnitAbilityLevel(u, SPELL_ID);
fac = DDGet(u, CASTER_FACING_KEY);
ux = GetUnitX(u); uy = GetUnitY(u);
tx = GetSpellTargetX(); ty = GetSpellTargetY();
rads = Atan2(-uy+ty, -ux+tx);
x = ux + FIRST_PORTAL_OFFSET * Cos(rads);
y = uy + FIRST_PORTAL_OFFSET * Sin(rads);
pt = p_integer.create();
pt[0] = portal.create(p, lvl, x, y, (rads*bj_RADTODEG)+90., tx, ty, fac[0]-90.);
pt[1] = portal.create(p, lvl, tx, ty, fac[0]-90., x, y, (rads*bj_RADTODEG)+90.);
portal(pt[0]).link = pt[1];
portal(pt[1]).link = pt[0];
portal(pt[0]).StartPortSys();
portal(pt[1]).StartPortSys();
DDSet(u, CASTER_PORTS_KEY, pt);
DDGenericSound(PORTAL_BIRTH_SOUND_FILE, PORTAL_BIRTH_SOUND_VOLUME, x, y, SOUND_MAX_DISTANCE, 1.);
DDGenericSound(PORTAL_BIRTH_SOUND_FILE, PORTAL_BIRTH_SOUND_VOLUME, tx, ty, SOUND_MAX_DISTANCE, 1.);
fac.destroy();
u = null;
return false;
});
}
}
//! endzinc
// ============================================================================================
// Change me from /* to // and then back to /* after saving and reopening the map
// |
// ˇ
/*
// Credits: PurgeandFire for lua tutorial
//! externalblock extension=lua ObjectMerger $FILENAME$
//! i -- =========================================================
//! i SHIMMERING_PORTAL_ABIL_ID = "SPrt"
//! i SHIMMERING_PORTAL_DUMMY_ID = "port"
//! i -- =========================================================
//! i -- -----------------------------------------------
//! i --Ability Create Code
//! i setobjecttype("abilities")
//! i createobject("ANto", SHIMMERING_PORTAL_ABIL_ID)
//! i makechange(current,"anam", "Shimmering Portal")
//! i makechange(current,"aart", "ReplaceableTextures\\CommandButtons\\BTNPortal.blp")
//! i makechange(current,"arar", "ReplaceableTextures\\CommandButtons\\BTNPortal.blp")
//! i makechange(current,"aani", "channel")
//! i makechange(current,"alev", "3")
//! i makechange(current,"arlv", "1")
//! i makechange(current,"ahky", "H")
//! i makechange(current,"arhk", "H")
//! i makechange(current,"aret", "Learn S|cff8000ffh|rimmering Portal - [|cffffcc00Level ".. string.char(37) .."d|r]")
//! i makechange(current,"arut", "|cffb300b3Opens portal allowing any ground unit to pass through.|n|r|n|cff408080[Level 1]|r - Portal lasts 10 seconds, up to 3 units can pass, 5 seconds transition time, cooldown 30 seconds.|n|cff408080[Level 2]|r - Portal lasts 15 seconds, up to 7 units can pass, 4 seconds transition time, cooldown 20 seconds.|n|cff408080[Level 3]|r - Portal lasts 20 seconds, up to 12 units can pass, 2 seconds transition time, cooldown 10 seconds.|n|n|cffb00000Channeling|r")
//! i makechange(current,"aub1","1","|cffb300b3Portal lasts 10 seconds, up to 3 units can pass, 5 seconds transition time, cooldown 30 seconds.|r")
//! i makechange(current,"aub1","2","|cffb300b3Portal lasts 15 seconds, up to 7 units can pass, 4 seconds transition time, cooldown 20 seconds.|r")
//! i makechange(current,"aub1","3","|cffb300b3Portal lasts 20 seconds, up to 12 units can pass, 2 seconds transition time, cooldown 10 seconds.|r")
//! i local i = 0
//! i for i=1, 3 do
//! i local si = tostring(i)
//! i makechange(current,"Ntou",si,"")
//! i makechange(current,"aran",si,"99999.")
//! i makechange(current,"acdn",si,tostring(10*(4-i)))
//! i makechange(current,"adur",si,"7.5")
//! i makechange(current,"ahdu",si,"7.5")
//! i makechange(current,"amcs",si,"100")
//! i makechange(current,"atp1",si,"S|cff8000ffh|rimmering Portal - [|cffffcc00Level ".. si .."|r]")
//! i end
//! i -- -----------------------------------------------
//! i --Dummy Create Code
//! i setobjecttype("units")
//! i createobject("hpea", SHIMMERING_PORTAL_DUMMY_ID)
//! i makechange(current, "uabi", "Avul,Aloc")
//! i makechange(current, "udtm", "5.77")
//! i makechange(current, "uico", "ReplaceableTextures\\CommandButtons\\BTNPortal.blp")
//! i makechange(current, "umdl", "Doodads\\Cinematic\\ShimmeringPortal\\ShimmeringPortal.mdl")
//! i makechange(current, "umxp", "0.")
//! i makechange(current, "umxr", "0.")
//! i makechange(current, "ushu", "")
//! i makechange(current, "ua1t", "")
//! i makechange(current, "udea", string.char(2))
//! i makechange(current, "umvt", "")
//! i makechange(current, "ucol", "0.")
//! i makechange(current, "ufoo", "0")
//! i makechange(current, "usid", "1200")
//! i makechange(current, "usin", "1200")
//! i makechange(current, "unam", "Portal")
//! i makechange(current, "unsf", " (Dummy)")
//! endexternalblock
*/
// ^
// |
// Change me from */ to // and then back to */ after saving and reopening the map
// ============================================================================================