Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 3 4 [5] 6 7 8

Author Topic: Holidays  (Read 9231 times)

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #60 on: September 27, 2019, 01:56:11 pm »

On the non-coding front, these are the holidays that I am thinking of starting with. Most will at least have an in game announcement, give some dwarves thoughts/emotions about the holiday and do something fun. Let me know your thoughts and if anyone has any ideas/suggestions:

The names here are the real life equivalents. I plan to change the names.

02/14 Valentine's Day: Some of the dwarves get married throughout the fortress;
The holiday gives dwarves caring, empathy and love.

03/17 Shamrock (St. Patrick's Day): A leprechaun attempts to steal from the fort. He is very fast with a very high dodge/evasion and if caught he drops a really high value gold coin. The holiday gives dwarves enjoyment, amusement and delight.

04/12 Easter: Some of the female dwarves get pregnant throughout the fortress. It also starts raining. The holiday gives dwarves arousal, lust and passion.

08/01 Harvest (Harvest Festival):

10/31 Halloween:
The holiday gives dwarves exhilaration and thrill.

11/28 Thanksgiving:

12/25 Christmas:
The holiday gives dwarves jolliness, joy and jubilation.

I also plan to make the seasons more seasonal. So far, I have added clovers and shamrocks to the spring.

Roses

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #61 on: September 27, 2019, 02:25:53 pm »

1. math.random is inclusive, meaning math.random(4) will give you 1, 2, 3, or 4

2. Your unit.n stuff is wrong. If you want to use numbers as table keys you have to define them using units[n] = unit and then call them using units[n]. As it is written units.n = unit is that same as units["n"] = unit. Also units.1 = unit won't work as lua only takes a string value after the .

3. You should be able to run the add-thought script like that

Ah ok thanks. I updated the unit table and will try it out. I only want 1, 2, 3 or 4 as my intention is to get in one of those four if statements. I wasn't sure of there was an if else in lua.

You updated the units.n = unit correctly but you forgot to update the units.n in the while loop run_script calls (should be units[n]).

Yes, lua has if elseif else so you could replace your if blocks with
Code: [Select]
if holiday_thought_type == 1 then
blah
elseif holiday_thought_type == 2 then
blah
elseif holiday_thought_type == 3 then
blah
end
Also noticed you forgot the then in your if statements
Logged

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #62 on: September 27, 2019, 07:57:49 pm »

Well, I am getting closer. It is now opening the arena create screen and waiting for me to click enter to spawn the leprechaun. I assume this is because of the error below. Possibly unrelated, but it looks like the leprechaun is being created at the bottom of the map (possibly in the underworld, but it looks like it is being created in the top left corner at the bottom of the map).

I'm going to try to reverse the pos.z loop to start from the top of the map instead of the bottom. pos.z might have to start at 0 instead of mapz-1 (or possibly even a negative number)?

[DFHack]# holiday_shamrock
initializing shamrock holiday
initializing shamrock countdown
shamrock tick:  19200   current tick:   16872   ticks to shamrock:      2328
calibrating leprechaun position
leprechaun positioning: [ 55 0 166 ]
...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:149: Cannot write field global.T_cursor.x: integer expected.
stack traceback:
        [C]: in metamethod '__newindex'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:149: in function <...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:119>
        [C]: in function 'xpcall'
        C:\Users\bro\Desktop\df_44_12_win\hack\lua\dfhack.lua:60: in function 'dfhack.pcall'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:104: in global 'createUnit'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:331: in global 'createUnitInCiv'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:574: in local 'script_code'
        C:\Users\bro\Desktop\df_44_12_win\hack\lua\dfhack.lua:680: in function 'dfhack.run_script_with_env'
        (...tail calls...)
        ...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:20: in global 'holiday_shamrock'
        ...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:13: in function <...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:13>


Code: [Select]
print("initializing shamrock holiday")

function holiday_shamrock_countdown()
 local year_tick_total = 1200*28*12
 local current_tick = df.global.cur_year_tick
 local date_shamrock = 1200*(0*28+16)
 local ticks = date_shamrock - current_tick
 if ticks < 0 then
  ticks = ticks + year_tick_total
 end
 print("initializing shamrock countdown")
 print("shamrock tick:", date_shamrock, "current tick:", current_tick, "ticks to shamrock:", ticks)
 dfhack.timeout(ticks+1,'ticks',holiday_shamrock)
end

function holiday_shamrock()
 pos = getPositionSurface()
 pos = '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]'
 print("leprechaun positioning:", pos)
 dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location",pos,"-age",1)
 dfhack.gui.showAnnouncement("The Shamrock Holiday has come! A day of mischief and merriment, this festival celebrates the middle of Spring, when day and night are equal. Keep a watchful eye and guard your valuables. This is the day of the leprechaun!", COLOR_WHITE)
 holiday_shamrock_countdown()
end

function getPositionSurface()
 print("calibrating leprechaun position")
 local rand = dfhack.random.new()
 local mapx, mapy, mapz = dfhack.maps.getTileSize()
 randx = rand:random(mapx)
 randy = rand:random(mapy)
 local pos = {}
 pos.x = randx
 pos.y = randy
 pos.z = mapz - 1
 local j = 0
 while dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z-j).designation[pos.x%16][pos.y%16].outside do
  j = j + 1
 end
 pos.z = pos.z - j + 1
 return pos
end

holiday_shamrock_countdown()

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Holidays
« Reply #63 on: September 27, 2019, 09:16:15 pm »

Quote
04/12 Easter: Some of the female dwarves get pregnant throughout the fortress. It also starts raining. The holiday gives dwarves arousal, lust and passion.
What nightmare has this world become?!

Also, there is no 10/31. Dwarven calendar has only 28-day months.

 - - - - - - - -

Your pos is still wrong. If one modifies my before-mentioned cat example, like this:

Code: [Select]
:lua dfhack.run_script("modtools/create-unit","-race","CAT","-caste","MALE","-name","PLAINS","-location","[ 90 98 165 ]","-age",1)
It creates Cat # at the cursor position while giving that same error. IOW, the location cannot be pasted together (sorry Roses); it must be separated into five parts, as it was before such modification.

Also, coding wise, it doesn't really matter, but instead of wrapping pos into a table, storing that in local variable, and then unwrapping a table you could directly put getPositionSurface() inside the run_script call. lua functions can return multiple variables (that can separated by commas, though they must be in a single return statement).

i.e. function gibthreefiddy() return 3, 50 end can be used like whole, fraction = gibthreefiddy() just as if you had used whole, fraction = 3, 50.

This has the disadvantage of being less "self-contained" and the advantage of not creating an additional table and local variable per request and using less lines of code. (Irrelevant overall, unless used in a loop repeating every step or something.)
« Last Edit: September 27, 2019, 09:19:49 pm by Fleeting Frames »
Logged

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #64 on: September 27, 2019, 09:53:12 pm »

Quote
04/12 Easter: Some of the female dwarves get pregnant throughout the fortress. It also starts raining. The holiday gives dwarves arousal, lust and passion.
What nightmare has this world become?!

Also, there is no 10/31. Dwarven calendar has only 28-day months.

A holiday to stay inside ;)

And good point, I'll change that to 10/28.

Your pos is still wrong. If one modifies my before-mentioned cat example, like this:

Code: [Select]
:lua dfhack.run_script("modtools/create-unit","-race","CAT","-caste","MALE","-name","PLAINS","-location","[ 90 98 165 ]","-age",1)
It creates Cat # at the cursor position while giving that same error. IOW, the location cannot be pasted together (sorry Roses); it must be separated into five parts, as it was before such modification.

How about this?

