Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tombstone implementation #74

Merged
merged 21 commits into from Jan 31, 2018
Merged

Tombstone implementation #74

merged 21 commits into from Jan 31, 2018

Conversation

AlinaNova21
Copy link
Contributor

@AlinaNova21 AlinaNova21 commented Jan 23, 2018

Image
Engine side of tombstone implementation. Forum Discussion
A tombstone is generated when creeps die (Via any death method, ttl, suicide, etc)

New RoomObject->Tombstone class with properties: id, room, pos, owner, creepId, creep, store, deathTime, ticksToDecay.

Done

New constant TOMBSTONE_DECAY_PER_PART: 5. Decay time is set to creep.body.length * TOMBSTONE_DECAY_PER_PART

Needs constants updated. (Should I PR screeps/common for this?)

When decayed, resources are dropped on the ground.

Working

Vision is provided.

As far as I can tell, this needs a driver/runtime update, do I need to write a PR for that?
Vision is working automatically.

Find and look constants are also implemented.

Test Cases I'm testing with:

  • Decays after TOMBSTONE_DECAY_PER_PART * body.length
  • Death:
    • Suicide
    • Damage
    • TTL
  • Resources:
    • Resources go into container if it exists and will fit, excess goes into tombstone
    • Drops resources on ground upon decay regardless of presence of container
    • Boosts drop correctly
    • One-shot killed creeps with CARRY also drop into tombstone
  • Userland Properties:
    • deathTime
      • creep:
        • id
        • name
        • body
        • ticksToLive
        • saying
          • Only set if last say was public

Image
For the rendering and constants, I'm using a tiny mod for testing

// Change a global constant

module.exports = function (config) {
    if(config.common) {
        config.common.constants.FIND_TOMBSTONES = 200
        config.common.constants.LOOK_TOMBSTONES = 'tombstone'
        config.common.constants.TOMBSTONE_DECAY_PER_PART = 5
    }

    if(config.backend) {
      // Add visuals
      config.backend.customObjectTypes.tombstone = { 
        // Only renders with Legacy SVG in client
        svg: `<g>
            <ellipse cx="0" cy="0" rx="30" ry="30" fill="#555555"></ellipse>
            <rect x="-30" y="0" width="60" height="40" fill="#555555"></rect>
            <text x="0" y="20" font-size="32" stroke="black" fill="white" text-anchor="middle">RIP</text>
            </g>`,
        sidepanel: `
          <div><label>Creep ID:</label><span>{{object.creepId}}</span></div>
          <div><label>Death Time:</label><span>{{object.deathTime}}</span></div>
          <div><label>Ticks To Decay:</label><span>{{object.decayTime - Room.gameTime}}</span></div>
          <div class='body'>
          <label class='body-header'>
          Store
          <div class='pull-right'>
          {{Room.calcResources(Room.selectedObject) | round}}
          </div>
          </label>
          <div ng:if='!Room.calcResources(Room.selectedObject)'>Empty</div>
          <table class='carry-resource'>
          <tr ng-if='Room.selectedObject[resourceType]' ng:repeat='resourceType in Room.Constants.RESOURCES_ALL'>
          <td>{{Room.selectedObject[resourceType] | number}}&nbsp;&times;&nbsp;</td>
          <td>
          <img class='resource-type' ng-src='https://s3.amazonaws.com/static.screeps.com/upload/mineral-icons/{{resourceType}}.png' tooltip='{{Room.resourceTypeNames[resourceType]}}'>
          </td>
          </tr>
          </table>
          </div>
        `
      }
      }
    }
};

@artch
Copy link
Contributor

artch commented Jan 24, 2018

Great job!

As for vision, could you please test it? It may work automatically, since it has user property in the DB.

Copy link
Contributor

@RiftLurker RiftLurker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DissiNL
Copy link
Contributor

DissiNL commented Jan 24, 2018

Will tombstones be part of the OBSTACLE_OBJECT_TYPES? Now they're walk-able.

@AlinaNova21
Copy link
Contributor Author

Can confirm, vision is working automatically.

}
});
}

if(container) bulk.upda
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that, removed

creepBody: object.body,
creepAgeTime: object.ageTime,
creepBody: object.body,
creepHits: object.hits,
Copy link
Contributor

@artch artch Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to store creep's hits, it seems to be always 0 since the creep is dead, right? Also, body[].hits is all 0 too, so we can store body in plain format ['move','move','work',...] (but expose to user in normal Creep.body format).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is hits 0 when a creep dies by TTL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, people can use TTL to determine cause of death, TTL would be 0 on age death, suicides are user triggered, and death from damage would leave a positive TTL

type: 'tombstone',
room: object.room,
x: object.x,
y: object.y,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x, y, and room are the same as in the tombstone, no need to store them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the tombstone x, y, and room

@AlinaNova21
Copy link
Contributor Author

AlinaNova21 commented Jan 24, 2018

@ButAds: Will tombstones be part of the OBSTACLE_OBJECT_TYPES? Now they're walk-able.

I don't think they should, they currently stack while in existence, one for each creep that has died on that tile. If they were obstacles, it would be easy to effectively blockade areas just by spamming creeps and suicide

@DissiNL
Copy link
Contributor

DissiNL commented Jan 24, 2018

I agree! Just wanted to make sure

@artch artch changed the base branch from master to ptr January 24, 2018 20:17

bulk.remove(object._id);
delete roomObjects[object._id];
require('./_die')(object, roomObjects, bulk, stats, undefined, gameTime);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now this will add to the creepsLost stat, which isn't exactly what you want.
Using undefined instead of stats will fix this already, but maybe it's better to add options to disable this behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, IIRC, somewhere else it also passes undefined as stats, updating now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its spawn recycle-creep where it passes undefined

@RiftLurker
Copy link
Contributor

Code looks good to me, going to test it later on.

This allows tombstones to contain the creep's last words
@RiftLurker
Copy link
Contributor

Tested with all of the above use cases, everything seems to work fine.

@artch artch merged commit ba7795e into screeps:ptr Jan 31, 2018
artch added a commit that referenced this pull request Jan 31, 2018
artch added a commit that referenced this pull request Jan 31, 2018
* Tombstone implementation

* Fixed new creeps auto-killing on blcoked spawns and recylcing

* Drop to container

* Adjust tombstones to use a stub creep

* Only store body types, removed duplicate creepBody, fix TTL saving

* Fixed syntax error and hitsMax

* Fixed containers being overfilled

* Adjusted so that any energy that won't fit into container (if it exists) is placed in tombstone

* Fix Tombstones to never drop into containers when decayed.

* Fix saving public say to tombstone

* Fixed tombstone not spawning for TTL deaths

* Tombstones: Don't pass stats to _die for TTL death

* Allow creep say intent to be processed before the suicide intent

This allows tombstones to contain the creep's last words

* small fixes

* remove `owner` and `my`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants