///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
fireNova(key target) {
float V0 = llGetRegionFPS()/2.0;
vector target = llList2Vector(llGetObjectDetails(target, [OBJECT_POS]), 0);
vector origin = llGetPos();
float dΔ=llVecDist(<target.x,target.y,0>,<origin.x,origin.y,0>);
float valSin = 9.81*dΔ/llPow(V0, 2);
if(valSin < -1 || valSin > 1) return;
rotation qΔ = llRotBetween(<1,0,0>,llVecNorm(<target.x-origin.x,target.y-origin.y, dΔ*llTan((RAD_TO_DEG*llAsin(valSin)/2) * DEG_TO_RAD) + target.z-origin.z>));
llRezObject("[K] Plugin:Nova - Bomb", llGetLocalPos(), llVecNorm(<1,0,0>*qΔ)*V0, qΔ, 0);
}
list cmd = [];
integer failFind = 5;
default {
link_message(integer sender_num, integer num, string str, key id) {
cmd = llCSV2List(str);
if(llList2String(cmd,1) != "nova") return;
llMessageLinked(LINK_THIS, 0, "glow:MAIN:HALT", NULL_KEY);
state nova;
}
on_rez(integer num) {
llResetScript();
}
}
state nova {
state_entry() {
llInstantMessage(llGetOwner(), "Attack!");
llSetStatus(STATUS_PHYSICS, FALSE);
failFind = 5;
llSensorRepeat(llList2String(cmd,2) + " " + llList2String(cmd,3), "", AGENT, 64, TWO_PI, 1);
}
sensor(integer num) {
failFind = 5;
llLookAt(llDetectedPos(0), .5, 1);
fireNova(llDetectedKey(0));
}
link_message(integer sender_num, integer num, string str, key id) {
if(str != "glow:PLUG:HALT") return;
llSensorRemove();
llStopLookAt();
llMessageLinked(LINK_THIS, 0, "glow:MAIN:CONT", NULL_KEY);
llSetRot(llEuler2Rot(<0,90,0> * DEG_TO_RAD));
state default;
}
no_sensor() {
--failFind;
if(failFind) return;
llSensorRemove();
llStopLookAt();
llMessageLinked(LINK_THIS, 0, "glow:MAIN:CONT", NULL_KEY);
llSetRot(llEuler2Rot(<0,90,0> * DEG_TO_RAD));
state default;
}
on_rez(integer num) {
llResetScript();
}
}