[Depricated] Trumble Treats - coming soon!

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

While talking about aegis, the word is only a fancy word for protection.

While it makes sense to talk about the station's aegis, meaning that whatever happens in that volume of space is both monitored and acted upon by the station, there ain't such a thing as a sun, planet, or moon aegis, unless someone manages to code a sentient planetary bodies OXP! :P
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

Ah. I have always assumed the eq_trumble was always there whenever there were trumbles onboard. I'm learning much today. :)

..
That vicinity code.
It fires only once? or is it triggered periodically while in aegis?
(The ship won't be hot enough for our purposes when it first triggers it, it takes some time for the effect to be complete too.)

...
What do you guys remember of how the trumble gift was handled in classic ELiTE?
was it a random amount of furs or always a full hold, did they appear while at the sun or as you docked?

I'm thinking of maybe only awarding the furs once in dock (as you would not have, unless you shipped a full hold of food, a full complement of empty containers in deep space.) It would also circumvent the solar timing challenge.


So far have this, which would be called for conditions [trumbleCount = 0 AND less than var AH_trumbleCount].

Code: Select all

this.fryTrumbles = function()
{
	player.consoleMessage("Oh noes! Your careless sundiving has fried your trumbles!");
	if (player.ship.cargoSpaceAvailable <= missionVariables.AH_trumbleCount/1000)
	{
    	player.ship.manifest.furs += player.ship.cargoSpaceAvailable;
	}
	else
	{
		player.ship.manifest.furs += missionVariables.AH_trumbleCount/1000
	}
	if (player.ship.cargoSpaceAvailable === 0)
	{
		player.consoleMessage("Their furry corpses litter every corner of the ship.");
	}
};
The messages would be fun only if sundiving, should we go for the docked trigger, I'd replace them for an ArrivalReport.

edit: aegis. yeh. it has come to mean 'general vicinity' in my vocabulary. :)
Riding the Rocket!
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Arexack_Heretic wrote:
That vicinity code.
It fires only once?
The planetary vicinity event triggers, as the name suggest, when you enter the vicinity of a planetary body, and that happens once.

Once you know you're near the sun, you can set up a timer, firing maybe once every 2 seconds or so. In there you can check if the temperature is high enough, then display the message/collect furs.

You'll also need to kill that timer, using the shipExitedPlanetaryVicinity event too. Inside that you put the code that says: is AH_trumble_timer running? stop that timer now, since we're away from the sun.


The code you've got there is trying to do a bit too much (something that was indeed needed in legacy - the thing is, we're not in legacy script anymore). As it says in the manifest documentation, if you try to add more cargo than you can fit, nothing bad will happen.

Edit: you did forget to reset the number of AH trumbles, though!

Code: Select all

this.fryTrumbles = function()
{
	player.consoleMessage("Oh noes! Your careless sundiving has fried your trumbles!");
	if (player.ship.cargoSpaceAvailable > 0)
	{
		// add as many furs as possible
		player.ship.manifest.furs += missionVariables.AH_trumbleCount/1000
	}
	else
	{
		player.consoleMessage("Their furry corpses litter every corner of the ship.");
	}
	missionVariables.AH_trumbleCount = 0; // they're dead now.
};
Or if you really want to do something fancy:

Code: Select all

this.fryTrumbles = function()
{
	player.consoleMessage("Oh noes! Your careless sundiving has fried your trumbles!");
	var fursToAdd=missionVariables.AH_trumbleCount/1000; // using missionVariables is slow, use them as little as possible.
	if (player.ship.cargoSpaceAvailable > 0)
	{

		if (player.ship.cargoSpaceAvailable < fursToAdd)
		{
			player.consoleMessage("No matter how hard you try, you can't stuff all their corpses in the cargo hold...");
		}
		
		// add as many furs as possible
		player.ship.manifest.furs += fursToAdd;
	}
	else
	{
		player.consoleMessage("Their furry corpses litter every corner of the ship.");
	}
	missionVariables.AH_trumbleCount = 0; // they're dead now.
};
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

hehe. nice.
I would combine the conditions using && as there is no else statement.

I'm still in doubt if I should award furs
-only if they are all gone (as classic did IIRC)
---at the moment they are all dead.
---while docking at a station.
-while they are dying at the sun, as you seem to suggest.
Riding the Rocket!
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

And how comes you can stuff trumble furs into the cargo hold when you can't get gold/gems/platinum out of it and into your safe until you dock?

Personally I'd award them on docking, although may be better to just automatically sell them if the local price of furs is available to script (not sure offhand).
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Arexack_Heretic wrote:
I'm still in doubt if I should award furs
-only if they are all gone (as classic did IIRC)
---at the moment they are all dead.
---while docking at a station.
-while they are dying at the sun, as you seem to suggest.
When you start a timer when close to the sun, you can keep an eye on the "player.trumbleCount" and award fur when detecting a decrease. You won't get all as there might have died two and born one between two timings.
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I know.
I'm asking what I should do, not what i could do,
that was earlier. :wink:
I could also do away with the mV and update a local variable with every check. (it was for use with EQ_TRUMBLE anyhow)

I'm afraid that allowing harvesting of trumblefur before they are all dead, though realistic, may unbalance the game too much.

It will need some testing, but perhaps the idea could be that trumbles are canibalistic.
"Oh the horror! The cuties are dropping dead left and right and their fellows are eating them!"

Only the last round of trumble death would yield fur.
(update the variable untill 0, then run award script. update frequency would be a tweakable parameter, which should end up so that Tn o furs becomes a number between 1 and 127 or so.)

Yeah, I think I'll try that. :)

horrid little monsters. luckilly they don't eat living things or you'd be in trouble yourself... err, do they consume slaves?
Riding the Rocket!
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Svengali wrote:
Yep. that's the way it works.

And a interesting page about loops -> http://4umi.com/web/javascript/optimize.php
By the way, I strongly recommend that you do not follow the coding style suggestions on that page under “Balancing”. Comments and long variable names are a Good Thing for maintainability, and they should have little to no effect on performance. (This is different in a web context, since the scripts have to be downloaded.)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

Code: Select all

this.shipEnteredPlanetaryVicinity = function(planet)
{
    if(planet.isSun)
	{
		log("test","Player enters aegis of sun with radius: "+ planet.radius);
		if (player.trumbleCount>0)
		{
			this.AH_trumbleTimer.start();
		}
    }
    else if(planet.hasAtmosphere)
    {
        log("test","Player enters aegis of planet with radius: "+ planet.radius);
        if (player.trumbleCount>0)
		{
			this.AH_trumbleTimer.start();
		}
	}
    else
        log("test","Player enters aegis of moon with radius: "+ planet.radius) //but who cares?
} 

//shipExitedPlanetaryVicinity : stop timer script
this.shipExitedPlanetaryVicinity = function(planet)
{
    if(planet.isSun)
	{
		log("test","Player leaves aegis of sun with radius: "+ planet.radius);
		this.AH_trumbleTimer.stop();
    }
    else if(planet.hasAtmosphere)
    {
        log("test","Player leaves aegis of planet with radius: "+ planet.radius);
		this.AH_trumbleTimer.stop();
	}
    else
        log("test","Player leaves aegis of moon with radius: "+ planet.radius) //but who cares?
} 

this.AH_trumbleTimer= new Timer(this, this.AH_fryTrumbles(), 0 ,5);
	
	
this.AH_fryTrumbles = function()
{
	if (!ah_trumbleCount){var ah_trumbleCount=player.trumbleCount;};
	if (!ah_trumbles_died){var ah_trumbles_died=0};
	if (player.trumbleCount>0) //There are trumbles onboard.
	{
		if (player.trumbleCount=>ah_trumbleCount) //trumbles are unaffected ... ok
		{
			ah_trumbleCount = player.trumbleCount; //update count
		}
		else //trumbles are dying 
		{
			ah_trumbles_died = ah_trumbleCount-player.trumbleCount; //how many since last round?
			ah_trumbleCount = player.trumbleCount; //update count
			if (!AH_10){var AH_10 = 0}; 
			if (AH_10<10){n+=1} //a comment once every... ten cycles
			else 
			{
				player.consoleMessage(expandDescription("[ah_horror]"));
				AH_10=0; //reset AH_10
			}
		}
	};
	else  //No more trumbles onboard
	{
		//count latest count and award furs. 
		if (ah_trumbleCount>0) //nothing happens if no trumbles died since last cycle.
		{
			if (player.ship.cargoSpaceAvailable > 0)
  			{
				if (player.ship.cargoSpaceAvailable < Math.round(ah_trumbleCount/1000)+1)
				{
					player.consoleMessage("No matter how hard you try, you can't stuff all their corpses in the cargo hold...");
      			}
				player.ship.manifest.furs += Math.round(ah_trumbleCount/1000)+1;
			}
			else
			{
				player.consoleMessage("Their furry corpses litter every corner of the ship.");
			}
			ah_trumbleCount = player.trumbleCount; // or 0.
		}
	}
};
Waddaya think?
The timer object is created in startUp, with a 10s interval.
I hope this is correct use of the timer methods and the timer itself.
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I'll release a v0.00 version, for testing. 8)
edit:See first post.
edit2:uploaded now.
Riding the Rocket!
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

