MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ChangeScript

Method ChangeScript

src/script/script_gui.cpp:168–194  ·  view source on GitHub ↗

* Changes the Script of the current slot. */

Source from the content-addressed store, hash-verified

166 * Changes the Script of the current slot.
167 */
168 void ChangeScript()
169 {
170 if (this->selected == -1) {
171 GetConfig(this->slot)->Change(std::nullopt);
172 } else {
173 ScriptInfoList::const_iterator it = this->info_list->cbegin();
174 std::advance(it, this->selected);
175 GetConfig(this->slot)->Change(it->second->GetName(), it->second->GetVersion());
176 }
177 if (_game_mode == GM_EDITOR) {
178 if (this->slot == OWNER_DEITY) {
179 if (Game::GetInstance() != nullptr) Game::ResetInstance();
180 Game::StartNew();
181 } else {
182 Company *c = Company::GetIfValid(this->slot);
183 if (c != nullptr && c->ai_instance != nullptr) {
184 c->ai_instance.reset();
185 AI::StartNew(this->slot);
186 }
187 }
188 }
189 InvalidateWindowData(WC_GAME_OPTIONS, this->slot == OWNER_DEITY ? WN_GAME_OPTIONS_GS : WN_GAME_OPTIONS_AI);
190 InvalidateWindowClassesData(WC_SCRIPT_SETTINGS);
191 InvalidateWindowClassesData(WC_SCRIPT_DEBUG, -1);
192 CloseWindowByClass(WC_QUERY_STRING);
193 InvalidateWindowClassesData(WC_TEXTFILE);
194 }
195
196 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
197 {

Callers 1

OnClickMethod · 0.95

Calls 9

GetConfigFunction · 0.85
CloseWindowByClassFunction · 0.85
cbeginMethod · 0.80
InvalidateWindowDataFunction · 0.50
ChangeMethod · 0.45
GetNameMethod · 0.45
GetVersionMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected