From 12770adba6ebe0f1340b372005d484edff243d03 Mon Sep 17 00:00:00 2001 From: Darkvater Date: Sat, 15 Apr 2006 21:27:59 +0000 Subject: (svn r4439) - NewGRF: Add support for Action 0x10. This also required an extra pre-stage (before initialize and activation) to scan the GRF file for GOTO labels. Big thanks for peter1138 for the guidance and answers, as well as parts of the code. --- newgrf.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 8 deletions(-) (limited to 'newgrf.c') diff --git a/newgrf.c b/newgrf.c index 7aff4d2f1..c38b4786a 100644 --- a/newgrf.c +++ b/newgrf.c @@ -38,7 +38,7 @@ static GRFFile *_cur_grffile; GRFFile *_first_grffile; static int _cur_spriteid; static int _cur_stage; -static int _nfo_line; +static uint32 _nfo_line; /* 32 * 8 = 256 flags. Apparently TTDPatch uses this many.. */ static uint32 _ttdpatch_flags[8]; @@ -1849,6 +1849,8 @@ static void SkipIf(byte *buf, int len) uint32 param_val = 0; uint32 cond_val = 0; bool result; + GRFLabel *label; + GRFLabel *choice = NULL; check_length(len, 6, "SkipIf"); param = buf[1]; @@ -1947,6 +1949,30 @@ static void SkipIf(byte *buf, int len) } numsprites = grf_load_byte(&buf); + + /* numsprites can be a GOTO label if it has been defined in the GRF + * file. The jump will always be the first matching label that follows + * the current nfo_line. If no matching label is found, the first matching + * label in the file is used. */ + for (label = _cur_grffile->label; label != NULL; label = label->next) { + if (label->label != numsprites) continue; + + /* Remember a goto before the current line */ + if (choice == NULL) choice = label; + /* If we find a label here, this is definitely good */ + if (label->nfo_line > _nfo_line) { + choice = label; + break; + } + } + + if (choice != NULL) { + grfmsg(GMS_NOTICE, "Jumping to label 0x%0X at line %d, test was true.", choice->label, choice->nfo_line); + FioSeekTo(choice->pos, SEEK_SET); + _nfo_line = choice->nfo_line; + return; + } + grfmsg(GMS_NOTICE, "Skipping %d sprites, test was true.", numsprites); _skip_sprites = numsprites; if (_skip_sprites == 0) { @@ -2065,6 +2091,12 @@ static void GRFComment(byte *buf, int len) /* <0C> [] * * V ignored Anything following the 0C is ignored */ + + static char comment[256]; + if (len == 1) return; + + ttd_strlcpy(comment, buf + 1, minu(sizeof(comment), len)); + grfmsg(GMS_NOTICE, "GRFComment: %s", comment); } /* Action 0x0D */ @@ -2278,6 +2310,36 @@ static void GRFInhibit(byte *buf, int len) } } +static void DefineGotoLabel(byte *buf, int len) +{ + /* <10>