The last function has a problem. When you define a variable inside a function, it is only valid as long you stay in that function. When that function ends, all content of that variables is lost. This is a common feature of languages like Pascal, C, JS etc. That allows for using using variable names inside a function without checking the whole code to see if the variable was used elsewhere also.

To make the variable permanent valid, you must define it at the main level of a script. But for oolite this is risky as the main level is shared between all scripts. That would introduce the need to choose a variable name that is not likely chosen by an other oxp. On the long end that will give problems between oxp's so better not start doing that.

One other way to store values is by making it a so called "property" of your script. Your script is symbolised by the "this" part. When you add something behind it, it becomes part of your script that is available throughout your script but becomes not part of other scripts.

I changes your code a bit in this way by giving your "variables" a starting value in startUp. That way it should work like you intended.

Code: Select all

this.startUp = function ()
{
   this.ah_trumbleCount=player.trumbleCount;
   this.ah_trumbles_died=0;
   this.AH_10 = 0;
}

this.AH_fryTrumbles = function() 
{ 
   if (player.trumbleCount>0) //There are trumbles onboard. 
   { 
      if (player.trumbleCount=> this.ah_trumbleCount) //trumbles are unaffected ... ok 
      { 
         this.ah_trumbleCount = player.trumbleCount; //update count 
      } 
      else //trumbles are dying 
      { 
         this.ah_trumbles_died = this.ah_trumbleCount - player.trumbleCount; //how many since last round? 
         this.ah_trumbleCount = player.trumbleCount; //update count 
         if (this.AH_10<10){this.AH_10 +=1} //a comment once every... ten cycles 
         else 
         { 
            player.consoleMessage(expandDescription("[ah_horror]")); 
            this.AH_10=0; //reset this.AH_10 
         } 
      } 
   }; 
   else  //No more trumbles onboard 
   { 
      //count latest count and award furs. 
      if (this.ah_trumbleCount>0) //nothing happens if no trumbles died since last cycle. 
      { 
         if (player.ship.cargoSpaceAvailable > 0) 
           { 
            if (player.ship.cargoSpaceAvailable < Math.round(this.ah_trumbleCount/1000)+1) 
            { 
               player.consoleMessage("No matter how hard you try, you can't stuff all their corpses in the cargo hold..."); 
               } 
            player.ship.manifest.furs += Math.round(this.ah_trumbleCount/1000)+1; 
         } 
         else 
         { 
            player.consoleMessage("Their furry corpses litter every corner of the ship."); 
         } 
         this.ah_trumbleCount = player.trumbleCount; // or 0. 
      } 
   } 
};
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

There's still a number of problems: the original number of trumbles is lost when you do

Code: Select all

this.ah_trumbleCount = player.trumbleCount; //update count 
inside the

Code: Select all

else //trumbles are dying 
bit...

What about using another variable (this.maxTrumbleCount perhaps?) to keep track of the highest number of trumbles ever, and use the max trumble count when determining the number of furs to give to the player.

Unless the original intention was to only use the last living trumbles in order to assign furs. In that case just ignore me.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

You are right about the trumblecount variable;
I was thinking of missionVariable terms, it was changed from a missionvar defined at startup and updated at launch and exiting hyper to a Jvar only defined if the timer runs...
did not realise that the variable would not persist after the function ends.
The AH_10 var was initially a let, untill i realised it needed to persist between calls.
The trumblesdied variable is actually only needed in the final call for determining the fur bonus, so an internal variable suffices there.... i think.

Now that I know that JSvar are only defined for the function they are called in and only persist as long as that function, I'll have a stroll through the rest of my code.

v000 is posted at the OP by the way. :)

@kaks: yes this was intended. This probably needs some tweaking of the interval timer to get the right amount of trumble.
I'll add a logmessage recording the number of trumbleCount.
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I've a question about the salted quasirandomnumber.
(I've since decided to use an incrementing counter (AH_10) instead, but ...)

situation:
I have a function that will be triggered multiple times, but having the player messaged every time would become annoying, so I'd want to have the message appear 10% of the time.

The obvious solution would be to have a condition with the random number, but I'm concerned that this value might not change over time, but only is linked to system.ID, leading to either never displaying a message or to always displaying it.

If the random number be different every time the function is called, then I can get rid of the AH_10 variable/script-property altogether.
Riding the Rocket!
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Not sure what you mean.

Salted quasi random numbers were created specifically to be able to get the same 'random number' every time you are inside a specific system. Change solar system, and you get a different quasi random number.

Random number were created specifically to be able to get random numbers ie a different number every time.

Surely if you want a truly random number, you use truly random numbers, not quasi- fake- almost- random ones?

PS: I can see now how you managed to break Murgh! :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply