Also "Premature optimization is the root of all evil" -- Don Knuth
Fair enough, I'll give a bit more thought to user defined traits.
[edit]
OK, I had a bit think. We could do something like this:
<traits>
<trait name="Pretty">
<!--
! let's look at some simple cases:
!
! events define lua functions that get called when certain things
! happen.
!
! the "on_gain" event is called when a girl gains a trait.
! so if an item gives a girl the "Pretty" trait, the following
! function would be run, with the girl passed as a parameter
!-->
<event name=on_gain>
function(girl)
girl.change_stat("beauty", 5)
end
</event>
<!--
! similarly we can define this to happen if she loses the trait
!-->
<event name=on_loss>
function(girl)
girl.change_stat("beauty", -5)
end
</event>
</trait>
<!--
! now let's try and design a "Medic" trait
!-->
<trait name="Medic">
<!--
! let's have Medic boost confidence a little bit
! The stat change code is probably going to be commonplace
! enough to be worth automating:
!-->
<stat name="confidence" change="5" />
<!--
! now then, check to see if she can help anyone
!-->
<event name=on_turn_end>
function(girl)
local i
local poorly_girl = nil
-- what was she doing this turn?
-- if it wasn't either matron duty
-- (or else nothing at all)
-- then she's probably too busy to be much help
local action = girl.current_action
if action ~= "free time" and action ~= "matron"
then
return
end
-- OK: is there anyone in her location
-- who needs help?
local brothel = girl.get_brothel()
-- loop over the girls in the brothel
-- looking for a sick one. This could be better:
-- logically you'd look for the sickest girl
-- I'd also want to stop her treating herself
--
-- but this'll do for our purposes
for i = 1, i < brothel.num_girls() do
poorly_girl = brothel.girl_at(i)
if poorly_girl.get_stat("health") < 30
then
break
end
end
-- if we didn't find one, we're done
if poorly_girl == nil then
return
end
-- otherwise, treatment
poorly_girl.change_stat("health", 30)
-- medical crises are tiring.
girl.change_stat("tiredness", 10)
end
</event>
</trait>
</traits>
The work there of course, is in writing the girl and brothel objects to make the game data available to the scripts. Specific things are easy enough to do, but in general, there's a hell of a lot of data that needs publishing.
Which was the primary idea behind the clonemaster branch, of course. If we have a game where the game data and game logic lives in XML and Lua by default, then we don't need to keep converting it to and from C format, and the C++ code is just responsible for the graphics and a few O/S integration functions.
Thoughts?