Mini Macro Challenges (Interest)

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

You can get token x/y on both tokens.
You can get token width/height on both tokens.
You can calculate the line from the token positions on the path.
You should be able to calculate the points on the line where the PC is adjacent to the trap.
The challenge is for it to choose the correct one of two points regardless of the slope of the line.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

I guess you're right, it should be possible with that info, im however not quite sure how fast this would be as you will need to do this for every waypoint set but your workflow would be:

This method assumes square pads and tokens, else the below has to be done for each corner point combination (=16 times)

1. take centrepoint of token (its coord is upper left so add half width height) for first point
2. dito second (way)point
3. construct line between points
4. create perpendicular line on that line with unknown 'b' (as in y'(x)= ax + b )
5. calculate centrepoint of 'pad' (of which you want to check if token has moved over it)
6. calculate b by filling in the pad centrepoint in y'(x)
7. calculate crosspoint between the two perpendicular lines (note that this crosspoint would be the 'trap trigger' coord*)
8. calculate distance between pad centrepoint and that crosspoint
9 if distance if shorter than half height pad + half height token: movedOverToken=true else false
10 rince and repeat for the next waypoint combo

*its not quite entirely correct that that coord is the trap trigger coord, as its the point where the two tokens overlap the most, The entry point can only be found by calculating each corner combination (so all 16 combos) and the picking the coord (for which 'movedOverToken=true) closest to the starting way point

so yeah its possible...

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

You are getting closer but your method will not work for a vertical line.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework


User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

so new challenge, again not so much about the code but more about the method, albeith within the context of what maptool provides.

Again: Inn Generator
I want to add careers to the patrons, I've done this in the past as well with the excel generator and want to make the translation to MT.
here's an excel sheet with careers all provided with different 'codes'.

Here's part of that sheet:

Code: Select all

Career		Type	Group	Race	Chance	Quality	place
Abtrittanbieter	W	3	H	4	1	UD
Agitator	W	1	HE	1	1	U
Alchemist	S	2	X	3	3	U
In the excel sheet all the codes are explained. What this concerns is the following:
There are essentially 4 denominators which can be applied to a token:
race, group, class(=quality) and place (theres also 'type' but lets ignore that for now)

Race:
4 core races (elf, human, dwarf, halfling) and thus are coded with one or more codes e.g. H= Human; HE=Human and Elf; X = all races.There's also the code F which stands for 'foreigner' for the more exotic careers. But ill have to prune this list anyway so that might be gone.

Group:
concerns: always alone, usually alone, usually in group, always in group

Place:
concerns: rural, urban, docks or anywhere

class/quality:
concerns: poor, common, good (and best)

Chance:
Next to this there's also the chance that you run into that career in a bar.

My questions:
1. whats the best way to store this table in MT (im guessing json object, but im open for nifty suggestions)
2. how do I pick a career? lets say a Dwarf in the Docks area in a Common quality bar, part of a group.
How do I create an extraction of the entire json (or whatever) for that combination and then randomly choose a career (taking 'chance' into account)?

I have some vague ideas about this, but Im mostly curious to suggestions.

Ideally I also take into account some cross-over (e.g. theres a small chance that a 'good' career finds its way in a 'common' inn.

Thank you!

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

one thought I have is that I can change the excel to this
x.png
x.png (4.05 KiB) Viewed 4163 times
which makes it more usuable in computerized terms. Is that helpfull? Still curious to other methods.

e.g. i could do a regex search based on the pattern I want a fit with e.g.
dwarf, good, group,docks would be: ???1???1????1??1 (except that for 'groups' factor this does not quite work...) then what remains i could randomly choose a profession from...except that i also need to take 'chance' into account...

so not quite there yet...

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

ok so updated the excel file with the above method:
x.png
x.png (23.48 KiB) Viewed 4153 times
etc.

now turn that into a json, and hopefully the regex method is fast enough. I notice that i misinterpreted 'group', it means that within one group of patrons :
1 = always only one of that career in that group
2= usually 1
3= usually more than 1
4= always more than 1

so i created multiplier for the chance:
1 = 0
2 = 0.5
3 = 1
4 = 10

as usual: suggestions are welcome.

edit:
I managed to create the json. I also managed to get the filter working...only to figure out that obviously not all cxxx are unique (e.g. the top two careers in the image hereabove) so you can't pull them properly from the json construct, another method is required for that. Suggestions?

edit2: added a unique id to each entry. that fixed it. so now the final hurdle how do I pick a random career from e.g. this list:

Code: Select all

{"mult":0,"chance":1,"career":"Grand Cross of the Raven, the"} 
{"mult":0.5,"chance":1,"career":"Grand Druid"}
{"mult":0.5,"chance":2,"career":"Knight Commander of the Raven"}
{"mult":0.5,"chance":2,"career":"Knight Of The Inner Circle"}
{"mult":0.5,"chance":3,"career":"Witch Hunter"}
{"mult":0.5,"chance":2,"career":"Wizard Lord"}
i could e.g. create a json array with the number 'chance' entries of that career; shuffle and draw, but I would have to rebuild that array EVERY SINGLE DRAW as e.g. the multiplier gets into effect changing the odds.
Also this is a small list, but a list of 150 (careers) with chances like 10, means HUGE random arrays...so any suggestions there?

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

the matter is now more specific so tlnr:

given the following (e.g.) json:

Code: Select all

[
{apple: 5, m=2}
{pear: 10, m=0.5}
{mango: 1, m=0}
{banana: 3, m=1}
]
technically you can read this as a list consisting out of: 5 apples, 10 pears, 1 mango, 3 banana's. The job is to pick one fruit randomly from that list.
This is easy something like

Code: Select all

count(5): list = json.append(list, apple) ; dito other fruit
json.shuffle(list)
json.get(list,0)
However... I want to pick 6 fruits and as soon as I pick a fruit the 'm' kicks in, in case of picking an apple then apple:5 becomes apple:5x2=10 (so there are now 10 apples in the list instead of 5). So I have to rebuild the list with the new values in order to pick the next fruit. Again not very hard to do BUT:

Is there a more efficient way to randomly pick the fruit?

clarification:
- after picking the 2nd apple the value remains unchanged: so apple:10 (so not 20) and
- after picking one fruit from the list, that fruit is NOT removed (like you would do with e.g. a deck of cards; so not 9 apples, but still 10)

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

hmm, you lot are a bit quiet...

here's a solution (after filtering down to the actual place/quality/race career list then the below to get the right entry):

Code: Select all

[r:test =
'[{"mult":0.5,"chance":3,"career":"Alchemists Apprentice"},{"mult":0.5,"chance":3,"career":"Apothecary"},{"mult":1,"chance":4,"career":"Artillerist"},{"mult":1,"chance":6,"career":"Artisan"}]'
] <!-- test array -->

[r:strfind	= '.*?"chance":(\\d+,)[^}]*']	<!-- remove everything except the chance values and a , -->

[r:result	= replace(replace(test, strfind, "\$1"), ",}]", "")] <-- = "3,3,4,6" -->
[r:chance	= math.listSum(result)]	<-- = 16 -->
[r:roll		= roll(1,chance)]			<-- = 7 -->

[h:tot		= 0]
[h,while(roll>tot), CODE:{
	[tot	= tot + listGet(result,roll.count)]
	[id		= roll.count]
}]

[r:json.get(test,id)]					<!-- = 3rd entry in this example -->

User avatar
bubblobill
Giant
Posts: 167
Joined: Sun Jan 24, 2010 3:07 pm

Re: Mini Macro Challenges (Interest)

Post by bubblobill »

You are making my head hurt.
How complex are you going here group-wise, is a group the entire patronage or a subset thereof such as a table?

I keep thinking that from the statistics point of view you are generating your population and then taking a random sample. You might be better off creating that population differently. Start by generating and storing a complete list of all possible individual patrons appropritely represented in proportion, so you would have one stored json that is the world, 1 x king, 1 x queen, 200 x knights, 1 x pope, 8 x cardinals, 40 x priests, 70 x carpenters, 400 x carpenter's apprentices, 5 x coopers, 15 x cooper's apprentices, etc. Give each individual their occupation, race, location, etc. This way your statistical outliers such as nobles slumming it at the docks are present in your population. I would be inclined to generate this in VBA and then just store it on the library token.

You then have three steps;
  1. Filtering out what doesn't belong, i.e. cull the list according to quality, location, etc.
  2. Randomly selecting a patron
  3. Picking or excluding a patron according to your rules for their company.
I'll be surprised if your next iteration doesn't include relationships. You cannot have this type of priest sitting next to that type of priest, you must have at least one bodyguard for every two nobles, x many prostitutes for every y many workers, miners will not be in the same table as assayers, two members of the watch for every seven rogues, etc.

We could commercialise that product as a wedding seating planner.
Bubblobill on the forum.
@Reverend on the MapTool Discord Server

Responsible for less atrocities than most... I do accept responsibility for these though: SmartDoors, Simple d20 Framework - barebones, Drop-in: All 3.5 SRD Monsters, Drop in: Simple Character Editor, Battletech Framework

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Mini Macro Challenges (Interest)

Post by Full Bleed »

bubblobill wrote:
Sat Jul 18, 2020 12:51 am
I'll be surprised if your next iteration doesn't include relationships. You cannot have this type of priest sitting next to that type of priest, you must have at least one bodyguard for every two nobles, x many prostitutes for every y many workers, miners will not be in the same table as assayers, two members of the watch for every seven rogues, etc.
What? This doesn't do those things yet?

You guys need to get to work!
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

the relationship thingie is why im doing it the way I do, some careers will be unique in a group while some other will always be in groups of two or more. So yeah, thats the next step. Ive got the first part working.

As for your question: a group is a group at a table, NOT the entire patron community in a bar. That said makes me realize that the 'unique' careers have to be filtered on a inn level and not table level, so good to mention that....just one more layer of complexity.

...wedding seating planner.... hmmm

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Mini Macro Challenges (Interest)

Post by wolph42 »

so, new attempt to get some (interest):

does anyone know an algorithm to find the HCF or GCD of an array of numbers (greatest common divisor or highest common factor)
e.g. of the array [6,18,9,12] the GCD is '3'.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Mini Macro Challenges (Interest)

Post by aliasmask »

You could make a chart for every number up to a certain point assuming the range isn't that big.


Post Reply

Return to “Macros”