Code: [Select]
dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location","[",pos.x,pos.y,pos.z,"]")
Also, coding wise, it doesn't really matter, but instead of wrapping pos into a table, storing that in local variable, and then unwrapping a table you could directly put getPositionSurface() inside the run_script call. lua functions can return multiple variables (that can separated by commas, though they must be in a single return statement).
Wouldn't this output an integer/float though and not a string like the previous error before this was added?
 
Code: [Select]
pos = '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]'


EDIT: by the way, is the below hard to do?

Also, coding wise, it Also note how it sets your cursor to that position, which might be undesirable in gameplay if you don't want player to notice it. (In that case, you'd set the cursor back to its old position right afterwards, but here you do want notice).
« Last Edit: September 27, 2019, 10:00:49 pm by brolol.404 »
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Holidays
« Reply #65 on: September 27, 2019, 10:08:10 pm »

Quote
And good point, I'll change that to 10/28.

Though you might want to consider moving the dates to match calendar months, depending on if you associate them with a season. i.e. atm Easter happens during summer and Halloween during winter.

Quote
How about this?
Test it and find out (that you might want to assign age? It works without but that may not be what you want).

Quote
Wouldn't this output an integer/float though and not a string like the previous error before this was added?

Well, you'd need to alter getPositionSurface of course so that instead of returning a table it returns "[", x, y, z, "]".

Edit:
Quote
EDIT: by the way, is the below hard to do?
Nah. You'd do something like local savedpos = copyall (df.global.cursor) then run create-unit then df.global.cursor:assign(savedpos)

Edit 2: Also when doing this you may want to set the unit to be sneaking, like an ambusher, such as by hidden_in_ambush via flagset argument.

edit 3: Hm, seems just assign keeps creature name visible - use dfhack.gui.refreshSidebar() after that to fix it.
« Last Edit: September 27, 2019, 10:29:09 pm by Fleeting Frames »
Logged

Roses

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #66 on: September 27, 2019, 10:09:18 pm »

Interesting. I guess that's why the script I pulled that position stuff from was using dfhack.run_command instead of dfhack.run_script.
Logged

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #67 on: September 28, 2019, 07:46:31 am »

Quote
And good point, I'll change that to 10/28.

Though you might want to consider moving the dates to match calendar months, depending on if you associate them with a season. i.e. atm Easter happens during summer and Halloween during winter.

Yeah. I was assuming Opal 1 was the start of the year. The holidays will be:

Granite 17 Shamrock (St. Patrick's Day)
Slate 12 Easter

Galena 01 Harvest (Harvest Festival)
Sandstone 31 Halloween
Timber 28 Thanksgiving

Moonstone 25 Christmas
Obsidian 14 Valentine's Day


http://dwarffortresswiki.org/index.php/DF2014:Calendar

Edit 2: Also when doing this you may want to set the unit to be sneaking, like an ambusher, such as by hidden_in_ambush via flagset argument.

edit 3: Hm, seems just assign keeps creature name visible - use dfhack.gui.refreshSidebar() after that to fix it.

I was hoping that making the creature a CURIOUSBEAST_ITEM would be enough to make it start invisible, but if thats not the case, I will add this.

I changed the code to make pos.z = 0 (to test it) and chose a flat map and was able to get the leprechaun to spawn on the surface successfully (still requiring an 'enter' keystroke and a strange name lol), but it still seems to dislike the location input. Now it looks like it wants an integer instead of a string?

Code: [Select]
dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location","[",pos.x,pos.y,pos.z,"]")


[DFHack]# holiday_shamrock
initializing shamrock holiday
initializing shamrock countdown
shamrock tick:  19200   current tick:   16872   ticks to shamrock:      2328
calibrating leprechaun position
leprechaun positioning: [ 116 160 0 ]
...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:149: Cannot write field global.T_cursor.x: integer expected.
stack traceback:
        [C]: in metamethod '__newindex'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:149: in function <...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:119>
        [C]: in function 'xpcall'
        C:\Users\bro\Desktop\df_44_12_win\hack\lua\dfhack.lua:60: in function 'dfhack.pcall'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:104: in global 'createUnit'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:331: in global 'createUnitInCiv'
        ...sktop\df_44_12_win/hack/scripts/modtools/create-unit.lua:574: in local 'script_code'
        C:\Users\bro\Desktop\df_44_12_win\hack\lua\dfhack.lua:680: in function 'dfhack.run_script_with_env'
        (...tail calls...)
        ...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:20: in function <...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:16>


Code: [Select]
print("initializing shamrock holiday")

function holiday_shamrock_countdown()
 local year_tick_total = 1200*28*12
 local current_tick = df.global.cur_year_tick
 local date_shamrock = 1200*(0*28+16)
 local ticks = date_shamrock - current_tick
 if ticks < 0 then
  ticks = ticks + year_tick_total
 end
 print("initializing shamrock countdown")
 print("shamrock tick:", date_shamrock, "current tick:", current_tick, "ticks to shamrock:", ticks)
 dfhack.timeout(ticks+1,'ticks',holiday_shamrock)
end

function holiday_shamrock()
 pos = getPositionSurface()
 pos = '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]'
 print("leprechaun positioning:", pos)
 dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location","[",pos.x,pos.y,pos.z,"]")
 holiday_shamrock_thoughts()
 dfhack.gui.showAnnouncement("The Shamrock Holiday has come! A day of mischief and merriment, this festival celebrates the middle of Spring, when day and night are equal. Keep a watchful eye and guard your valuables. This is the day of the leprechaun!", COLOR_WHITE)
 holiday_shamrock_countdown()
end

function getPositionSurface()
 print("calibrating leprechaun position")
 local rand = dfhack.random.new()
 local mapx, mapy, mapz = dfhack.maps.getTileSize()
 randx = rand:random(mapx)
 randy = rand:random(mapy)
 local pos = {}
 pos.x = randx
 pos.y = randy
 pos.z = mapz - 1
 local j = 0
 while dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z-j).designation[pos.x%16][pos.y%16].outside do
  j = j + 1
 end
 pos.z = 0
 return pos
end

function holiday_thoughts_shamrock()
 print("extracting dwarven thoughts")
 local units = {}
 local n = 0
 for i,unit in pairs(df.global.world.units.active) do
  if dfhack.units.isDwarf(unit) then
    n = n + 1
    units[n] = unit
  end
 end
 print("dwarves thinking:",n)
 while n > 0 do
  local holiday_thought_type = math.random(4)
  if (holiday_thought_type == 1) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","ENJOYMENT","-severity",1)
  elseif (holiday_thought_type == 2) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","AMUSEMENT","-severity",1)
  elseif (holiday_thought_type == 3) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","DELIGHT","-severity",1)
  elseif (holiday_thought_type == 4) then
   -- no thought
  end
  units[n] = nil
  n = n - 1
 end
end

holiday_shamrock_countdown()
« Last Edit: September 28, 2019, 08:13:18 am by brolol.404 »
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Holidays
« Reply #68 on: September 28, 2019, 08:10:32 am »

So, 2-1-2-2. Hm, maybe add a Jonathan Day or something for Summer Solstice? Many cultures celebrate it.


Code-wise, huh, odd. When I set pos to cursor, take that line, replace leprechaun with cat and run it, it spawns fine with no errors. 

So I'm not sure why it gives you that error. But maybe try dfhack.run_command with everything in run_script pasted together and separated by spaces, and see if that works?

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #69 on: September 28, 2019, 08:21:15 am »

So, 2-1-2-2. Hm, maybe add a Jonathan Day or something for Summer Solstice? Many cultures celebrate it.


Code-wise, huh, odd. When I set pos to cursor, take that line, replace leprechaun with cat and run it, it spawns fine with no errors. 

So I'm not sure why it gives you that error. But maybe try dfhack.run_command with everything in run_script pasted together and separated by spaces, and see if that works?

Yeah I'll add Summer Solstice on Hematite 20 :)

Like the other holidays, I will come up with some other name.

Like this?

Code: [Select]
dfhack.run_command(modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location [ pos.x pos.y pos.z])
What does this mean exactly? What does the %16 do?

Code: [Select]
designation[pos.x%16][pos.y%16]
EDIT: I guess this should be the same thing:

Code: [Select]
dfhack.run_command(modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location pos )
« Last Edit: September 28, 2019, 08:36:59 am by brolol.404 »
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Holidays
« Reply #70 on: September 28, 2019, 08:50:36 am »

20? - oh right. DF has shorter year than we have, of course.


Also, heh, I guess I wasn't clear.

dfhack.run_command (and run_command_silent) accepts 1 string as argument, and that string would have to be typed exactly as you would it into dfhack console. i.e. dfhack.run_command("gui/gm-editor")

Or here, dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]'), as Roses said on last page.


As for %16 (modulo 16), df stores tiles internally in 16x16 blocks, which can show up when, say, you toy with water in u-bends. dfhack's ensureTileBlock grabs (or generates if absent) the block at given place, but the internal values only count from 0 to 15 so %16 discards the whole number of blocks it "skipped" over.

E: dfhack called the internal field designation when it was mapped but as you can figure it stores more than just that.
« Last Edit: September 28, 2019, 08:54:34 am by Fleeting Frames »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #71 on: September 28, 2019, 09:49:37 am »

Will the script run unintentionally in adv-mode too?
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Roses

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #72 on: September 28, 2019, 11:21:47 am »

Just to add some clarification;

dfhack.run_command takes a single string exactly how it would if you typed it in the command line (just as Fleeting Frames said). It can be a little dangerous to use though as it can also run potentially harmful things as it doesn't have to be a dfhack script that it runs (although I'm usually not worried about that from modders from this forum, it is worth noting, and I would suggest always making it clear what you are calling with run_command, i.e. don't hide the call in some other variable).
Code: [Select]
dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
dfhack.run_script take a string which is the script name (e.g. "modtools/create-unit") then a set of arguments which essentially maps to replacing a comma in every space in your run_command call (thanks to Fleeting Frames for pointing out that you have to split up a position call).
Code: [Select]
dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location","[",pos.x,pos.y,pos.z,"]")
Now the reason you got that error is because right before that call you changed what the variable pos was
Code: [Select]
pos = getPositionSurface()
 pos = '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]'
 print("leprechaun positioning:", pos)
 dfhack.run_script("modtools/create-unit","-race","holiday_LEPRECHAUN","-caste","MALE","-name","PLAINS","-location","[",pos.x,pos.y,pos.z,"]")
So that pos.x, pos.y, and pos.z would all return nil. If you take out the pos = '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]' line it should work.

And just to give a more mathematical description to the %16 in case you are unfamiliar with modulo
pos.x = 132
pos.x%16 = 132 modulo 16 = 4
132/16 = 8 and 4/16

As for Meph's question, as written the script would run in adventure mode, but you could add an extra if statement making sure that it only runs in fortress mode really easy.
Logged

brolol.404

  • Bay Watcher
    • View Profile
Re: Holidays
« Reply #73 on: September 28, 2019, 12:52:11 pm »

Thanks for all of the help guys! It works as intended :)

It also starts on it's own with a unique file (onMapLoad_holiday.init)





Only issue is that [MISCHIEVIOUS] and [CURIOUSBEAST_ITEM] don't seem to work. I assume it is because the leprechaun is being created as "friendly" with the fortress.

Spoiler: leprechaun raw (click to show/hide)



I tried adding -civId -1 and groupId -1 like below, but it went back to an error (possibly doesn't see -1 as a string?):

dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -civId -1 groupId -1 -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')

The announcement also works!



Now I have to figure out the holiday thought function, which it doesn't seem to like me deleting variables in a table by setting them to nil? EDIT below

initializing shamrock holiday
initializing shamrock countdown
shamrock tick:  19200   current tick:   16800   ticks to shamrock:      2400
calibrating leprechaun position
leprechaun positioning: [ 38 156 128 ]
...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:20: attempt to call a nil value (global 'holiday_shamrock_thoughts')
stack traceback:
        ...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:20: in function <...a\Desktop\df_44_12_win/hack/scripts/holiday_shamrock.lua:16>


Code: [Select]
print("initializing shamrock holiday")

function holiday_shamrock_countdown()
 local year_tick_total = 1200*28*12
 local current_tick = df.global.cur_year_tick
 local date_shamrock = 1200*(0*28+16)
 local ticks = date_shamrock - current_tick
 if ticks < 0 then
  ticks = ticks + year_tick_total
 end
 print("initializing shamrock countdown")
 print("shamrock tick:", date_shamrock, "current tick:", current_tick, "ticks to shamrock:", ticks)
 dfhack.timeout(ticks+1,'ticks',holiday_shamrock)
end

function holiday_shamrock()
 pos = getPositionSurface()
 print("leprechaun positioning:", '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
 dfhack.run_command("modtools/create-unit -race holiday_LEPRECHAUN -caste MALE -name PLAINS -location " .. '[ ' ..tostring(pos.x)..' '..tostring(pos.y)..' '..tostring(pos.z).. ' ]')
 holiday_shamrock_thoughts()
 dfhack.gui.showAnnouncement("The Shamrock Holiday has come! A day of mischief and merriment, this festival celebrates the middle of Spring, when day and night are equal. Keep a watchful eye and guard your valuables. This is the day of the leprechaun!", COLOR_WHITE , true )
 holiday_shamrock_countdown()
end

function getPositionSurface()
 print("calibrating leprechaun position")
 local rand = dfhack.random.new()
 local mapx, mapy, mapz = dfhack.maps.getTileSize()
 randx = rand:random(mapx)
 randy = rand:random(mapy)
 local pos = {}
 pos.x = randx
 pos.y = randy
 pos.z = mapz - 1
 local j = 0
 while dfhack.maps.ensureTileBlock(pos.x,pos.y,pos.z-j).designation[pos.x%16][pos.y%16].outside do
  j = j + 1
 end
 pos.z = pos.z - j + 1
 return pos
end

function holiday_thoughts_shamrock()
 print("extracting holiday thoughts")
 local units = {}
 local n = 0
 for i,unit in pairs(df.global.world.units.active) do
  if dfhack.units.isDwarf(unit) then
    n = n + 1
    units[n] = unit
  end
 end
 print("merrymakers thinking:",n)
 while n > 0 do
  local holiday_thought_type = math.random(4)
  if (holiday_thought_type == 1) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","ENJOYMENT","-severity",1)
  elseif (holiday_thought_type == 2) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","AMUSEMENT","-severity",1)
  elseif (holiday_thought_type == 3) then
   dfhack.run_script("add-thought", "-unit",units[n],"-thought","DELIGHT","-severity",1)
  elseif (holiday_thought_type == 4) then
   -- no thought
  end
  units[n] = nil
  n = n - 1
 end
end

holiday_shamrock_countdown()

Will the script run unintentionally in adv-mode too?

It runs in adv-mode now, but I'm not sure it will have any negative impacts. It should show an announcement and possibly spawn things nearby, but I don't think it would crash the game. I can look at disabling it in adv-mode if you think it should only affect fort mode?

by the way, since you are here, feel free to make a leprechaun, clover plant, shamrock plant and unique coin sprite if you want a version included in the meph tileset :P

EDIT: looking at the thoughts code again, the error comes in the first for loop before "merrymakers thinking:" is printed.
« Last Edit: September 28, 2019, 01:04:28 pm by brolol.404 »
Logged

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: Holidays
« Reply #74 on: September 28, 2019, 02:57:18 pm »

I'd advice to do a pop-up window, like a megabeast visit, instead of a the announcement window. It's a bit less intrusive.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::
Pages: 1 ... 3 4 [5] 6 7 8