@@ -524,9 +524,25 @@ bool Collision(combodata f)
524524//Finds the location of a combo, given its (x,y) coordinates on the screen
525525int ComboAt(int x, int y)
526526{
527- x = VBound(x,255,0);
528- y = VBound(y,175,0);
529- return (y & 240)+(x>>4);
527+ // Don't actually need this yet.
528+ // if (Region->ID)
529+ // {
530+ // x = VBound(x, Region->Width - 1, 0);
531+ // y = VBound(y, Region->Height - 1, 0);
532+ // // Floor'd because in ZScript, ints aren't ints?!
533+ // int scr_dx = Floor(x / 256);
534+ // int scr_dy = Floor(y / 176);
535+ // int offset_pos = (scr_dx + scr_dy * Region->ScreenWidth)*176;
536+ // int pos = ((y%176) & 240)+((x%256)>>4);
537+ // return offset_pos + pos;
538+ // }
539+ // else
540+ {
541+ // Fast path.
542+ x = VBound(x,255,0);
543+ y = VBound(y,175,0);
544+ return (y & 240)+(x>>4);
545+ }
530546}
531547
532548//Returns true if the combo at '(x, y)' has either an inherent or place flag of type 'flag'
@@ -542,14 +558,122 @@ bool ComboFI(int loc, int flag)
542558 return Screen->ComboF[loc] == flag || Screen->ComboI[loc] == flag;
543559}
544560
561+ // Note: all of the `Region->ID` checks in these various functions are minor performance improvements. The functions
562+ // likely work even without that.
563+
545564//Return the coordinates of a combo on the screen
546- int ComboX(int loc)
565+ int ComboX(int rpos)
566+ {
567+ // Don't actually need this yet.
568+ // if (Region->ID)
569+ // {
570+ // int scr_index = Floor(rpos / 176);
571+ // int scr_width = Region->ScreenWidth;
572+ // int scr_dx = scr_index % scr_width;
573+ // int scr_dy = Floor(scr_index / scr_width);
574+ // int pos = rpos % 176;
575+ // return scr_dx*16*16 + pos%16*16;
576+ // }
577+ // else
578+ {
579+ return rpos%16*16;
580+ }
581+ }
582+ int ComboY(int rpos)
583+ {
584+ // Don't actually need this yet.
585+ // if (Region->ID)
586+ // {
587+ // int scr_index = Floor(rpos / 176);
588+ // int scr_width = Region->ScreenWidth;
589+ // int scr_dx = scr_index % scr_width;
590+ // int scr_dy = Floor(scr_index / scr_width);
591+ // int pos = rpos % 176;
592+ // return scr_dy*11*16 + (pos&0xF0);
593+ // }
594+ // else
595+ {
596+ return rpos&0xF0;
597+ }
598+ }
599+
600+ // Given a screen index, returns the screen offset in the X direction in the current region.
601+ // Example: If the region origin is screen 5, `RegionRelativeScreenX(8) == 3`
602+ int RegionRelativeScreenX(int scr)
547603{
548- return loc%16*16;
604+ if (Region->ID)
605+ {
606+ return scr%16 - Region->OriginScreen%16;
607+ }
608+ else
609+ {
610+ return 0;
611+ }
549612}
550- int ComboY(int loc)
613+
614+ // Given a screen index, returns the screen offset in the Y direction in the current region.
615+ int RegionRelativeScreenY(int scr)
616+ {
617+ if (Region->ID)
618+ {
619+ return Floor(scr/16) - Floor(Region->OriginScreen/16);
620+ }
621+ else
622+ {
623+ return 0;
624+ }
625+ }
626+
627+ // Given a screen index, returns the world offset in the x direction for the current region.
628+ int RegionWorldOffsetX(int scr)
629+ {
630+ if (Region->ID)
631+ {
632+ return RegionRelativeScreenX(scr) * 256;
633+ }
634+ else
635+ {
636+ return 0;
637+ }
638+ }
639+
640+ // Given a screen index, returns the world offset in the y direction for the current region.
641+ int RegionWorldOffsetY(int scr)
642+ {
643+ if (Region->ID)
644+ {
645+ return RegionRelativeScreenY(scr) * 176;
646+ }
647+ else
648+ {
649+ return 0;
650+ }
651+ }
652+
653+ // Returns true if the given screen index is inside the current region.
654+ // When not in a region, only returns true if scr is equal to Game->CurScreen.
655+ bool RegionIncludesScreen(int scr)
656+ {
657+ if (Region->ID)
658+ {
659+ int dx = RegionRelativeScreenX(scr);
660+ if (dx < 0 || dx > Region->ScreenWidth) return false;
661+
662+ int dy = RegionRelativeScreenY(scr);
663+ if (dy < 0 || dy > Region->ScreenHeight) return false;
664+
665+ return true;
666+ }
667+
668+ return scr == Game->CurScreen;
669+ }
670+
671+ // Returns the FFC ID of the screen `scr`, which must be within the current Region.
672+ // `index` is the screen-specific index of the FFC (what you would see in the editor on that screen).
673+ int RegionGetFFCId(int scr, int index)
551674{
552- return loc&0xF0;
675+ int offset = 128 * (RegionRelativeScreenX(scr) + RegionRelativeScreenY(scr)*Region->ScreenWidth);
676+ return offset + index;
553677}
554678
555679//Returns a if cond is true, else b. Overloaded.
0 commit comments