From ad405c57ae9345056e5f0af4aa6f93e72110928e Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 11 Nov 2015 06:46:58 +0000 Subject: [PATCH] Start of civilian ships: will follow player when close and flee in to extraction points. --- data/fighters/civilian.json | 10 +++++ data/fighters/list.json | 3 +- gfx/craft/civilian01.png | Bin 0 -> 1897 bytes gfx/craft/civilian02.png | Bin 0 -> 2272 bytes src/battle/ai.c | 69 +++++++++++++++++++++++++++++++++++ src/battle/ai.h | 1 + src/battle/extractionPoint.c | 8 +++- src/battle/fighterDefs.c | 5 +++ src/battle/fighterDefs.h | 1 + src/battle/fighters.c | 31 +++++++++++----- src/battle/fighters.h | 1 + src/defs.h | 1 + src/system/lookup.c | 2 + 13 files changed, 120 insertions(+), 12 deletions(-) create mode 100644 data/fighters/civilian.json create mode 100644 gfx/craft/civilian01.png create mode 100644 gfx/craft/civilian02.png diff --git a/data/fighters/civilian.json b/data/fighters/civilian.json new file mode 100644 index 0000000..62b0786 --- /dev/null +++ b/data/fighters/civilian.json @@ -0,0 +1,10 @@ +{ + "name" : "Civilian", + "health" : 10, + "shield" : 0, + "speed" : 2, + "reloadTime" : 0, + "shieldRechargeRate" : 0, + "textureName" : "gfx/craft/civilian01.png", + "flags" : "EF_CIVILIAN+EF_FLEEING" +} diff --git a/data/fighters/list.json b/data/fighters/list.json index 1f599c8..451ccd7 100644 --- a/data/fighters/list.json +++ b/data/fighters/list.json @@ -11,5 +11,6 @@ "data/fighters/nymph.json", "data/fighters/firefly.json", "data/fighters/hyena.json", - "data/fighters/leopard.json" + "data/fighters/leopard.json", + "data/fighters/civilian.json" ] diff --git a/gfx/craft/civilian01.png b/gfx/craft/civilian01.png new file mode 100644 index 0000000000000000000000000000000000000000..b99cb4e3e4e0284024281730050d181bfe879778 GIT binary patch literal 1897 zcmV-v2bTDWP)Px#24YJ`L;zC&Qvg#MXr99W000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i^h* z4-_dp)TDF(000?uMObu0Z*6U5Zg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z97I)Bq$BC=?WMZ9dSO82eJAbh?L|5gRaKV*|6>mm%d)Vgix7h0;o&7K8y+4mT|}h2 zq~3oP0zRLQCyyR2DWxBl@+XfT;q&=EKLNkrkFM(s3=FK8F9QPu=(@h7=YI~9e_8#@ j_fvd7%d`9sJ=6aO?Asr*3_+?z00000NkvXXu0mjfA^UQ< literal 0 HcmV?d00001 diff --git a/gfx/craft/civilian02.png b/gfx/craft/civilian02.png new file mode 100644 index 0000000000000000000000000000000000000000..5b208beb2dd990beca1427221fcc5f1a17908de7 GIT binary patch literal 2272 zcmV<62p{)}P)Px#24YJ`L;(K){{R4uzepYc000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i^e) z6et$1lE(J{000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}000O(NklVzJ1E4I40jOXBxm*sv-~S)u z!SqAmU0q#dvsnP<=H~Evz394*q9~Zn-!(@yn5{RP6`|rQc%9Setuv)E5PEO+Y z`)`SND;F3&Jw0@HcN2|95k-;K)>gVYJ2`gj7!-@tuc)Wi=|rxQk*j2Colfdk)I+hz zv17;R>g=SowG~kmiAJMzcX!j%({oFAe4l{P-ri1odpoi$v*&@2c|?APY&J_OrQ-E^ zIey{QJvDs`44Gr<` zyYG@nBv6!U1_riLAyzQ_&M=CiP%IW%TwLVp)vEy1)zu-(G8T)4L?XdczkG_Eo?~R> zZzK{)6h&e8?%jO!(MM>SMj#O2(xpoPCJSJ6b#>9Zemzd7lbw$}#_4~YW;QrWG#W(^ z1jfe3xOnLzZnvAgd-ozq64|VVVHi|aR^oOy@Zf`e3=Itt3R}bebohe3H@AqkQ(yPxyzWnk_&YnF>B9Wk2EK(>Gh{a+|PEK;=$`vx14Euh!kG3^!tXj2- zSS-eeAAU%MD3Z(T4D|Q&$+>gfd+)tmym+xx2P#C7rKKfQRb^p*ft+5dY@#TV&Sbc9 zB&eEQj^q|+&CYF*_$IbCOA zegRcgS;j19!JmeQsjjZZZnrZtGlRonFI6c)z&^Q$j@(O(o*L!r*;xQQ&wPN#JRT38XFdSn>)BaGPmR)%dkOpG9t1)7wuzN=+wFF$tE>6b@bC=+9*+l`-G-tl zw6?BhWaMO-z-~HQi!-+&9Ouh9RFqzOajiyzrP*W=5a0r*nh0o{1@AtE^v5`n5f^pqo+tzJN zO-+>uM8CPpiu!u$>gouE!noaT78VxJG>xUDC0s5S$z&;=_Wh!TU@*w>;JN3X6&>&j-N3zyLEdGc0442{bh|Az3Bb+S+it?<@N=9**5|S)bc|A8l=IjDIm+ zCMW>(_xGcwR6?N;nwH_^mtQ84NMJIVNT<^*E-s>~Dr?uSrMbDebW5ibS(X8CIh|zE zX_}jx$z(E|J$shL#YNKTG?kT=Jp1gkD2l@T{5+vh2sNeB-`~&Cqen|w;IKQ$X0zzJ zj$s&RnuZ_zGU?R8>WiBqT{fRaHzT69rwz<#J)MSct`9 zq*5u8$s~dxplPMbsp~q~Y!-*zaU%^69y*BCDv`_O$QSbXd_ImGIYM)DGcK2l3l}aB zkH?WD2|ZsR6bg}6RVF4Tn3$L#t(L5(=L<-ZL_8kn!i5XCTrQfMn>lji2tJ>Wd?8OR zm&0n6IC$vb4FWAKE!5SmKoA7flv;kQ?BBniy1Kd>IWCH%GilP9G?|Q6mS-|rS-xEP zmYdZ6{rk&JPfe)^fVHjAgRt_INT;6}vSpcrZt}#43Ou+AFhu8bvhlt1HG1jbUznw3Zant-E u*)7kmS<`NKJf2(bz3czoU3~A#IR6F%Y@AjziY>ta0000x - 500, self->y - 500, 1000, 1000, self); + i = 0; + + e = candidates[i]; + + self->target = NULL; + + while (e) + { + if (e->type == ET_EXTRACTION_POINT) + { + self->target = e; + } + + i++; + + e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL; + } + + if (self->target != NULL) + { + self->action = moveToExtractionPoint; + } + + return self->target != NULL; +} + +static int nearEnemies(void) +{ + return 0; +} + +static void moveToExtractionPoint(void) +{ + faceTarget(self->target); + + applyFighterThrust(); +} + +static void lookForPlayer(void) +{ + if (getDistance(self->x, self->y, player->x, player->y) < 1000) + { + moveToPlayer(); + return; + } + + applyFighterBrakes(); +} diff --git a/src/battle/ai.h b/src/battle/ai.h index ad424ac..fdbeb50 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -34,6 +34,7 @@ extern float getAngle(int x1, int y1, int x2, int y2); extern void applyFighterThrust(void); extern void applyFighterBrakes(void); extern void addHudMessage(SDL_Color c, char *format, ...); +extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Battle battle; extern Colors colors; diff --git a/src/battle/extractionPoint.c b/src/battle/extractionPoint.c index 11efc35..f772a35 100644 --- a/src/battle/extractionPoint.c +++ b/src/battle/extractionPoint.c @@ -58,11 +58,17 @@ static void handleFleeingEntities(void) candidates = getAllEntsWithin(self->x, self->y, self->w, self->h, self); i = 0; - for (e = candidates[i] ; (e != NULL && i < MAX_GRID_CANDIDATES) ; i++) + e = candidates[i]; + + while (e) { if (e->health > 0 && e->flags & EF_FLEEING && getDistance(e->x, e->y, self->x, self->y) <= 64) { e->alive = ALIVE_DEAD; } + + i++; + + e = (i < MAX_GRID_CANDIDATES) ? candidates[i] : NULL; } } diff --git a/src/battle/fighterDefs.c b/src/battle/fighterDefs.c index 31cde82..e5b233a 100644 --- a/src/battle/fighterDefs.c +++ b/src/battle/fighterDefs.c @@ -126,6 +126,11 @@ static void loadFighterDef(char *filename) f->missiles.ammo = f->missiles.maxAmmo = cJSON_GetObjectItem(node, "ammo")->valueint; } + if (cJSON_GetObjectItem(root, "flags")) + { + f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring); + } + f->separationRadius = MAX(f->w, f->h); f->separationRadius *= 2; diff --git a/src/battle/fighterDefs.h b/src/battle/fighterDefs.h index 57d2506..1db55c2 100644 --- a/src/battle/fighterDefs.h +++ b/src/battle/fighterDefs.h @@ -27,4 +27,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(char *filename); extern SDL_Texture *getTexture(char *filename); extern long lookup(char *name); +extern long flagsToLong(char *flags); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 04aad7f..be9fd47 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -71,7 +71,15 @@ Entity *spawnFighter(char *name, int x, int y, int side) randomizeDart(f); } - f->defaultAction = doAI; + if (f->flags & EF_CIVILIAN) + { + f->defaultAction = doCivilianAI; + } + else + { + f->defaultAction = doAI; + } + f->die = die; return f; @@ -271,17 +279,20 @@ static void separate(void) while (e) { - distance = getDistance(e->x, e->y, self->x, self->y); - - if (distance > 0 && distance < self->separationRadius) + if (e->type == ET_FIGHTER) { - angle = getAngle(self->x, self->y, e->x, e->y); + distance = getDistance(e->x, e->y, self->x, self->y); - dx += sin(TO_RAIDANS(angle)); - dy += -cos(TO_RAIDANS(angle)); - force += (self->separationRadius - distance) * 0.005; - - count++; + if (distance > 0 && distance < self->separationRadius) + { + angle = getAngle(self->x, self->y, e->x, e->y); + + dx += sin(TO_RAIDANS(angle)); + dy += -cos(TO_RAIDANS(angle)); + force += (self->separationRadius - distance) * 0.005; + + count++; + } } i++; diff --git a/src/battle/fighters.h b/src/battle/fighters.h index 1d59898..62ac8fe 100644 --- a/src/battle/fighters.h +++ b/src/battle/fighters.h @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern SDL_Texture *getTexture(char *filename); extern void doAI(void); +extern void doCivilianAI(void); extern void blitRotated(SDL_Texture *t, int x, int y, int angle); extern void blit(SDL_Texture *t, int x, int y, int center); extern float getAngle(int x1, int y1, int x2, int y2); diff --git a/src/defs.h b/src/defs.h index 35ac3bd..ba0e3e9 100644 --- a/src/defs.h +++ b/src/defs.h @@ -66,6 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EF_FLEES (2 << 4) #define EF_FLEEING (2 << 5) #define EF_NO_MT_BOX (2 << 6) +#define EF_CIVILIAN (2 << 7) enum { diff --git a/src/system/lookup.c b/src/system/lookup.c index 158b86e..ae29048 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -38,6 +38,8 @@ void initLookups(void) addLookup("EF_IMMORTAL", EF_IMMORTAL); addLookup("EF_MISSION_TARGET", EF_MISSION_TARGET); addLookup("EF_FLEES", EF_FLEES); + addLookup("EF_FLEEING", EF_FLEEING); + addLookup("EF_CIVILIAN", EF_CIVILIAN); addLookup("TT_DESTROY", TT_DESTROY); addLookup("TT_DISABLE", TT_DISABLE);