Consuming power

Freeform discussion about anything related to modding Transcendence.
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

I'd like opinions on this ticket:
http://wiki.neurohack.com/transcendence/trac/ticket/300

First, I'm not sure I understand the use case. Don't weapons consume power normally even if OnFireWeapon is used? Is this only to create weapons with variable power-use?

I'm inclined to fix this by adding a new power consumption function:

(shpConsumePower ship power time)

This would consume the given amount of power (in tenths of MWs) for the specified number of ticks (starting now).

Unfortunately, the implementation of that function is non-trivial.

[For example, imagine the following:

On tick 1, you call (shpConsumePower gPlayerShip 10 30)
On tick 15, you call (shpConsumePower gPlayerShip 20 30)

To calculate power consumption on any given tick we need to keep a list of all the calls to shpConsumePower, add up their consumption, and expire them when appropriate.]

Can anyone think of a simpler way to do this?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

I would think a itmConsumePower might be easier. It would overwrite the old itmConsumePower and you would already have a list. It would only consume extra power for installed items so you would need virtual equipped items for consuming power with no corresponding equipped item.
You would also need a itmGetConsumePower.

The issue with putting them per ship as you said is there would not be and easy way of getting them. You would also want to get them individually in case you wanted to end one early (by a counteracting power use with the appropriate timeout or just removing it).

The counteracting power use is something I just thought of but would be helpful. It would be negative power use.
Crying is not a proper retort!
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Betelgeuse wrote:It would overwrite the old itmConsumePower and you would already have a list.
I'm not sure what you mean. There is no itmConsumePower function. Do you mean the old shpConsumeFuel function?

Right now, devices calculate how much power to consume based on a C++ function. Do you mean that there should be a new event:

<GetPowerConsumption>

that devices can override? That would work, but it would have to be called every tick (which could be expensive).

If we did it that way (which would be easier) then the device will have to do all its own power calculations (e.g., don't consume power if disabled, change power consumption based on enhancements, etc.)

Is that what you had in mind?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

I was thinking just a stored number for the current power consumption stored on the item that would be removed or invalidated after the timer is done. I suggested that way because a GetPowerConsumption would be expensive and power use doesn't change that often. There might be use for a flag to say never expire.

While it wouldn't be as useful as a GetPowerConsumption (due to not being able to tell what state the item is in arbitrarily but I think those would be better handled by separate events)it would be able to do everything that shpConsumePower and more easier.
Crying is not a proper retort!
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Betelgeuse wrote:I was thinking just a stored number for the current power consumption stored on the item that would be removed or invalidated after the timer is done.
Got it. I like that idea. [Technically I would have to store the number in the device structure--meaning only installed devices would have it, not all items.]

If you had this, how would you use it in <OnFireWeapon>? When would you reset it?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

There would be a default that you would put in the xml (like all items currently have). The new power use would be used instead of that one while it is active (however long the timer is). If a new one is applied it would overwrite the old one (this is on a single device so I don't see any issues with that).
To stop one going on I would just put a power consume with the default power and very low time so it would expire right away.

In OnFireWeapon I would just have it consume power if the conditions are correct for the correct amount of time (one tick I think for weapons?)
For shields we could use the OnShieldDamage event to call the function if needed.
For invokable installed items it would be trivial.
I am not sure what would be best for drives and repairers (I don't think repairers have different power levels currently anyway).
Crying is not a proper retort!
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Ugh, you're right--I forgot about the timer. That increase complexity, unfortunately. Probably not for the next release, then, but maybe for 1.1.

Remind me again why you can just use the normal (constant) power consumption in weapons? Is all this just to get variable power consumption?
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

what started this all is because we wanted a weapon that fired only when certain conditions where met. Using firing power even when not being fired didn't seem fair.
Crying is not a proper retort!
george moromisato
Developer
Developer
Posts: 2997
Joined: Thu Jul 24, 2003 9:53 pm
Contact:

Betelgeuse wrote:what started this all is because we wanted a weapon that fired only when certain conditions where met. Using firing power even when not being fired didn't seem fair.
Maybe an easier solution is to allow a return value from OnFireWeapon that communicates whether or not we should consume power (or something like that).
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

maybe we could do without timers if we had events for when it would normally change power.
Crying is not a proper retort!
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

george moromisato wrote:
Betelgeuse wrote:what started this all is because we wanted a weapon that fired only when certain conditions where met. Using firing power even when not being fired didn't seem fair.
Maybe an easier solution is to allow a return value from OnFireWeapon that communicates whether or not we should consume power (or something like that).
that would work. 8)
don't forget it currently firing the weapon normally when it returns nil.
Crying is not a proper retort!
User avatar
Prophet
Militia Captain
Militia Captain
Posts: 826
Joined: Tue Nov 18, 2008 6:09 pm

I hope I'm not too late but I would like to make some suggestions.

My vote is for a function rather than an event as I wanted to use power with non-installed items.

Perhaps something like (itmSetPowerUsage itm power)->True/Nil and the obvious (itmGetPowerUsage itm)->power. This would eliminate the need for a timer in the function itself but would have to be reversed manually.

It's not a perfect solution but would make my cyberdecks more weapon-like if they used energy rather than fuel.
Coming soon: The Syrtian War adventure mod!
A Turret defense genre mod exploring the worst era in Earth's history.
Can you defend the Earth from the Syrtian invaders?
Stay tuned for updates!
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

As far as I can see the problem is split in two parts.

1. We need to be able to set the power draw on installed items, that is, items that would draw power every tick, or however often the game does it internally.
This suggest to me (itmSetPowerUsage source itm) and (itmGetPowerUsage ship itm)

2. We need to be able to draw power directly, as a onetime event, or a continuous draw controlled through events. This would lead to (objDrawPower source amount) and perhaps (objGetCurrentPower source)

Perhaps it would also be nice to have a function that could set the actual level of power on a ship (so we could add or remove power) (objSetCurrentPower source value) comes to mind. In that case objDrawPower could just be a wrapper around (objGet/SetCurrentPower)

As for the weapons drawing power even when not firing, that is actually another issue imo. Having a return value that indicates you don't want to fire, which in turn does not draw power seems like a good solution to me. Perhaps a 'noFire return value? (a bit like the OnPlayerLeftSystem event takes different return values to control behaviour)
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

I think the current behavior is that they don't draw fire unless onfireweapon returns nil. At least that's what it looks like I said in the ticket.
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

itmSetPower would be a nice thing to have but the only problem with that is we don't have a way of doing timed events for items. (other than onUpdate and that is expensive)
Crying is not a proper retort!
Post Reply