Initial tree implementation
This commit is contained in:
parent
3dbc618418
commit
45d200e6ba
1 changed files with 149 additions and 4 deletions
153
LSL/raw/tree.lsl
153
LSL/raw/tree.lsl
|
@ -1,13 +1,158 @@
|
||||||
#include "Common.lsl"
|
#include "Common.lsl"
|
||||||
|
|
||||||
integer g_iStartedGrowing;
|
integer g_iTreeStage;
|
||||||
integer g_iWater;
|
integer g_iTreeGrowth;
|
||||||
|
integer g_iTotalWater;
|
||||||
|
|
||||||
|
float g_fMaxTreeSize = 10.0; // Maximum tree size
|
||||||
|
float g_fMaxGrowth = 150.0; // Maximum growth value
|
||||||
|
integer g_iLastGrowthStep = 0;
|
||||||
|
|
||||||
|
integer g_iLastUsedWater;
|
||||||
|
|
||||||
|
|
||||||
|
integer g_iTree;
|
||||||
|
integer g_iTreeStump;
|
||||||
|
integer g_iSapling;
|
||||||
|
|
||||||
|
vector g_vInitialSapling = <0.59996, 0.56265, 1.01659>;
|
||||||
|
vector g_vInitialTree = <0.77864, 0.90290, 1.38959>;
|
||||||
|
vector g_vInitialStump = <0.14584, 0.14018, 0.05000>;
|
||||||
|
|
||||||
|
|
||||||
|
SCAN() {
|
||||||
|
integer i=0;
|
||||||
|
integer end = llGetNumberOfPrims();
|
||||||
|
|
||||||
|
for(i=LINK_ROOT;i<=end;i++) {
|
||||||
|
string sName = llGetLinkName(i);
|
||||||
|
if(sName == "stump") g_iTreeStump = i;
|
||||||
|
if(sName == "tree") g_iTree = i;
|
||||||
|
if(sName == "sapling") g_iSapling = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!g_iTree && !g_iTreeStump && !g_iSapling) {
|
||||||
|
llSay(0, "Something has gone wrong with the linkset setup");
|
||||||
|
|
||||||
|
if(!g_iTree) llSay(0, "> Tree Prim");
|
||||||
|
if(!g_iTreeStump) llSay(0, "> Stump Prim");
|
||||||
|
if(!g_iSapling) llSay(0, "> Sapling Prim");
|
||||||
|
|
||||||
|
llSay(0, "Disabling script to prevent damage to linkset");
|
||||||
|
llSetScriptState(llGetScriptName(), FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InitialAppearance() {
|
||||||
|
llSetLinkPrimitiveParams(g_iTreeStump, [PRIM_POS_LOCAL, ZERO_VECTOR, PRIM_SIZE, g_vInitialStump]);
|
||||||
|
llSetLinkPrimitiveParams(g_iTree, [PRIM_POS_LOCAL, <0,-0.035,0.65>, PRIM_SIZE, g_vInitialTree]);
|
||||||
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_POS_LOCAL, <0,0.025,0.45>, PRIM_SIZE, g_vInitialSapling]);
|
||||||
|
llSetLinkPrimitiveParams(LINK_ROOT, [PRIM_SIZE, <0.05,0.05,0.05>]);
|
||||||
|
|
||||||
|
llSetLinkAlpha(g_iTreeStump, 0, ALL_SIDES);
|
||||||
|
llSetLinkAlpha(g_iTree, 0, ALL_SIDES);
|
||||||
|
llSetLinkAlpha(g_iSapling, 1, ALL_SIDES);
|
||||||
|
|
||||||
|
llScaleByFactor(0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
setText() {
|
||||||
|
|
||||||
|
if(g_iTreeStage == 1 && g_iTreeGrowth == 100) {
|
||||||
|
llSetText("", ZERO_VECTOR, 1);
|
||||||
|
}else
|
||||||
|
llSetText("Water: " + (string)g_iTotalWater+"%\nStage: " + (string)g_iTreeStage + "/1" + "\nProgress: " + (string)g_iTreeGrowth+"%\n \n \n \n \n \n \n \n", <1,1,1>,1);
|
||||||
|
}
|
||||||
|
|
||||||
default
|
default
|
||||||
{
|
{
|
||||||
state_entry()
|
state_entry()
|
||||||
{
|
{
|
||||||
g_iStartedGrowing = (integer)llLinksetDataRead("progress");
|
llLinksetDataReset();
|
||||||
g_iWater = (integer)llLinksetDataRead("water");
|
XteaKey(PSK);
|
||||||
|
global_ingredients = getIngredientChannel(NULL_KEY);
|
||||||
|
llSay(0, "Scanning linkset...");
|
||||||
|
SCAN();
|
||||||
|
llSay(0, "Checking permissions...");
|
||||||
|
PROTECT();
|
||||||
|
llSay(0, "Done checking permissions");
|
||||||
|
|
||||||
|
llSay(0, "Setting scale, and hiding parts..");
|
||||||
|
InitialAppearance();
|
||||||
|
|
||||||
|
llSay(0, "Setting value: I need water");
|
||||||
|
g_iTotalWater = 0;
|
||||||
|
llSay(0, "Tree is now thirsty");
|
||||||
|
llSay(0, "Setting growth stage to 0, at 0%");
|
||||||
|
g_iTreeGrowth = 0;
|
||||||
|
g_iTreeStage = 0;
|
||||||
|
llSay(0, "> Timers are not running, they will be started on next rez");
|
||||||
|
llSay(0, "I am now ready to be packaged");
|
||||||
|
llListen(global_ingredients, "", "", "");
|
||||||
|
|
||||||
|
llSay(0, "DEBUG MODE DETECTED.\n\n[ STARTING TIMERS ]");
|
||||||
|
llSetTimerEvent(1);
|
||||||
|
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
|
||||||
|
timer() {
|
||||||
|
if(llGetUnixTime() > g_iLastUsedWater+5)
|
||||||
|
llWhisper(global_ingredients, xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "query"])));
|
||||||
|
|
||||||
|
if(llGetUnixTime() > g_iLastGrowthStep + 120) {
|
||||||
|
|
||||||
|
if(g_iTotalWater == 0) return;
|
||||||
|
|
||||||
|
g_iLastGrowthStep = llGetUnixTime();
|
||||||
|
integer iRoll = llRound(llFrand(100));
|
||||||
|
if((iRoll % 2) == 0) {
|
||||||
|
// Bump growth
|
||||||
|
g_iTreeGrowth++;
|
||||||
|
if(g_iTreeStage)
|
||||||
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_SIZE,ZERO_VECTOR]);
|
||||||
|
|
||||||
|
llScaleByFactor(1.0225);
|
||||||
|
|
||||||
|
setText();
|
||||||
|
|
||||||
|
iRoll = llRound(llFrand(100));
|
||||||
|
if((iRoll%2)==0) {
|
||||||
|
g_iTotalWater--;
|
||||||
|
|
||||||
|
if(g_iTotalWater <= 0) g_iTotalWater = 0;
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(g_iTreeGrowth == 100) {
|
||||||
|
g_iTreeStage++;
|
||||||
|
g_iTreeGrowth = 0;
|
||||||
|
llSetLinkAlpha(g_iSapling,0, ALL_SIDES);
|
||||||
|
llSetLinkAlpha(g_iTree,1,ALL_SIDES);
|
||||||
|
|
||||||
|
llSetLinkPrimitiveParams(g_iSapling, [PRIM_SIZE,ZERO_VECTOR]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(g_iTreeStage == 1 && g_iTreeGrowth == 100) {
|
||||||
|
llSetTimerEvent(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listen(integer c,string n,key i,string m) {
|
||||||
|
string sJson = xtea_decrypt_string(m);
|
||||||
|
if(llJsonGetValue(sJson, ["cmd"]) == "reply") {
|
||||||
|
if(llJsonGetValue(sJson, ["ingredient"]) == "Water") {
|
||||||
|
if(g_iTotalWater <= 75 && llGetUnixTime() > g_iLastUsedWater + 5) {
|
||||||
|
|
||||||
|
g_iTotalWater += 25;
|
||||||
|
g_iLastUsedWater = llGetUnixTime();
|
||||||
|
llRegionSayTo(i, getIngredientChannel(i), xtea_encrypt_string(llList2Json(JSON_OBJECT, ["cmd", "use", "id", llJsonGetValue(sJson, ["id"])])));
|
||||||
|
|
||||||
|
setText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue