How I made a - Refiller

I recently looked into how to automate the refilling of certain spaces in Feudum, and I wanted to share how I created this feature.

The goal is to have a button in the toolbar that, when pressed, retrieves pieces from a bag and places them at specific locations on the map. The bag contains various types of pieces, each of which must be sended in a designated spot.

The button on toolbar is a GKC defined like this:

  • Button text: replenish me
  • GKC: replenishMe
  • Pre-select by location Specific Map here insert the map where refiller resides
  • Pre-select by properties type==refiller

Now we need some pieces(the refiller) on the map. These are pieces placed in an At-Start Stack(one for each stack) with these traits:

  • BasicPiece refillCheckerSalt1
  • Marker GoodRefilled=saltpeter you can create different refiller just change name. Must match the Basic Name of the piece contained in the deck from which you wish to draw
  • Prototype: refiller

Our refiller prototype is defined with these traits:

  • Does not stack move=never
  • Marker type=refiller
  • Layer empty.png (this is an image with 10% opacity over the space on the map so you can see through)
  • GKC
    • key command=replenishMe
    • GKC=refill
    • pre-select by location specific write here your deck of pieces
    • pre-select by properties BasicName==$GoodRefilled$ (This is important, $..$ checks against source piece property, the one that issues this GKC instead of target piece property, more details in Comparing Properties For Global Key Commands)
      within a deck apply to fixed number of pieces 1
  • Restrict command disable {StackSize > 1} restrict this command replenishMe (this stops refilling if you need only 1 piece in the spot)

Finally in the pieces inside the deck you need this trait:

  • Basic Name=saltpeter
  • Send To Location
    • key command=refill
    • destination any counter, selected by properties {GoodRefilled=="saltpeter" && StackSize==1} so you send only on non refilled spots.

Done!

Briefly when the button on toolbar is pressed a GKC is fired to all refiller pieces on the map. Each of this, if hasn’t pieces in stack(StackSize==1), sends a GKC to a deck (filtering for type of pieces inside the deck).
Every piece that matches, listens for this GKC(refill) and is sended to the location(not a location but on a counter).

I hope it’s clear.

I can also use
{GoodRefilled=="$BasicName$" && StackSize==1}
in Send To Location trait but I need to click multiple times to refill 2+ spaces. With a straight string all spaces are filled with one click on toolbar button. I still don’t know why and it would be helpful if someone could explain it.