const int CMB_LIT_TORCH = 0; //Set to the combo number of the torch in its lit state. const int TIME_INIT_DELAY_LIGHTING_ROOM = 10; //Initial delay before marking the room lit: 20 frames. const int TIME_INTERPOLERATED_FADING_DARKNESS = 20; //30 frames per layer const int DARK_LAYER_0 = 0; const int DARK_LAYER_1 = 1; const int DARK_LAYER_2 = 1; const int DARK_LAYER_3 = 1; const int DARK_LAYER_4 = 1; const int DARK_LAYER_5 = 1; const int DARK_LAYER_6 = 1; const int DARK_OPACITY = 64; //Call before main loop. InitTorchTimers(){ GRAM[TORCH_LIT_THIS_SCREEN] = 0; GRAM[TORCH_LIGHT_TIMER] = TIME_INIT_DELAY_LIGHTING_ROOM; for ( int q = TIME_INIT_DELAY_LIGHTING_ROOM; q <= TORCH_LIGHT_TIMER_LAYER6; q++ ){ if ( q == 0 && DARK_LAYER_0 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_1 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_2 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_3 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_4 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_5 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; if ( q == 0 && DARK_LAYER_6 ) GRAM[q] = TIME_INTERPOLERATED_FADING_DARKNESS; } } void Torches(){ ClearTorchTimersOnScreenChange(); LightRoom(); } Callevery frame before waitdraw. void ClearTorchTimersOnScreenChange(){ if ( ScreenChanged() || DMapChanged() ) { InitTorchTimers(); RoomLit(false); } const int COLOUR_BLACK = 0x91; //Set to the colour for black in your palette in hex. void LightRoom(){ if ( !RoomLit ) { for ( int q = 0; q <= 6; q++ ) { //layers if (Screen->LayerMap != -1) { for ( int w = 0; q < 176; w++ ){ if ( Screen->ComboD[q] == CMB_LIT_TORCH ) { if ( MainTorchTimer() ) MainTorchTimer(true); else if ( !MainTorchTimer() { if ( !(Screen->Lit ) ) Screen->Lit = true; for ( int e = 0; e <= 6; e++ ) { //Layer0 if ( LayerTorchTimer(e) && !RoomLit(e) ) { Screen->Rectangle(e,0,0,256,176,COLOUR_BLACK,-1,0,0,0,true,DARK_OPACITY); LayerTorchTimer(e,true); } if ( !LayerTorchTimer(e) && RoomLit(e) ) RoomLit(e,false); } RoomLit } } } } } } } int MainTorchTimer(){ return GRAM[TORCH_LIGHT_TIMER]; } void MainTorchTimer(bool dec){ GRAM[TORCH_LIGHT_TIMER]--; } int LayerTorchTimer(int layer){ return GRAM[TORCH_LIGHT_TIMER_LAYER0 + layer]; } int LayerTorchTimer(int layer, bool dec){ GRAM[TORCH_LIGHT_TIMER_LAYER0 + layer]--; } int RoomLit(){ return GRAM[ROOM_FULLY_LIT] == 7; } bool RoomLit(int layer){ return RoomLit() == layer + 1; } void RoomLit(int layer, bool clear){ if ( dlear ) GRAM[ROOM_FULLY_LIT] = 0; else GRAM[ROOM_FULLY_LIT] = layer+1; } //void RoomLit(bool lit){ // if ( lit ) GRAM[ROOM_FULLY_LIT] = 7; // else GRAM[ROOM_FULLY_LIT] = 0; //} ` //Global Array to hold values. float GRAM[214727]; //Global RAM indices. const int GR_MAIN = 1900; //Dictates if the main loop should run. const int GR_SCREENSHANGED = 1901; //Screen, DMap, and Map changes. const int GR_LASTSCREEN = 1902; const int GR_DMAPCHANGED = 1903; const int GR_LASTDMAP = 1904; const int GR_MAPCHANGED = 1905; const int GR_LASTMAP = 1906; const int GR_OLDSCREEN = 1907; const int GR_OLDDMAP = 1908; const int TORCH_LIT_THIS_SCREEN = 2000; const int TORCH_LIGHT_TIMER = 2001; const int TORCH_LIGHT_TIMER_LAYER0 = 2002; const int TORCH_LIGHT_TIMER_LAYER1 = 2003; const int TORCH_LIGHT_TIMER_LAYER2 = 2004; const int TORCH_LIGHT_TIMER_LAYER3 = 2005; const int TORCH_LIGHT_TIMER_LAYER4 = 2006; const int TORCH_LIGHT_TIMER_LAYER5 = 2007; const int TORCH_LIGHT_TIMER_LAYER6 = 2008; const int ROOM_FULLY_LIT = 2009; //! Functions for checking screen and DMap changes. //Returns if the screen has changed, and stores the values as an update at at one time. bool ScreenChanged(){ if ( Game->GetCurScreen() != GRAM(GR_LASTSCREEN) ) { GRAM(GR_OLDSCREEN,GRAM(GR_LASTSCREEN)); GRAM(GR_LASTSCREEN, Game->GetCurScreen()); GRAM(GR_SCREENCHANGED,1); return true; } else { GRAM(GR_SCREENCHANGED,0); return false; } } //Returns if the DMap has changed, and stores the values as an update at at one time. bool DMapChanged(){ if ( Game->GetCurDMap() != GRAM(GR_LASTDMAP) ) { GRAM(GR_OLDDMAP,GRAM(GR_LASTDMAP); GRAM(GR_LASTDMAP, Game->GetCurDMap()); GRAM(GR_DMAPCHANGED,1); return true; } else { GRAM(GR_DMAPCHANGED,0); return false; } } //Returns if the Map (NOT DMap!) has changed, and stores the values as an update at at one time. bool MapChanged(){ if ( Game->GetCurMap() != GRAM(GR_LASTMAP) ) { GRAM(GR_OLDMAP,GRAM(GR_LASTMAP)); GRAM(GR_LASTMAP, Game->GetCurMap()); GRAM(GR_MAPCHANGED,1); return true; } else { GRAM(GR_MAPCHANGED,0); return false; } }