/* ----------------------------------------------- GTASC - GTA adaptation for TI Calculators ----------------------------------------------- Programmed by : Olivier SANGALA Version : 1.2 License : Free under GNU General Public License ( see "gpl.txt" ) Release Date : 05/01/2007 Platform : TI89/TI92+/V200 Website : http://olivier.sangala.free.fr Email : olivier_sangala@hotmail.com ---------- License ---------- Copyright (C) 2002-2007 Olivier SANGALA This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //----------------------------------------------------------------------------- /* Flips Routines that move objects (peds,vehs) from one border of the screen to another, to make so just like if it's crowded with peds and vehs Method : - Disable objects, that can be disable - Enable objects and place them, if possible */ //--------------------------------------------------------------------------- #include #include "defines.h" #include "tmde.h" //--------------------------------------------------------------------------- extern TCamera Camera; extern int scx; extern int scy; //-------------------------------------------------------------------------- // extern extern TGame*Game; extern byte gangs_area[4][6]; //-------------------------------------------------------------------------- void Flip_Objects(void) { int a; // TRY TO DISABLE // Peds TPed*P=Game->Peds; for (a=0;aVehs; for (a=0;aBullets; for (a=0;aPeds; for (a=0;aenable) Flip_Try_Enable_Ped(P); // Peds V=Game->Vehs; for (a=0;aenable) Flip_Try_Enable_Veh(V); } //--------------------------------------------------------------------------- void Flip_Try_Disable_Ped(TPed*P) { // - enable if (!P->enable) return; // - not main ped/veh if (P==Game->MainPed) return; // dead_disappear_counter if (P->dead_disappear_counter==5 && P->health==0) { P->enable=0; return; } // - invisible int x=(P->MD.Pos.x-scx); int y=(P->MD.Pos.y-scy); if (x>-8 && y>-8 && x<=159 && y<=99) { P->once_appeared = 1; P->invisible_counter = 0; return; } // - not mission used if (P->mission_used) return; // - has once appeared OR invisible for 5s if (!(P->once_appeared || P->invisible_counter>=5)) return; // else -> ok P->enable=0; } //--------------------------------------------------------------------------- void Flip_Try_Disable_Veh(TVeh*V) { // - enable if (!V->enable) return; // - not main ped/veh if (V==Game->MainVeh) return; // - invisible int x=(V->MD.Pos.x-scx); int y=(V->MD.Pos.y-scy); if (x>-16 && y>-16 && x<=159 && y<=99) { V->once_appeared = 1; V->invisible_counter = 0; return; } // - not mission used if (V->mission_used) return; // - has once appeared OR invisible for 5s if (!(V->once_appeared || V->invisible_counter>=5)) return; // - is NOT gonna xplode if (V->health==1) return; // else -> ok V->enable=0; } //--------------------------------------------------------------------------- void Flip_Try_Disable_Bullet(TBullet*B) { // - enable if (!B->enable) return; // - invisible int x=(B->MD.Pos.x-scx); int y=(B->MD.Pos.y-scy); if (x>-8 && y>-8 && x<=159 && y<=99) return; // else -> ok B->enable=0; } //--------------------------------------------------------------------------- void Flip_Try_Enable_Ped(TPed*P) { Ped_Init(P); P->enable=1; // position TPoint8 PP; int r=Flip_FindTile(&PP,FLIP_PED); if (!r) { P->enable=0; return; } // center on tile : (8,8) on (16,16) P->MD.Pos.x=MUL16(PP.x)+4; P->MD.Pos.y=MUL16(PP.y)+4; // angle -> come to mainped int dx=P->MD.Pos.x-Game->MainPed->MD.Pos.x; int dy=P->MD.Pos.y-Game->MainPed->MD.Pos.y; if (dx>=0 && dy>=0) // bottom right P->MD.angle=(random(2)?0:12); else if (dx>=0 && dy<=0) // top right P->MD.angle=(random(2)?8:12); else if (dx<=0 && dy>=0) // bottom left P->MD.angle=(random(2)?4:0); else if (dx<=0 && dy<=0) // top left P->MD.angle=(random(2)?4:8); P->MD.speed=1*SPEED_LCD; P->CC_behaviour=BH_Ped_Computer; P->skin=PED_SKIN_CIV; // gangs - freq = 1/4 int y=QUOT16(P->MD.Pos.y); int x=QUOT16(P->MD.Pos.x); int a=0; for (a=0;a<4;a++) if (y>=gangs_area[a][0] && x>=gangs_area[a][1] && y<=gangs_area[a][2] && x<=gangs_area[a][3]) { if (random(4)==0) { P->skin=gangs_area[a][4]; P->bullets=99; } } // cop freqs = 1/8 - 1/4 - 1/2 - 3/4 - 4/5 int cop_freq[5][2]={{1,8},{1,4},{1,2},{3,4},{4,5}}; int d0=cop_freq[Game->Save.fugitive_factor][0]; int d1=cop_freq[Game->Save.fugitive_factor][1]; if (random(d1)skin=PED_SKIN_COP; P->bullets=99; int f=Game->Save.fugitive_factor; if (f) P->CC_behaviour=(f==1?BH_Ped_BustChase:f==2?BH_Ped_ShootStand:f==3?BH_Ped_ShootChase:BH_Ped_ShootChase); } // refresh angle Ped_OnNewAngle(P); // collision if (TC_Ped_Flip(P)) { P->enable=0; return; } } //--------------------------------------------------------------------------- void Flip_Try_Enable_Veh(TVeh*V) { // enable Veh_Init(V); V->enable=1; // position TPoint8 PP; int r=Flip_FindTile(&PP,FLIP_VEH); if (!r) { V->enable=0; return; } // angle byte tiles_way[8]={12,4,8,0,12,4,8,0}; byte tn = (*GET_PTR(PP.x,PP.y)); if (tn>=8) { V->enable=0; return; } V->MD.angle=tiles_way[tn]; V->MD.Pos.x=MUL16(PP.x); V->MD.Pos.y=MUL16(PP.y); V->MD.speed=1*SPEED_LCD; V->skin=random(VEH_SKINS_COUNT); V->CC_behaviour=BH_Veh_Computer; // gangs - freq = 1/4 int y=QUOT16(V->MD.Pos.y); int x=QUOT16(V->MD.Pos.x); int a=0; for (a=0;a<4;a++) if (y>=gangs_area[a][0] && x>=gangs_area[a][1] && y<=gangs_area[a][2] && x<=gangs_area[a][3]) if (random(4)==0) { V->skin=gangs_area[a][5]; } // cop freqs = 1/8 - 1/4 - 1/2 - 3/4 - 4/5 int cop_freq[5][2]={{1,8},{1,4},{1,2},{3,4},{4,5}}; int d0=cop_freq[Game->Save.fugitive_factor][0]; int d1=cop_freq[Game->Save.fugitive_factor][1]; if (random(d1)skin=VEH_SKIN_COP; int f=Game->Save.fugitive_factor; if (f==4) V->CC_behaviour=BH_Veh_HurtChase; } // refresh td // refresh angle Veh_OnNewAngle(V); Veh_LoadTD(V); // collision if (TC_Veh_Flip(V)) { V->enable=0; return; } } //--------------------------------------------------------------------------- int Flip_Test(byte tn, int type) { if (type==FLIP_PED) return (ISTILEMOVE_CC_PED(tn)); else if (type==FLIP_VEH) return (ISTILEMOVE_CC_VEH(tn)); else return 0; } //--------------------------------------------------------------------------- int Flip_FindTile(TPoint8*P, int type) { /* find a suitable tile by going along a rectangle around the screen order of points : P1 -> P2 P4 <- P3 */ byte x1 = QUOT16(scx)-1; byte y1 = QUOT16(scy)-1; byte x2 = QUOT16(scx+159)+1; byte y2 = QUOT16(scy+99)+1; TPoint8 P2; P2.x = x1; P2.y = y1; // if error if ( ! (P2.xTMSizeX && P2.yTMSizeY)) return 0; // start to search byte *ptr=GET_PTR(P2.x,P2.y); int counter=0; TPoint8 *PtPtr=Game->FlipPosList; // 1 -> 2 while (P2.xTMSizeX && P2.yTMSizeY) if (Flip_Test(*ptr,type)) {counter++;*(PtPtr++)=P2;} P2.x++; ptr++; } // 2 -> 3 while (P2.yTMSizeX && P2.yTMSizeY) if (Flip_Test(*ptr,type)) {counter++;*(PtPtr++)=P2;} P2.y++; ptr+=Game->TMSizeX; } // 3 -> 4 while (P2.x>x1) { if (P2.xTMSizeX && P2.yTMSizeY) if (Flip_Test(*ptr,type)) {counter++;*(PtPtr++)=P2;} P2.x--; ptr--; } // 4 -> 1 while (P2.y>y1) { if (P2.xTMSizeX && P2.yTMSizeY) if (Flip_Test(*ptr,type)) {counter++;*(PtPtr++)=P2;} P2.y--; ptr-=Game->TMSizeX; } // if found tiles, choose one if (counter) *P = Game->FlipPosList[random(counter)]; // return number of tiles found return counter; } //---------------------------------------------------------------------------