Intent cost is non-refundable



  • So the Game.cpu.getUsed() function takes into account CPU used by intents. Intent costs are added up as you add intents to a "queue" the costs are added immediately into a sum on each intent call.

    This can be seen here:
    https://github.com/screeps/driver/blob/master/lib/runtime/runtime.js#L149

    However, when they are canceled, they do not refund that CPU used, even though they never (as far as I can tell) reach the database or conflict checking. Changing an intent (such as from LEFT to RIGHT) doesn't incur higher costs, but canceling does not refund the cost.

    on this line you can see the intent removed without the cost refunded: https://github.com/screeps/driver/blob/master/lib/runtime/runtime.js#L174

    This makes some sense, since the 'Game.cpu.getUsed()` function used for profiling could then return values less than the starting point call, which would cause some areas of a player's codebase to display as having negative CPU usage.

    I would like to know if it is possible to separate Game.cpu.getUsed() into two functions that would (1 get the actual time spent in the code, and (2 get the cost implied by intents.

    In this way, something like this, could be added for removed intents to refund the cost that was canceled.

    if(!freeMethods[name] && this.list[id][name]) {
        this.cpu -= intentCpu;
    }
    
    💯