Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "std.zh"
- int fortress_virtual_map_IDs[255];
- global script init{
- void run(){
- //Map 106.
- fortress_virtual_map_IDs[0] = virtual_map_overworld_desert;
- //Set style attributes for fortress 0.
- 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_overworld_desert);
- }
- }
- //Arrays
- int _____GRAM[1024]; //GLobal RAM
- const int LOOPS_Q = 1023;
- //Fortresses array
- int Fortresses[256]; //tmer, dir, speed, x, y, dmap, screen
- //int FortressTimers[20];
- //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_SCALE = 19;
- const int FORTRESS_SHADOW_X = 20;
- const int FORTRESS_SHADOW_Y = 21;
- const int FORTRESS_SHADOW_SCALE = 22;
- const int FORTRESS_VIRTUAL_MAP = 23;
- 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,
- //sconst 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 = 00000000000000001b;
- const int LINKF_01 = 00000000000000010b;
- const int LINKF_02 = 00000000000000100b;
- const int LINKF_03 = 00000000000001000b;
- const int LINKF_04 = 00000000000010000b;
- const int LINKF_05 = 00000000000100000b;
- const int LINKF_06 = 00000000001000000b;
- const int LINKF_07 = 00000000010000000b;
- const int LINKF_08 = 00000000100000000b;
- const int LINKF_09 = 00000001000000000b;
- const int LINKF_10 = 00000010000000000b;
- const int LINKF_11 = 00000100000000000b;
- const int LINKF_12 = 00001000000000000b;
- const int LINKF_13 = 00010000000000000b;
- const int LINKF_14 = 00100000000000000b;
- const int LINKF_LEAVING_FORTRESS = 01000000000000000b;
- const int LINKF_FORTRESS_Z = 10000000000000000b;
- const int LINK_MISC_CURFORTRESS = 14; //Current Fortress ID. Stored for use when shifting to or from a fortress.
- //Fortress FFC Settings
- const int DEFAULT_FORTRESS_TILE = 65303;
- 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_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 = 65304;
- const int DEFAULT_FORTRESS_SHADOW_TILEWIDTH = 1;
- const int DEFAULT_FORTRESS_SHADOW_TILEHEIGHT = 1;
- const int DEFAULT_FORTRESS_SHADOW_SCALE = 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;
- /// 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;
- //map 106, dmap getcurdmap
- int virtual_map_overworld_desert[]={
- // 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};
- //This array should hold the overworld layout for crossing dmap boundaries.
- int virtual_dmaps[]={
- //The world layout
- //DMap IDs as they actually connect
- 000, 001, 002, 003, 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, 003, 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, 003, 004, 005, 006, 007,
- //Wrap Left
- 007, 000, 001, 002, 003, 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, 003, 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};
- //! 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){ 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){ 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; }
- int FortressShadowY(int fort_id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y]; }
- void FortressShadowY(int fort_id, int v) { Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_Y] = v; }
- //int FortressTimer(int id){ return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER]; }
- //void FortressTimer(int id, int v){ Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_TIMER] = v; }
- int FortressScale(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SCALE]; }
- int FortressShadowScale(int fort_id) { return Fortresses[(FORTRESS_DMAP_OFFSET*fort_id)+FORTRESS_SHADOW_SCALE]; }
- //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
- }
- //!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(LINKF_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(LINKF_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 ) FortressTimer(id, FortressTime(FORTRESS_TIME_MIN, FORTRESS_TIME_MAX, FORTRESS_TIME_FRACTIONAL_MIN, FORTRESS_TIME_FRACTIONAL_MAX));
- else FortressTimer(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){
- int virtual_map = fortress_virtual_map_IDs[fortress_id]; //get the virtual map ID.
- DoFortressTimers(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){
- //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, FortressShadowScale(fortress_id), FortressShadowScale(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 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, virtual_map) ) {
- 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_UP));
- 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 DoFortressTimers(int fortress_id){
- if ( FortressTimer(fortress_id) <= 0 ) {
- TurnFortress(fortress_id);
- }
- else {
- FortressTimer(fortress_id, FortressTimer(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 && FortressX(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 && FortressY(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, int 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_UP]; }
- 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.
- }
- //! 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), FortressDMap(fortress_id), FORTRESS_EXIT_SIDEWARP_TYPE);
- }
- Waitframe();
- }
- }
- }
- ffc script FortressFFC{
- void run(int fortress_id, 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();
- }
- }
- }
- int Q(){ return _____GRAM[LOOPS_Q]; }
- void Q(int v){ _____GRAM[LOOPS_Q] = v; }
- //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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement