Thursday, 8 September 2011

Action and Action_Sleep

The action base class is pretty trivial
class Action
        attr_accessor :name
        attr_accessor :resistance

        def initialize(args)
                @name = args[:name]
                @resistance = args[:resistance] || 100
        end
end
That's a name, and a resistance value. In general if obedience exceeds resistance.

Of course, doing this in ruby, we don't really need a base class. So all this does is set a default resistance.

So, we have our first (and so far only) subclass Action_Sleep

class Action_Sleep < Action
        def initialize(args=nil)
                args = {} unless args
                args[:name] = "Sleep" unless args[:name]
                args[:resistance] = 35 unless args[:resistance]
                super(args)
        end
end

That defauts the name and changes the default resistance. I've left the args in so we can either have custom sleep actions for girls with strange sleep patterns, or else subclass it for something sleeplike later on.

What's missing here is the perform method. And this is where I get in a tangle.




#
#       two factors: obedience and tiredness
#
#       five outcomes:
#
#       disobedient and alert: will stay awake
#       disobedient and a bit tired: will try to stay awake
#       disobedient and very tired: fall asleep, mumbling defiance
#       obedient and tired: will go to sleep
#       obedient and alert: will try to sleep and pretend if need be
#
#       how to define "tired" then?
#       what do I want from tiredness?
#
#       I want to impose some limit on how long people can work
#       I want to be able to exceed that limit
#       I want to use sleep-dep to compel obedience
#
        def perform(actor)
                tiredness = 100 - actor.alertness
                obeidient = (actor.obedience > @resistance)
                tired = (tiredness > 40)
#
#               now, the simplest case is the obedient one
#
                if obedient
                        if tired
                                print "#{} sleeps soundly"
                        else
                                print "#{} lies still and pretends to sleep"
                        end
                        return
                end

#               so, these are the disobedient cases
#               simplest of which is if she's at zero alertness
#               in which case she falls asleep anyway
#
                if actor.alertness == 0
                        print "#{} mutters in her sleep"
                        return
                end

#
#               if she's not tired, she refuses to pretend to sleep
#
                if !tired
                        print "#{} makes rude gestures at the CCTV camera"
                        return
                end

#
#               now then: being tired will make her more inclined to
#               obey than she would be otherwise. Let's have a bonus #               from 1-20
#
                if actor.obedience + tiredness / 5 >= @resistance
                        print "#{} dozes, restlessly"
                else
                        print "#{} stares bleary-eyed at the camera"
                end
        end
That's still not got any changes to stats. Tiredness, obedience, resistance, none of them are moving at this point.

Next thing is to make it all compile and see how it runs.

No comments: