Have you ever wondered why mathematicians look at you strangely? Somewhere in the digits of pi, your diary is written in plain ASCII.
The basic mathematical operators were already described in section 6.10. Many additional mathematical functions are provided for various specialized purposes. These are described in the following sections.
|
If only a single argument is given, it is treated as the upper bound and the lower bound takes its default of zero.
The following example makes a potion for gamblers.
obj/potion/lucky verb/drink() usr.AddLife(rand(-20,20))
Depending on how lucky the user is, the potion could do anything from -20 in damage to +20 in healing.
This code assumes the definition of an AddLife()
procedure that handles
healing or damaging a mob. It would be similar to the HurtMe()
proc
defined in section 6.1 but with the meaning of the argument
reversed.
|
This can be used to choose between one of two possible outcomes. The following example gives a player a certain chance of bad side-effects when drinking a magic potion.
obj/potion/health verb/drink() if(prob(20)) //backfire 20% of time usr.AddLife(-10) else usr.AddLife(20)
|
The dice parameters can either be specified as two separate numerical arguments or as one combined text value. The text version might be useful if you want to store the dice parameters in a single variable.
The following example uses roll to compute the impact of a weapon.
obj/weapon var/power clipboard power = "1d4" calculator power = "2d6" verb/swing(mob/trg in view(1)) var/damage = roll(power) view() << "[usr] hits [trg] with \a [src] for [damage] point\s!"
In both programming and combat, you have to make do with what you have.
The pick instruction randomly chooses one of its arguments and
returns that value.
1.4 pick
|
If you want to give a particular value a higher or lower chance of being chosen, a relative probability may be specified. A relative probability of 200 is twice as likely as the norm, 50 is half, and so on.
|
The following example uses pick() to implement a fortune cookie.
obj/fortune_cookie verb/eat() usr << "The message inside says:" usr << pick ( "Never trust an undead doctor.", "Only trust undead lawyers.", prob(25) "The throne marks the way.", prob(10) "The wall behind the throne is an illusion!" ) del(src)
In this example, there are a couple messages with the normal default probability, one a quarter as likely, and one a tenth as likely to be seen. Note how prob() may be followed by a newline instead of a semicolon since the two are equivalent. That allows you to line things up, if you are the lining-up sort of person.
The abs instruction computes the absolute value of a number.
2. abs
|
The min instruction returns the minimum of its arguments.
3. min
|
The max instruction returns the maximum of its arguments.
4. max
|
|
|