How does it know? Where is on_day_passed defined? I want to see if there are more events I can trigger on but I can’t even figure out how this one gets triggered. Can someone please help?
what is it even involved with? what depends on it?
statsthruskills uses it to trigger its script every day at midnight. When it triggers it calculates your stats based on what your skill levels among other things, then displays the resulting changes.
What I can’t figure out is how the lua knows that MOD.on_day_passed = run this script at midnight. It’s seems to be creating it on the spot, it’s really confusing and I hate lua now, because I’m sure there’s a simple answer to this staring me in the face. I’ve used git to search the source for anything related to on_day_passed and it literally only occurs in statsthruskills and the sample elfmod. Somebody help me please.
stomps out of the room, flouncily
So what youre saying is this s that mode where you reconjugure your base attribuites based on your current skill levels.
I don’t know lua but it seems to reason that yes it does generate its business at midnight and then uses that printout to run the mods gibbly bits.
So 2359 comes or w.e. and the mod scrit pulls out your skills and then puts them through their machinery?
I really do wish I had taken the time to learn code but then Id be a software engineer instead of a semi-employed student. :v
It would seem to me that the first step is to figure out why it can get away with generating the script from magicponytime and what makes that possible. i.e. what it extracts.
Yes, that exactly I think? …magicponytime…Anyway, I’ve dug through catalua.cpp, it’s incomprehensible to me. I’ve compiled the game on my pc so I could view catabindings.cpp hoping it was being generated at build time, but it’s not there either as far as I can tell. I don’t know enough about either c++ or lua to code properly, I’ll freely admit that, but I can usually at least figure out what’s going on in existing code.
Where do you come from on_passed_day? I want to know how to add an event to the c++ side that I can call upon in lua. It’s for a discussion I was having about spawning static npc’s in building as the world is generated. Something in the source is give lua the ability to detect the passage of days, but I’ll be damned if I can find it
Doesnt CDDA detect passage of days on its own? Day 1 or day 2 or day 363 or w.e.
I dont know jack about lua, but I’d try to find the name for the variable [Days passed] and then find out what references that.
The hud displays how many days, so . . .
In game.cpp, line 1030 - 1055
[spoiler]
[code]
std::string sTemp;
std::stringstream ssTemp;
int days_survived = int(calendar::turn.get_turn() / DAYS(1));
int days_adventured = int((calendar::turn.get_turn() - calendar::start.get_turn()) / DAYS(1));
for (int lifespan = 0; lifespan < 2; ++lifespan) {
// Show the second, "Adventured", lifespan
// only if it's different from the first.
if (lifespan && days_adventured == days_survived) {
continue;
}
sTemp = lifespan ? _("Adventured:") : _("Survived:");
mvwprintz(w_rip, iInfoLine++, (FULL_SCREEN_WIDTH / 2) - 5, c_ltgray, (sTemp + " ").c_str());
int iDays = lifespan ? days_adventured : days_survived;
ssTemp << iDays;
wprintz(w_rip, c_magenta, ssTemp.str().c_str());
ssTemp.str("");
sTemp = (iDays == 1) ? _("day") : _("days");
wprintz(w_rip, c_white, (" " + sTemp).c_str());
}
int iTotalKills = 0;
[/code][spoiler]
That is part of the memorial generation function. It only gets called when you die or suicide. That particular bit will figure out how many days your survivor made it before he croaked. The function starts on line 885 with “bool game::cleanup_at_end()” and ends at line 1147.
It calls on how many days youve survived in addition to w.e. else it does.
Im not sure what you are looking for. Are you looking for how the games transitions to a new day?
That would be a start. Calender.h and calender.cpp handle turns, and I thought for sure I had the answer when I found the once_every function in there, but none of the places it’s called seem related to midnight. Then I found seconds_past_midnight and minutes_past_midnight and thought, surely this is it? But no luck. Somehow the game knows when midnight strikes, and is giving lua access to that knowledge. Frustration.
When the [days survived] increments, a script is extracting w.e. infos and manipulating it?
the mods load when you load the game, so its not like it cant be happening any more than autosaves happen.
I love finding things like this, it’s really encouraging.
/* Main Loop for cataclysm
- Linux only I guess
- But maybe not
- Who knows
*/
Ok, thats another thing to try to find, but how does lua know? Where does .on_day_passed () come from? You can’t just call a function without defining what it does somewhere. That is the place I want to find.
edit: I’m reading every single line of class_definitions.lua. Again. Maybe I missed something. Not maybe…probably. YEARGH!
lua_callback(“on_day_passed”) is called in src/game.cpp
I don’t think lua callbacks need a specific definition, adding more callbacks, like “on_skill_change” or “on_craft_finish” would probably be as simple as just adding lua_callback(callback_name_here) to relevant sections, then wrapping it up with a “#ifdef LUA” and “#endif” to make sure it doesn’t break builds.
My preferred way of seaching stuff in DDA sources is just parsing the entire src (or data) folder with a string search program. Linux (and I assume MacOSX) has grep "string here" -r src
, but I’m pretty sure there are Windows equivalents.
Holy cow, I knew it was staring me in the face. Githubs search engine lied to me…Thank you very much. I will definitely be tracking down whatever equivalent to grep exists in windows. This is so cool, the source is starting to make sense
#ifdef LUA and #endif are instructions for the compiler? I see a lot of #ifdef TILES throughout game.cpp, but no #ifdef LUA. How does that work with the lua_callback instruction?
edit: Correction, I see a lot of #ifndef TILES, which is something entirely different maybe?
Ok I get it now. If lua is not enabled, catalua.cpp will replace lua_callback () with a blank function that does nothing. Does this mean I don’t need to use #ifdef #endif, since lua_callback is an empty function when lua is not enabled? That is how I’m interpreting it right now, can you confirm/deny?
Sounds correct.
In this case the ‘n’ means ‘not’.
Ah! Thank you for locating it, I’ve been looking for it myself in order to (hopefully) augment NPC’s restock_shops.
It is called on line 1343 of game.cpp in game:do_turn():
[code]// MAIN GAME LOOP
// Returns true if game is over (death, saved, quit, etc)
1326: bool game::do_turn()
1327: {
…
1343: lua_callback(“on_day_passed”);
…
1347: // Move hordes every 5 min[/code]
I’ve been trying to look for other callbacks to see where I can get the game and LUA to (again hopefully) communicate without having to compile.