/* ----------------------------------------------- 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 */ //----------------------------------------------------------------------------- /* pedestrians functions */ #include // Include All Header Files #include "defines.h" //-------------------------------------------------------------------------- // extern extern TGame*Game; //-------------------------------------------------------------------------- extern int FrameCounter; //-------------------------------------------------------------------------- void Ped_Init(TPed*P) { memset(P,0,sizeof(TPed)); P->health=PED_HEALTH_INIT; Ped_OnNewAngle(P); } //--------------------------------------------------------------------------- // ped computer control function void Ped_CC(TPed*P) { int b=P->CC_behaviour; // BH_None if (b==BH_Ped_None) { P->MD.speed=0; } // BH_Computer else if (b==BH_Ped_Computer) { Ped_CC_Computer(P); } // others else { // cancel any chase behavior if ff=0 if (Game->Save.fugitive_factor==0) { P->CC_behaviour=BH_Ped_None; return; } int cop_angle = 1; int cop_chase = (b==BH_Ped_BustChase || b==BH_Ped_ShootChase); int cop_stayfar = (b==BH_Ped_ShootStand || b==BH_Ped_ShootChase || Game->MainVeh); int cop_shoot = (b==BH_Ped_ShootStand || b==BH_Ped_ShootChase); TPed*P2=Game->MainPed; if (cop_angle) P->MD.angle=GetFastAngle16(P->MD.Pos,P2->MD.Pos); if (cop_chase) P->MD.speed=SPEED_LCD; else P->MD.speed=0; int dx = P2->MD.Pos.x-P->MD.Pos.x; int dy = P2->MD.Pos.y-P->MD.Pos.y; int too_close = (abs(dx)<32 && abs(dy)<32); if (cop_stayfar && too_close) P->MD.speed=0; if (cop_shoot) Ped_Shoot(P); } } //--------------------------------------------------------------------------- // ped default behaviour void Ped_CC_Computer(TPed*P) { // flag_collideCC // -> collision with vehicle // -> go backward if (P->flag_collideCC) { P->flag_collideCC=0; //P->CC_flag_stopdelay=3; P->MD.speed=0; P->MD.angle+=8; P->MD.angle&=15; return; } // CC_flag_stopdelay if (P->CC_flag_stopdelay) { P->MD.speed=0; return; } int x=P->MD.Pos.x-4; int y=P->MD.Pos.y-4; int qx=QUOT16(x); int qy=QUOT16(y); int rx=REM16(x); int ry=REM16(y); byte*ptr=GET_PTR(qx,qy); int tmove_u = ISTILEMOVE_CC_PED(*(ptr-Game->TMSizeX)); int tmove_d = ISTILEMOVE_CC_PED(*(ptr+Game->TMSizeX)); int tmove_l = ISTILEMOVE_CC_PED(*(ptr-1)); int tmove_r = ISTILEMOVE_CC_PED(*(ptr+1)); // if in the middle of the tile if (rx==0 && ry==0) { int obstacleU = (P->MD.angle==0 && tmove_u==0); int obstacleR = (P->MD.angle==4 && tmove_r==0); int obstacleD = (P->MD.angle==8 && tmove_d==0); int obstacleL = (P->MD.angle==12 && tmove_l==0); int obstacle = (obstacleU||obstacleR||obstacleD||obstacleL); // turn if obstacle if (obstacle) { if (random(2)) P->MD.angle+=4; else P->MD.angle-=4; P->MD.angle&=15; // stop walking P->MD.speed=0; } else { // keep walking P->MD.speed=SPEED_LCD; } } else { // keep walking P->MD.speed=SPEED_LCD; } } //--------------------------------------------------------------------------- void Ped_OnNewAngle(TPed*P) { MD_OnNewAngle(&P->MD); Ped_LoadTD(P); } //--------------------------------------------------------------------------- // load tiledata ptr void Ped_LoadTD(TPed*P) { // tiles count = 2*80+1 = 161 int state_list[8]={0,1,2,1,0,3,4,3,}; int weapon = P->bullets?1:0; int angle = P->MD.angle; int state = (P->MD.speed?state_list[FrameCounter&7]:0); int tn=0; // if not dead if (P->health) { tn=1; // skip tile 'ped dead' if (weapon) tn+=80; // 80=5*16 tn+=(MUL4(angle)+angle); tn+=state; } P->TileData = Game->VP_Ped+MUL16(tn); } //--------------------------------------------------------------------------- void Ped_Shoot(TPed*P) { // infinite ammo for cops / gangsters / main ped if (P->skin!=PED_SKIN_CIV || P==Game->MainPed) P->bullets=99; // - ped has ammo if (!P->bullets) return; // - not in veh, if main ped if (P==Game->MainPed && Game->MainVeh) return; // - bullet is disable // -> get bullet ptr correspongind to ped TBullet*B=Game->Bullets; TPed*PP=Game->Peds; while (P!=PP) { PP++; B++; } // check if disable if (B->enable) return; // -> OK P->bullets--; // create bullet B->enable=1; B->MD.Pos = P->MD.Pos; B->MD.angle = P->MD.angle; B->MD.speed = 2*SPEED_LCD; // 2*SPEED_LCD B->Shooter=P; // OnChangeAngle MD_OnNewAngle(&B->MD); } //--------------------------------------------------------------------------- void Ped_Hurt(TPed*P) { // decrease health if (P->health>1) P->health--; else Ped_Kill(P); } //--------------------------------------------------------------------------- void Ped_Kill(TPed*P) { // do nothing if already dead if (P->health==0) return; // kill ped P->health=0; // dead_disappear_counter P->dead_disappear_counter=0; // stop walking P->MD.speed=0; // MISSIONS FLAGS Game->Miss.flag_pedkilled=1; Game->Miss.KilledPed=P; // STATS Game->Save.peds_killed++; // fugitive_factor Game->ff_killedped++; if (Game->ff_killedped>=10) { Game->ff_killedped=0; if (Game->Save.fugitive_factor<4) Game->Save.fugitive_factor++; } } //--------------------------------------------------------------------------- int Ped_IsIntoVeh(TPed*P) { return (P==Game->MainPed && Game->MainVeh); } //---------------------------------------------------------------------------