MCPcopy Create free account
hub / github.com/DFHack/dfhack / command_result plugin_onstatechange

Function command_result plugin_onstatechange

plugins/examples/skeleton.cpp:106–154  ·  view source on GitHub ↗

Called to notify the plugin about important state changes. Invoked with DF suspended, and always before the matching plugin_onupdate. More event codes may be added in the future.

Source from the content-addressed store, hash-verified

104// Invoked with DF suspended, and always before the matching plugin_onupdate.
105// More event codes may be added in the future.
106DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event) {
107 switch (event) {
108 case SC_UNKNOWN:
109 DEBUG(status,out).print("game state changed: SC_UNKNOWN\n");
110 break;
111 case SC_WORLD_LOADED:
112 DEBUG(status,out).print("game state changed: SC_WORLD_LOADED\n");
113 break;
114 case SC_WORLD_UNLOADED:
115 DEBUG(status,out).print("game state changed: SC_WORLD_UNLOADED\n");
116 break;
117 case SC_MAP_LOADED:
118 DEBUG(status,out).print("game state changed: SC_MAP_LOADED\n");
119 break;
120 case SC_MAP_UNLOADED:
121 DEBUG(status,out).print("game state changed: SC_MAP_UNLOADED\n");
122 break;
123 case SC_VIEWSCREEN_CHANGED:
124 {
125 auto vs = Gui::getCurViewscreen(true);
126 string name = Core::getInstance().p->readClassName(*(void**)vs);
127 if (name.starts_with("viewscreen_"))
128 name = name.substr(11, name.size()-11-2);
129 else if (dfhack_viewscreen::is_instance(vs)) {
130 auto fs = Gui::getFocusStrings(vs);
131 if (fs.size())
132 name = fs[0];
133 }
134
135 DEBUG(status,out).print("game state changed: SC_VIEWSCREEN_CHANGED ({})\n",
136 name.c_str());
137 break;
138 }
139 case SC_CORE_INITIALIZED:
140 DEBUG(status,out).print("game state changed: SC_CORE_INITIALIZED\n");
141 break;
142 case SC_BEGIN_UNLOAD:
143 DEBUG(status,out).print("game state changed: SC_BEGIN_UNLOAD\n");
144 break;
145 case SC_PAUSED:
146 DEBUG(status,out).print("game state changed: SC_PAUSED\n");
147 break;
148 case SC_UNPAUSED:
149 DEBUG(status,out).print("game state changed: SC_UNPAUSED\n");
150 break;
151 }
152
153 return CR_OK;
154}
155
156// Whatever you put here will be done in each game tick/frame. Don't abuse it.
157// Note that if the plugin implements the enabled API, this function is only called

Callers

nothing calls this directly

Calls 4

is_instanceFunction · 0.85
c_strMethod · 0.80
printMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected