Table of Contents | Extensions > Fueled Light Source
Prev: Footnotes     Next: MobileCollectiveGroup    

Fueled Light Source

Overview

The purpose of the fueled.t extension is to enable the definition of light sources that have a finite life due to a limited fuel supply. Once the fuel supply is exhausted a FueledLightSource goes out and can’t be relit (unless it’s refueled).

New Classes, Objects and Properties

In addition to a number of properties intended purely for internal use, this extension defines the following new class and properties:

Usage

Include the fueled.t file after the library files but before your game source files. FueledLightSource is a mix-in class, so that it must be included first in the list of classes when you define an object that uses it, such as a flashlight or something that’s lit in some other way.

The FueledLight source class gives a light source a finite life. One unit of fuel is consumed every turn the light source is lit. When the fuel is exhausted the light goes out and cannot be re-lit (unless fuel is added again). The properties and methods of FueledLightSource that contril this behaviour are:

As an example to illustrate all of this, here’s how we might implement a flashlight (or torch in British parlance) that requires a battery:

    + torch: FueledLightSource, OpenableContainer, Flashlight 'torch; heavy black; flashlight'
        "It's a heavy black torch. "
        
        fuelSource = battery
        
        showWarning()
        {
            switch(fuelSource.fuelLevel)
            {
            case 2:
                "The torch is starting to grow dim. ";
                break;
            case 1:
                "The torch is getting very dim. ";
                break;
            }
        }
        
        plungedIntoDarknessMsg = ', leaving you in total darkness'
        
        notifyRemove(obj)
        {
            if(obj == battery)
                removeFuelSource();
            inherited(obj);            
        }
        
        notifyInsert(obj)
        {
            inherited(obj);
            
            /* 
             *  If we reinsert a battery when the torch is on, and there's still life in the battery,
             *  we need to relight the torch and restart the fuel-consumption daemon. 
             */
            if(obj.ofKind(Battery))
            {
                fuelSource = obj;
                if(isOn && fuelSource.fuelLevel > 1)
                {
                   "The torch comes on again. ";
                
                   /* call makeLit to make sure we also restart the fuel daemon here. */
                   makeLit(true); 
               }
            }
        }
            
    ;

    ++ battery: Battery 
        fuelLevel = 10    
    ;

    class Battery: Thing 'battery'
       fuelLevel = 200
    ;

This covers most of what you need to know to use this extension. For additional information see the source code and comments in the fueled.t file.


Adv3Lite Manual
Table of Contents | Extensions > Fueled Light Source
Prev: Footnotes     Next: MobileCollectiveGroup