Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! We need a GetScreenDown and GetScreenUp function pair to go with the virtual maps.
- //Arrays
- int _____GRAM[1024]; //GLobal RAM
- const int LOOPS_Q = 1023;
- //Fortresses array
- int Fortresses[256]; //tmer, dir, speed, x, y, dmap, screen
- //Fortress[] Array Indices and Offses
- const int FORTRESS_TIMER = 0;
- const int FORTRESS_DIR = 1;
- const int FORTRESS_SPEED = 2;
- const int FORTRESS_X = 3;
- const int FORTRESS_Y = 4;
- const int FORTRESS_DMAP_ID = 5;
- const int FORTRESS_SCREEN_ID = 6;
- const int FORTRESS_TILE = 7;
- const int FORTRESS_CSET = 8;
- const int FORTRES_SCALE = 9; //Scale it, blast you!
- const int FORTRESS_SHADOW_TILE = 10;
- const int FORTRESS_SHADOW_ = 11; //More scaling effects, for perspective.
- const int FORTRESS_DEST_DMAP = 12; //the dmap of the actual dungeon for this fortress
- const int FORTRESS_DEST_SCREEN = 13; //the entrance screen of the actual dungeon for this fortress
- const int FORTRESS_TILEWIDTH = 14;
- const int FORTRESS_TILEHEIGHT = 15;
- const int FORTRESS_SHADOW_Y_OFS = 16;
- const int FORTRESS_SHADOW_TILEHEIGHT = 17;
- const int FORTRESS_SHADOW_TILEWIDTH = 18;
- const int FORTRESS_VIRTUAL_MAP = 19;
- const int FORTRESS_DMAP_OFFSET = 20; // Multiply this * Fortress ID, then add element.
- //! Fortress Constants and Settings
- //Base Fortress Constants
- const int NUM_FORTRESSES = 9;
- const int NUM_WORLD_DMAPS = 32;
- const int FORTRESS_1_TILE = 100; //Replaced by array value,
- const int FORTRESS_SHADOW_TILE = 101; //Replaced by array value,
- const int FORTRESS_SHADOW_Y_OFFSET = 70; //Replaced by array value,
- const int FORTRESS_DRAW_LAYER = 6;
- const int FORTRESS_SHADOW_DRAW_LAYER = 6;
- //const int FORTRESS_TILEWIDTH = 1; Now by array
- //const int FORTRESS_TILEHEIGHT = 1; Now by array
- const int FORTRESS_WIDTH = 8; //Sprite dimensions. Unused?
- const int FORTRESS_HEIGHT = 8; //Unused?
- const int FORTRESS_Z_LOCATION = 100; //must match this Z to enter.
- const int FORTRESS_SHADOW_CSET = 0;
- //Warps
- const int FORTRESS_EXIT_SIDEWARP = 0; //Default SideWarp ID.,
- const int FORTRESS_EXIT_SIDEWARP_TYPE = 0; //Fadeout warp here?
- const int FORTRESS_ENTRANCE_TILEWARP = 3; //Tile Warp D is reserved for this.
- const int FORTRESS_ENTRANCE_TILEWARP_TYPE = 0; //Fadeout?
- const int FORTRESS_TILEWARP_COMBO = 0; //Should be an insta-warp D type.
- //FFC Values
- const int FORTRESS_FFC_SLOT = 30; //When on-screen, the ffc will use this slot.
- const int FORTRESS_FFC_DEFDATA = 1; //The combo (invisible) used by the ffc
- //Movment and Turn Timer
- const int FORTRESS_MOVE_TMER_MIN = 120;
- const int FORTRESS_MOVE_TMER_MAX = 400;
- const int FORTRESS_MOVE_DIST_MIN = 6;
- const int FORTRESS_MOVE_DIST_MAX = 14;
- const int FORTRESS_TIME_MIN = 0; //minutes
- const int FORTRESS_TIME_MAX = 3; //minutes
- const int FORTRESS_TIME_FRACTIONAL_MIN = 10; //seconds
- const int FORTRESS_TIME_FRACTIONAL_MAX = 59; //seconds
- //Link Misc[]
- const int LINK_FLAGS = 15; //Link->Misc, 17 bits
- //Temporary constants for each bit.
- const int LINKF_00 = 00000000000000001;
- const int LINKF_01 = 00000000000000010;
- const int LINKF_02 = 00000000000000100;
- const int LINKF_03 = 00000000000001000;
- const int LINKF_04 = 00000000000010000;
- const int LINKF_05 = 00000000000100000;
- const int LINKF_06 = 00000000001000000;
- const int LINKF_07 = 00000000010000000;
- const int LINKF_08 = 00000000100000000;
- const int LINKF_09 = 00000001000000000;
- const int LINKF_10 = 00000010000000000;
- const int LINKF_11 = 00000100000000000;
- const int LINKF_12 = 00001000000000000;
- const int LINKF_13 = 00010000000000000;
- const int LINKF_14 = 00100000000000000;
- const int LINKF_LEAVING_FORTRESS = 01000000000000000;
- const int LINKF_FORTRESS_Z = 10000000000000000;
- const int LINK_MISC_CURFORTRESS = 14; //Current Fortress ID. Stored for use when shifting to or from a fortress.
- //! Accessors for Fortresses[]
- //Getters
- int FortressX(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X]<<0); } //Truncated
- int FortressY(int fort_id){ return (Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y]<<0); } //Truncated
- int FortressDir(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR]; }
- int FortressSpeed(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED]; }
- int FortressDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID]; }
- int FortressScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID]; }
- int FortressTimer(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
- int FortressTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE]; }
- int FortressCSet(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET]; }
- int FortresScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
- int FortressShadowTile(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE]; }
- int FortresaShadowScale(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
- int FortressDestDMap(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP]; }
- int FortressDestScreen(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN]; }
- int FortressTileHeight(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT]; }
- int FortressTileWidth(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH];; }
- int FortressShadowYOffset(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS]; }
- int FortressShadowTileWidth(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH]; }
- int FortressShadowTileHeight(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT]; }
- int FortressVirtualMap(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP];; }
- //Setters
- void FortressX(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_X] = VBound(v,0,255); }
- void FortressY(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
- void FortressDir(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DIR] = VBound(v,0,7); }
- void FortressSpeed(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SPEED] = Abs(v); }
- void FortressDMap(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DMAP_ID] = v; }
- void FortressScreen(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCREEN_ID] = VBound(v,0,255); }
- void FortressTimer(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = Abs(v); }
- void FortressY(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_Y] = VBound(v,0,175); }
- void FortressTile(int fort_id, int tile){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILE] = tile; }
- void FortressCSet(int fort_id, int v){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_CSET] = v; }
- void FortressScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE] = scale; }
- void FortressShadowTile(int fort_id, int tile) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILE] = tile; }
- void FortressShadowScale(int fort_id, int scale) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE] = scale; }
- void FortressDestScreen(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_SCREEN] = s; }
- void FortressDestDMap(int fort_id, int s){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_DEST_DMAP] = s; }
- void FortressTileHeight(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEHEIGHT] = VBound(v,1,4); }
- void FortressTileWidth(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TILEWIDTH] = VBound(v,1,4); }
- void FortressShadowYOffset(int fort_id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y_OFS] = v; }
- void FortressShadowTileWidth(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEWIDTH] = VBound(v,1,4); }
- void FortressShadowTileHeight(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_TILEHEIGHT] = VBound(v,1,4); }
- void FortressVirtualMap(int fort_id, int virtual_map_ptr) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_VIRTUAL_MAP] = virtual_map_ptr; }
- //!Link Flag Functions
- void SetLinkFlag(int flag, bool state){
- if(state) Link->Misc[LINK_FLAGS] |= flag;
- else Link->Misc[LINK_FLAGS] &= ~flag;
- }
- bool GetLinkFlag(int flag){
- return (Link->Misc[LINK_FLAGS]&flag) != 0;
- }
- //Determines or sets of Link can enter the fortress because he has a sufficient fake Z, by whatever mechanism gives him that fake Z value.
- bool LinkFortressZ(){ return (Link->Misc[LINK_FLAGS]&LINKF_FORTRESS_Z) != 0; }
- void LinkFortressZ(bool z){ if (z) Link->Misc[LINK_FLAGS] |= LINKF_FORTRESS_Z; else Link->Misc[LINK_FLAGS] &= ~LINKF_FORTRESS_Z; }
- //Call globally to adust Link's X and Y when leaving the fortress.
- void LeavingFortress(){
- //Set Link invisible and fix his coordinates,
- if ( GetLinkFlag(LINK_LEAVING_FORTRESS) && Game->GetCurScreen() == FortressScreen(Link->Misc[LINK_MISC_CURFORTRESS])
- && Game->GetCurDMap() == FortressDMap(Link->Misc[LINK_MISC_CURFORTRESS]) ) {
- Link->Invisible = true;
- Link->X = FortressX(Link->Misc[LINK_MISC_CURFORTRESS]);
- Link->Y = FortressShadowY(Link->Misc[LINK_MISC_CURFORTRESS]));
- SetLinkFLag(LINK_LEAVING_FORTRESS,false);
- }
- else Link->Invisible = false;
- }
- //!! Fortress Functions
- //Call in Init, per fortress ID to set the attributes of each fortress.
- void SetFortressInitialAttributes
- ( int id, int x, int y, int dmap, int screen, int dir, float speed, float time, int tile,
- int tilewidth, int tileheight, int scale, int cset, int shadowtile, int shadow_tilewidth,
- int shadow_tileheight, int shadowscale, int shadow_y_offset,
- int dest_dmap, int dest_screen, int virtual_map_ptr
- ){
- FortressX(id, x); FortressY(id,y);
- if ( dir == -1 ) FortressDir(id, Rand(0,3); else FortressDir(dir);
- if ( speed == -1 ) FortresssTimer(id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX));
- else FortresssTimer(id, time);
- FortressDMap(id, dmap);
- FortressScreen(id, screen);
- FortressTile(id, tile); FortressTileWidth(id, tilewidth); FortressTileHeight(id, tileheight);
- FortressScale(id, scale);
- FortressShadowTile(id, shadowtile); FortressShadowScale(id, shadowscale); FortressShadowYOffset(id, shadow_y_offset);
- FortressShadowTileWidth(id, shadow_tilewidth); FortressShadowTileHeight(id, shadow_tileheight);
- FortressCSet(id, cset);
- FortressDestDMap(id, dest_dmap); FortressDestScreen(id, dest_screen);
- FortressVirtualMap(id, virtual_map_ptr);
- }
- //Main fortress function. Call once per fortress, pointing to its id and the virtual map that it uses.
- void DoFortress(int fortress_id, int virtual_map){
- DoFortressTmers(fortress_id);
- MoveFortress(fortress_id, virtual_map); //Moves the fortress every frame, and chanhges its direction fi it cannot move.
- //UpdateFortressScreen(fortress_id); //If the fortress moves off-screen, wrap it to the next one.
- DrawFortress(fortress_id);
- }
- //Draws the fortress. Called by DoFortress()
- void DrawFortress(int fortress_id, int tile){
- //if it is on this dmap
- if ( FortressDMap(fortress_id) == Game->GetCurDMap() ) {
- //...and this screen
- if ( FortressScreen(fortress_id) == Game->GetCurScreen() ) {
- //Draw it
- Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id),
- FortressTileWidth(fortress_id), FortressTileHeight(fortress_id), FortressCSet(fortress_id), FortressScale(fortress_id), FortressScale(fortress_id),
- 0, 0, 0, 0, true, OP_OPAQUE);
- //Draw its shadow.
- Screen->DrawTile(FORTRESS_DRAW_LAYER,FortressShadowTile(fortress_id), FortressX(fortress_id), FortressY(fortress_id)+FORTRESS_SHADOW_Y_OFFSET,
- FortressShadowTileWidth(fortress_id), FortressShadowTileHeight(fortress_id), FORTRESS_SHADOW_CSET, FortresShadowScale(fortress_id), FortresShadowScale(fortress_id),
- 0, 0, 0, 0, true, OP_OPAQUE);
- }
- DoFortressFFC(fortress_id); //Run the ffc that handles warping Link.
- }
- } //!!z Now uses accessors and the array for almost every attribute.
- //Determines if the fortress, moving where it wishes, is legal.
- bool FortressCanMove(int fortress_id, int virtual_map, int screen){
- int dir = FortressDir(fortress_id);
- int scr = FortressScreen(fortress_id);
- //If the fortress is on a screen edge, check if that is a dmap edge, too.
- if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id) ){
- if ( dir == DIR_LEFT ) {
- if ( virtual_map[scr] >= 8 ) return false;
- return true;
- }
- if ( dir == DIR_RIGHT ){
- if ( virtual_map[scr] >= 4 && virtual_map[scr] <= 6 ) return false;
- return true;
- }
- if ( dir == DIR_DOWN ) {
- if ( virtual_map[scr] == 10 || virtual_map[scr] == 2 || virtual_map[scr] == 6 ) return false;
- return true;
- }
- if ( dir == DIR_UP ) {
- if ( virtual_map[scr] == 9 || virtual_map[scr] == 1 || virtual_map[scr] == 5 ) return false;
- return true;
- }
- }
- return true; //The fortress is not on a screen edge, so it can move freely.
- }
- //Moves the fortress based on its speed, and changes its direction if it cannot move.
- void MoveFortress(int fortress_id, int virtual_map){
- if ( FortressCanMove(fortress_id) ) {
- if ( FortressDir(fortress_id) == DIR_LEFT ) {
- //If it is on the edge of a screen
- if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
- //Move it one screen to the left and reset its X
- FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_LEFT) );
- FortressX(fortress_id,255);
- }
- //Move left
- else FortressX(fortress_id, FortressX(fortress_id)-FortressSpeed(fortress_id));
- }
- if ( FortressDir(fortress_id) == DIR_RIGHT ) {
- if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
- //Move it one screen to the right and reset its X
- FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_RIGHT));
- FortressX(fortress_id,0);
- }
- //Move right
- else FortressX(fortress_id, FortressX(fortress_id)+FortressSpeed(fortress_id));
- }
- if ( FortressDir(fortress_id) == DIR_UP ) {
- if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
- //Move it one screen up and reset its Y
- FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_UO));
- FortressY(fortress_id,175);
- }
- //Move up
- FortressY(fortress_id, FortressY(fortress_id)-FortressSpeed(fortress_id));
- }
- if ( FortressDir(fortress_id) == DIR_DOWN ) {
- if ( FortressAtScreenEdge(fortress_id, FortressDir(fortress_id)) {
- //Move it one screen down and reset its Y
- FortressScreen(fortress_id, GetWrapScreen(virtual_map, FortressScreen(fortress_id),DIR_DOWN));
- FortressY(fortress_id,0);
- }
- //Move down
- FortressY(fortress_id, FortressY(fortress_id)+FortressSpeed(fortress_id));
- }
- }
- else {
- //Change the direction.
- FortressDir( fortress_id, FindLegalTurn(fortress_id, virtual_map) );
- }
- }
- //Handles turn timers.
- void DoFortressTmers(int fortress_id){
- if FortressTimer(fortress_id) <= 0 ) {
- TurnFortress(fortress_id);
- }
- else {
- FortressTime(fortress_id, FortressTime(fortress_id)-1); //Reduce the timer.
- }
- }
- //Returns if the fortress is on the edge of a screen based on its direction.
- bool FortressAtScreenEdge(int fortress_id, int dir){
- if ( dir == DIR_LEFT && FottressX(fortress_id) <= 0+FORTRESS_WIDTH ) return true;
- if ( dir == DIR_RIGHT && FortressX(fortress_id) >= 256 ) return true;
- if ( dir == DIR_UP && FortressY(fortress_id)+FORTRESS_HEIGHT < 0 ) return true;
- if ( dir == DIR_DOWN && FortrwessY(fortress_id) >= 176 ) return true;
- return false;
- }
- //Turns the fortress if its timer expires.
- bool TurnFortress(int fortress_id) { {
- //Choose a direction other than the present diretion.
- int dir;
- do { //Pick a random direction that differs from this direction.
- dir = Rand(0,7);
- } while ( dir != FortressDir(fortress_id);
- FortressDir(fortress_id, dir); //Change the direction.
- //Reset the turn timer to a randomised value. .
- FortressTimer(fortress_id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX) );
- }
- //Set the turn timer.
- int FortressTime(int time_min, time_max, int frac_time, int frac_max){
- int t = Rand(time_min,time_max); int tt = (Rand(frac_time, frac_max) / 60);
- Return (t+tt)*60;
- }
- //Called from the global if the fortress is on-screen, via DrawFortress()
- void DoFortressFFC(int fortress_id){
- ffc f = Screen->LoadFFC(FORTRESS_FFC_SLOT);
- int ff[]="FortressFFC";
- int fff = Game->GetFFCScript(ff);
- if ( f->Script != fff ) {
- f->Data = FORTRESS_FFC_DEFDATA;
- f->InitD[0] = FortressDestDMap(fortress_id);
- f->InitD[1] = FortressDestScreen(fortress_id);
- f->Script = fff;
- }
- }
- //Returns the correct screen for wrapping x.y coordinates off a given screen for a virtual map.
- int GetWrapScreen(int virtual_map, int screen, int dir){
- if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UP]; }
- if ( dir == DIR_DOWN ) { return virtual_map[screen+VM_WRAP_DOWN]; }
- if ( dir == DIR_LEFT ) { return virtual_map[screen+VM_WRAP_LEFT]; }
- if ( dir == DIR_UP ) { return virtual_map[screen+VM_WRAP_UO]; }
- return -1; //Invalid direction.
- }
- //Determines a random, legal directions, based on values on a vritual map.
- int FindLegalTurn(int virtual_map, int screen){
- if ( virtual_map[screen] == 1 ) { //cannot turn up
- return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_DOWN) );
- }
- if ( virtual_map[screen] == 2 ) { //cannot tuen down
- return ( Choose(DIR_RIGHT, DIR_LEFT, DIR_UP) );
- }
- if ( virtual_map[screen] == 4 ) { //cannot turn right
- return ( Choose(DIR_LEFT, DIR_DOWN, DIR_UP) );
- }
- if ( virtual_map[screen] == 5 ) { //cannot turn up or right
- return ( Choose(DIR_DOWN, DIR_LEFT) );
- }
- if ( virtual_map[screen] == 6 ) { //cannot turn down or right
- return ( Choose(DIR_UP, DIR_LEFT) );
- }
- if ( virtual_map[screen] == 8 ) { //cannot turn left
- return ( Choose(DIR_RIGHT, DIR_DOWN, DIR_UP) );
- }
- if ( virtual_map[screen] == 9 ) { //cannot turn left or up
- return ( Choose(DIR_RIGHT, DIR_DOWN) );
- }
- if ( virtual_map[screen] == 10 ) { //cannot turn left or down
- return ( Choose(DIR_RIGHT, DIR_UP) );
- }
- return Rand(0,3); //Otherwise, return a random direction.
- }
- /// VIRTUAL MAPS AND DMAPS ///
- //! Let's hardcode some DMAPS! Z
- const int FF_DMAP_SCREEN_VALID = 0;
- const int FF_DMAP_SCREEN_INVALID = -1;
- const int FF_DMAP_SCREEN_BOUNDARY = 1; //1 or higher is a screen boundary.
- //A virtual DMap. 0s are empty space, 1s are screens, 2s are boundaries.
- //Should each edge and corner be a unique value
- /*
- -1 empty space
- 0 has sceens on each side
- 1 cannot turn up
- 2 cannot turn down
- 4 cannot turn right
- 8 cannot turn up
- */
- //DMap and Screen Boundaries
- const int NOT_VALID_SCREEN = -1;
- const int CANNOT_TURN_UP = 1;
- const int CANNOT_TURN_DOWN = 2;
- const int CANNOT_TURN_RIGHT = 4;
- const int CANNOT_TURN_LEFT = 8;
- //Virtual Map Wrap Entry Point Offsets
- const int VM_WRAP_UP = 128;
- const int VM_WRAP_DOWN = 256;
- const int VM_WRAP_LEFT = 384;
- const int VM_WRAP_RIGHT = 512;
- //A virtual map with the edges marked.
- int virtual_map_1[]={
- // Illegal Turns
- 9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,
- 10,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,
- //Wraps
- //! These wrap from the screen at [index] to the specified screen for each given direction.
- //! Needed for non-16x8 DMaps
- //!! We can handle WORLD WRAPPING in the same manner, by storing an U/D/L/R grid for each DMap as
- //!! four arrays.
- //Wrap Screen Up
- 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
- 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
- //Wrap screen down
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
- 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
- 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
- //Wrap Screen left
- 0x0F,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,
- 0x1F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,
- 0x2F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,
- 0x3F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,
- 0x4F,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,
- 0x5F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,
- 0x6F,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,
- 0x7F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,
- //Wrap screen right
- 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x00,
- 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x10,
- 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x20,
- 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x30,
- 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x40,
- 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x50,
- 0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x60,
- 0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x70,
- 0,0,0,0};
- int virtual_dmaps[]={
- //The world layout
- //DMap IDs as they actually connect
- 000, 001, 002, 003m 004, 005, 006, 007,
- 008, 009, 010, 011, 012, 013, 014, 015,
- 016, 017, 018, 019, 020. 021, 022, 023,
- 024, 025, 026, 027, 028, 029, 030, 031,
- //Wrap Up
- 024, 025, 026, 027, 028, 029, 030, 031,
- 000, 001, 002, 003m 004, 005, 006, 007,
- 008, 009, 010, 011, 012, 013, 014, 015,
- 016, 017, 018, 019, 020. 021, 022, 023,
- //Wrap Down
- 008, 009, 010, 011, 012, 013, 014, 015,
- 016, 017, 018, 019, 020. 021, 022, 023,
- 024, 025, 026, 027, 028, 029, 030, 031,
- 000, 001, 002, 003m 004, 005, 006, 007,
- //Wrap Left
- 007, 000, 001, 002, 003m 004, 005, 006,
- 015, 008, 009, 010, 011, 012, 013, 014,
- 023, 016, 017, 018, 019, 020. 021, 022,
- 031, 024, 025, 026, 027, 028, 029, 030,
- //Wrap Right
- 001, 002, 003m 004, 005, 006, 007, 000,
- 009, 010, 011, 012, 013, 014, 015, 008,
- 017, 018, 019, 020. 021, 022, 023, 016,
- 025, 026, 027, 028, 029, 030, 031, 024,
- 0,0,0,0};
- //Returns the logical dmap onto which we wrap.
- //!Does NOT give the screen on that DMap.
- //!We need a second function for /that/
- int GetWrapDMap(int virtual_map, int dmap, int dir, int dmap_max){
- int pos;
- for ( pos = 0; pos < dmap_max, pos++ ) {
- if ( virtual_map[pos] == dmap ) {
- if ( dir == DIR_UP ) return ( virtual_map[ ( NUM_WORLD_DMAPS ) + pos];
- if ( dir == DIR_DOWN ) return ( virtual_map[ ( NUM_WORLD_DMAPS*2 ) + pos];
- if ( dir == DIR_LEFT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*3 ) + pos];
- if ( dir == DIR_RIGHT ) return ( virtual_map[ ( NUM_WORLD_DMAPS*4 ) + pos];
- return 1; //invalid directiom
- }
- }
- return -1; //no match
- }
- int virtual_map_0[]={
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
- //! FFC Scripts
- ffc script FortressExit{
- void run(int fortress_id){
- while(true){
- if ( Collision(this) ) {
- SetLinkFlag(LINKF_LEAVING_FORTRESS,true); //mark Link Leaving fortress
- Screen->SetSideWarp(FORTRESS_EXIT_SIDEWARP, FortressScreen(fortress_id), FortressDMapfortress_id), FORTRESS_EXIT_SIDEWARP_TYPE);
- }
- Waitframe();
- }
- }
- }
- ffc script FortressFFC{
- void run(int warp_to_dmap, int warp_to_screen){
- while(true){
- if ( FortressScreen(fortress_id) != Game->GetCurScreen() ) Quit(); //If the fortress moves off-screen, quit.
- if ( LinkFortressZ() && Collision(this) ) { //If collision with this and Link has the fake Z needed...
- //Set the tilewarp and change this ffc's data to a warp type.
- Screen->SetTileWarp(FORTRESS_ENTRANCE_TILEWARP, warp_to_screen, warp_to_dmap, FORTRESS_ENTRANCE_TILEWARP_TYPE);
- this->Data = FORTRESS_TILEWARP_COMBO;
- }
- Waitframe();
- }
- }
- }
- //Test Global Active Script
- global script test_fortress{
- void run(){
- while(true){
- for ( _____GRAM[LOOPS_Q] = 0; _____GRAM[LOOPS_Q] < 9; _____GRAM[LOOPS_Q]++ ) {
- DoFortress(q);
- }
- Waitdraw();
- Waitframe();
- }
- }
- }
- const int DEFAULT_FORTRESS_TILE = 0;
- const int DEFAULT_FORTRESS_X = 30;
- const int DEFAULT_FORTRESS_Y = 20;
- const int DEFAULT_FORTRESS_DMAP = 0;
- const int DEFAULT_FORTRESS_SCREEN = 0x14;
- const int DEFAULT_FORTRESS_DIR = 0;
- const float DEFAULT_FORTRESS_SPEED = 0.002;
- const float DEFAULT_FORTRESS_TIME = 0.50;
- const int DEFAULT_FORTRESS_TILE = 10100;
- const int DEFAULT_FORTRESS_TILEWIDTH = 1;
- const int DEFAULT_FORTRESS_TILEHEIGHT = 1;
- const int DEFAULT_FORTRESS_SCALE = 30;
- const int DEFAULT_FORTRESS_CSET = 0;
- const int DEFAULT_FORTRESS_SHADOWTILE = 10100;
- const int DEFAULT_FORTRESS_TILEWIDTH = 1;
- const int DEFAULT_FORTRESS_TILEHEIGHT = 1;
- const int DEFAULT_FORTRESS_SHADOWSCALE = 18;
- const int DEFAULT_FORTRESS_SHADOW_Y_OFS = 30;
- const int DEFAULT_FORTRESS_DEST_DMAP = 1;
- const int DEFAULT_FORTRESS_DEST_SCREEN = 0x71;
- //Example Init script
- global script init{
- void run(){
- SetFortressInitialAttributes(0, DEFAULT_FORTRESS_X, DEFAULT_FORTRESS_Y, DEFAULT_FORTRESS_DMAP, DEFAULT_FORTRESS_SCREEN,
- DEFAULT_FORTRESS_DIR, DEFAULT_FORTRESS_SPEED, DEFAULT_FORTRESS_TIME, DEFAULT_FORTRESS_TILE, DEFAULT_FORTRESS_TILEWIDTH,
- DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SCALE, DEFAULT_FORTRESS_CSET, DEFAULT_FORTRESS_SHADOWTILE, DEFAULT_FORTRESS_TILEWIDTH,
- DEFAULT_FORTRESS_TILEHEIGHT, DEFAULT_FORTRESS_SHADOWSCALE, DEFAULT_FORTRESS_SHADOW_Y_OFS, DEFAULT_FORTRESS_DEST_DMAP, DEFAULT_FORTRESS_DEST_SCREEN,
- virtual_map_1);
- }
- }
- //! For world-wrapping, in a future version
- int virtual_map[114]; //nine dmaps screen, x, y, left_bound, rightbound, topbound, bottombound* dmaps];
- const int DMAP1 = 0;
- const int DMAP_COLS = 12;
- //start ( dmap, start screen, screen_left, screen_right, screen_up, screen_down, dma_left, dmap_right, dmap_down, dmap_up, x, y ) * dmap count
- int virtualmap_dmap-connections[numdmaps];
- //Call in init script to set up all the boundaries, dest screens, and so forth.
- void SetMapBound(int ptr, int type, int screen, bool wrapdmap, int wrapto){
- //Set the screen that is the left most, and the screen on the right of the dmap to wrap into.
- //If we are wrapping to another dmap, we need to know it.
- if ( type == BOUND_LEFT ) {
- //We need to automatically set up wraps to dmaps using GetWrapDMap()
- ptr[FLF_MAP_BOUND_LEFT = screen; //the screen at which we start the wrap
- ptr[FLF_MAP_BOUND_LEFT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
- if ( wrapdmap ) ptr[FLF_MAP_BOUND_LEFT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_LEFT); //the dmap on which we end the wrap.
- ptr[FLF_X] = 255; //We wrapped left from x=0, so we wrap to x = 255.
- }
- if ( type == BOUND_RIGHT ) {
- ptr[FLF_MAP_BOUND_RIGHT = screen; //the screen at which we start the wrap
- ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
- if ( wrapdmap ) ptr[FLF_MAP_BOUND_RIGHT_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_RIGHT); //the dmap on which we end the wrap.
- ptr[FLF_X] = 0; //We wrapped left from x=255, so we wrap to x = 0.
- }
- if ( type == BOUND_UP ) {
- ptr[FLF_MAP_BOUND_UP = screen; //the screen at which we start the wrap
- ptr[FLF_MAP_BOUND_UP_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
- if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_UP_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_UP); //the dmap on which we end the wrap.
- ptr[FLF_Y] = 175; //We wrapped left from y=0, so we wrap to Y = 175.
- }
- if ( type == BOUND_DOWN ) {
- ptr[FLF_MAP_BOUND_DOWN = screen; //the screen at which we start the wrap
- ptr[FLF_MAP_BOUND_DOWN_WRAPTO_SCREEN] = wrapto; //the screen at which we end the map
- if ( wrapdmap != -1 ) ptr[FLF_MAP_BOUND_DOWN_WRAPTO_DMAP] = GetWrapDMap(Game->GetCurDMap(DIR_DOWN); //the dmap on which we end the wrap.
- ptr[FLF_Y] = 0; //We wrapped left from y=175, so we wrap to Y = 0.
- }
- }
- /*
- int WrapDMap(int dmap){
- int dmap = Game->GetCurDMap();
- //checck ths table to see if we are on the edge of a dmap and wrappinf to another one,
- //if so, return its value
- //otherwise, return the current dmap.
- int dmap1[128]={
- 0,0,0,0,0,0
- }
- */
- const int DMAP_COLS = 4; //Actual columns
- const int DMAP_ROWS = 4; //Actual rows
- int GetWrapDMap(int source, int dir){
- int virtual_dmaps[ (4_dirs +1 )* NumDMaps] {
- //Layout of the world by DMap IDs.
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- //Left position from each
- 3, 0, 1, 2,
- 7, 4, 5, 6,
- 11, 8, 9, 10,
- 15, 12, 13, 14,
- //Right position from each
- 1, 2, 3, 0,
- 5, 6, 7, 4,
- 9, 10, 11, 8,
- 13, 14, 15, 12,
- //Down position from each
- 4, 5, 6, 7,
- 8, 9, 10, 11,
- 12, 13, 14, 15,
- 0, 1, 2, 3,
- //Up position from each
- 12, 13, 14, 15,
- 0, 1, 2, 3,
- 8, 9, 10, 11,
- 7, 8, 9, 10,
- }
- if ( dir == DIR_LEFT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*1)];
- if ( dir == DIR_RIGHT ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*2)];
- if ( dir == DIR_DOWN ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*3)];
- if ( dir == DIR_UP ) return [virtual_dmaps[pos+((DMAP_COLS*DMAP_ROWS)*4)];
- return -1;//Error
- }
- //If our DMap is square, this part is easier.
- int virtual_maps[]={ 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- 0, 0x1F, 0, 0x1F,
- }; //Topleft, Topright, BottomLeft, BottomRight Screen IDs
- //! Deprecated --------------------------------------------------------------------------------------------------------
- bool TurnFortress(int fortress_id) {
- if ( ( FortressAtScreenEdge(fortres_id), FortressDir(fortress_id) ) || FortressTimer(fortress_id) <= 0 ) {
- //Choose a direction other than the present diretion.
- int dir;
- do { //Pick a random direction that differs from this direction.
- dir = Rand(0,7);
- } while ( dir != FortressDir(fortress_id);
- FortressDir(fortress_id, dir); //Change the direction.
- }
- }
- int MoveForetressSpeed()
- //Edge of Boundary Screen
- bool FortressAtDMapEdge(int virtual_map){
- }
- void SetFortressTimers(int ptr){
- nt sz = SzeOfArray(ptr);
- for ( int q = 0; q < sz; q += NUM_FORTRESSES ) ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX);
- }
- void DoFortressTmers(int ptr){
- int sz = SizeOfArray(ptr);
- for ( int q = 0; q < sz; q += NUM_FORTRESSES ) {
- if ( ptr[q] <= 0 ) { MoveFortress(q); ptr[q] = Rand(FORTRESS_MOVE_TMER_MIN,FORTRESS_MOVE_TMER_MAX); }
- else ptr[q]--;
- }
- }
- int MoveFortressDir(int ptr) {
- int dirs[4] = {UP, DOWN, LEFT, RIGHT};
- int dir = dirs[Rand(0,4)]; //What about angles?
- //
- }
- //I forgot what this was supposed to do, ans I may as well start fresh after I resolve DMap boundaries.
- void MoveFortress(int ptr){
- int distx = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
- int disty = Rand(FORTRESS_MOVE_DIST_MIN, FORTRESS_MOVE_DIST_MAX);
- bool neg = RandB();
- if ( neg )
- //Avoid jiter somehow?
- }
- void MoveFortress(int id)}
- const int FLF_MAP_
- //! THis function is Not finished
- //Boundary Screen?
- bool FortressAtDMapBoundary(int fortress_id, int virtual_map, int offset){
- //Map out the screens of this DMap.
- int map[4];
- for ( int q = 0; q < 3; q++ ) {
- map[q] = virtual_map[(offset*4)+q];
- }
- int edges[4];
- if ( FortressScreen(fortress_id) % map[0] == 0 ) edges[0] = 1; //on left side of dmap. //Will this work of the DMap has an offset???
- //Decide which screens are dmap boundaries.
- //If the fortress is on one of these screens, return true.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement