3410 STR_NEWGRF_ERROR_MSG_WARNING, |
3411 STR_NEWGRF_ERROR_MSG_WARNING, |
3411 STR_NEWGRF_ERROR_MSG_ERROR, |
3412 STR_NEWGRF_ERROR_MSG_ERROR, |
3412 STR_NEWGRF_ERROR_MSG_FATAL |
3413 STR_NEWGRF_ERROR_MSG_FATAL |
3413 }; |
3414 }; |
3414 |
3415 |
3415 /* AddGRFString expects the string to be referred to by an id in the newgrf |
|
3416 * file. Errors messages are never referred to however, so invent ids that |
|
3417 * are unlikely to be reached in a newgrf file so they don't overwrite |
|
3418 * anything else. */ |
|
3419 enum { |
|
3420 MESSAGE_STRING_ID = MAX_UVALUE(StringID) - 1, |
|
3421 MESSAGE_DATA_ID = MAX_UVALUE(StringID) |
|
3422 }; |
|
3423 |
|
3424 if (!check_length(len, 6, "GRFLoadError")) return; |
3416 if (!check_length(len, 6, "GRFLoadError")) return; |
3425 |
3417 |
3426 /* For now we can only show one message per newgrf file. */ |
3418 /* For now we can only show one message per newgrf file. */ |
3427 if (_cur_grfconfig->error != NULL) return; |
3419 if (_cur_grfconfig->error != NULL) return; |
3428 |
3420 |
3429 buf++; // Skip the action byte. |
3421 buf++; // Skip the action byte. |
3430 byte severity = grf_load_byte(&buf); |
3422 byte severity = grf_load_byte(&buf); |
3431 byte lang = grf_load_byte(&buf); |
3423 byte lang = grf_load_byte(&buf); |
3432 byte message_id = grf_load_byte(&buf); |
3424 byte message_id = grf_load_byte(&buf); |
3433 len -= 4; |
3425 len -= 4; |
|
3426 |
|
3427 /* Skip the error if it isn't valid for the current language. */ |
|
3428 if (!CheckGrfLangID(lang, _cur_grffile->grf_version)) return; |
3434 |
3429 |
3435 /* Skip the error until the activation stage unless bit 7 of the severity |
3430 /* Skip the error until the activation stage unless bit 7 of the severity |
3436 * is set. */ |
3431 * is set. */ |
3437 if (!HASBIT(severity, 7) && _cur_stage == GLS_INIT) { |
3432 if (!HASBIT(severity, 7) && _cur_stage == GLS_INIT) { |
3438 grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur_stage); |
3433 grfmsg(7, "GRFLoadError: Skipping non-fatal GRFLoadError in stage %d", _cur_stage); |
3459 if (len <= 1) { |
3454 if (len <= 1) { |
3460 grfmsg(7, "GRFLoadError: No message data supplied."); |
3455 grfmsg(7, "GRFLoadError: No message data supplied."); |
3461 return; |
3456 return; |
3462 } |
3457 } |
3463 |
3458 |
3464 bool new_scheme = _cur_grffile->grf_version >= 7; |
|
3465 GRFError *error = CallocT<GRFError>(1); |
3459 GRFError *error = CallocT<GRFError>(1); |
3466 |
3460 |
3467 error->severity = sevstr[severity]; |
3461 error->severity = sevstr[severity]; |
3468 |
3462 |
3469 if (message_id == 0xFF) { |
3463 if (message_id == 0xFF) { |
3470 /* This is a custom error message. */ |
3464 /* This is a custom error message. */ |
3471 const char *message = grf_load_string(&buf, len); |
3465 const char *message = grf_load_string(&buf, len); |
3472 len -= (strlen(message) + 1); |
3466 len -= (strlen(message) + 1); |
3473 |
3467 |
3474 error->message = AddGRFString(_cur_grffile->grfid, MESSAGE_STRING_ID, lang, new_scheme, message, STR_UNDEFINED); |
3468 error->custom_message = TranslateTTDPatchCodes(message); |
3475 } else { |
3469 } else { |
3476 error->message = msgstr[message_id]; |
3470 error->message = msgstr[message_id]; |
3477 } |
3471 } |
3478 |
3472 |
3479 if (len > 0) { |
3473 if (len > 0) { |
3480 const char *data = grf_load_string(&buf, len); |
3474 const char *data = grf_load_string(&buf, len); |
3481 len -= (strlen(data) + 1); |
3475 len -= (strlen(data) + 1); |
3482 |
3476 |
3483 error->data = AddGRFString(_cur_grffile->grfid, MESSAGE_DATA_ID, lang, new_scheme, data, STR_UNDEFINED); |
3477 error->data = TranslateTTDPatchCodes(data); |
3484 } |
3478 } |
3485 |
3479 |
3486 /* Only two parameter numbers can be used in the string. */ |
3480 /* Only two parameter numbers can be used in the string. */ |
3487 uint i = 0; |
3481 uint i = 0; |
3488 for (; i < 2 && len > 0; i++) { |
3482 for (; i < 2 && len > 0; i++) { |
4114 |
4108 |
4115 if (c->status == GCS_INITIALISED) { |
4109 if (c->status == GCS_INITIALISED) { |
4116 /* If the file is not active but will be activated later, give an error |
4110 /* If the file is not active but will be activated later, give an error |
4117 * and disable this file. */ |
4111 * and disable this file. */ |
4118 GRFError *error = CallocT<GRFError>(1); |
4112 GRFError *error = CallocT<GRFError>(1); |
|
4113 |
|
4114 char tmp[256]; |
|
4115 GetString(tmp, STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE, lastof(tmp)); |
|
4116 error->data = strdup(tmp); |
|
4117 |
4119 error->message = STR_NEWGRF_ERROR_LOAD_AFTER; |
4118 error->message = STR_NEWGRF_ERROR_LOAD_AFTER; |
4120 error->data = STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE; |
|
4121 error->severity = STR_NEWGRF_ERROR_MSG_FATAL; |
4119 error->severity = STR_NEWGRF_ERROR_MSG_FATAL; |
4122 |
4120 |
4123 if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error); |
4121 if (_cur_grfconfig->error != NULL) free(_cur_grfconfig->error); |
4124 _cur_grfconfig->error = error; |
4122 _cur_grfconfig->error = error; |
4125 |
4123 |