From 64b85f122e408e73b1c89c4e9140c99fdb621218 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 9 Apr 2016 13:21:19 +0100 Subject: [PATCH] Added components to jumpgate, to allow it to be targetted. --- gfx/entities/jumpgateNode.png | Bin 0 -> 1173 bytes src/battle/jumpgate.c | 65 +++++++++++++++++++++++++++++++--- src/battle/jumpgate.h | 7 ++++ src/defs.h | 13 +++---- src/galaxy/mission.c | 6 ++-- src/galaxy/mission.h | 2 +- 6 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 gfx/entities/jumpgateNode.png diff --git a/gfx/entities/jumpgateNode.png b/gfx/entities/jumpgateNode.png new file mode 100644 index 0000000000000000000000000000000000000000..1362b27fe78411a55801a63073eeab425a420265 GIT binary patch literal 1173 zcmV;G1Zw+e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00aF=L_t(Y$Gw%$YujcR$3K>1 zSy2?nk>lEpXJ=4a+%}Mqw4Dj;*g#x(9T6#rt{R=ly=a4}9c`{L^BkQdtD<0=I!R zAUj@a08fBNzyrfD+8+$4R4U&9U-`Z-o2H3nSsWi91CUOqDHIA6i$xSg34ren!}$8W z0F_Fm2;2v5?(gqYtJM%fy!8;0B(b@<$=22uzyWa2FbwmZfbr(Lwr%HkcXw$vn?xcJ zBvnFEC8DYXz`zrT@i!a}$z(EYZ*QaP`k%n|dC1Hghq`auc7A7P2iJ9p&P9nAWaMR; z_>znyj{qVN^iKkUdO+U_Xf~Vd?Cel3m-D)=-v@3@HjKW}^DiGhd`P?9CYFw&T#A!e znVy|J3h^3lhxJLT&Yx&tJUf+Q@~g)Kke`D zN1r}@N^~xYaw*QjMuMfS6zS_}a#xqhewrnfOEI6(m|2)1nv@Vi5PBhlGeM`_K?p%U zpZ}~>D*afkR{cqf?)ttj*J?E)kqGgE%=|Tt)GeLtwJf=n9N9z`ZAJsY4P6?G4UV*< zQOo?%d-P17TCK*$#)hmY%3a`x3E;MAng}6?&P9=zW#%r=kt`(1t>h@CuCfwaVSyw7 zr?Nvbb_js)`goUn^y)r+D`3zaV45cD>+84A1J*3d8c9!;h%d>g7iUQ=>tqvIR$?n$ zk*<(p34j(S5CbRC##wITTy%&p$#hkTL3e;c4DHaDj~@dvL-XDs%SGB z3nWRg#04%)<+i|IXfqnKs*0?Q6c$w_UctnWSpex{XVK&ajdVJlcU^a6qCgP10X@&d z4P8!UXVjK)wK(Av2RC%-c^-iqAOgX_6VoUe=hYPOq);g2pFe+&@J1%`UiN6!Z5oS> z(SycDZ2>sN;qcWVjk5-=x{dd;NB<;1i~)s0fpHj40gsBs;um{+dk9Yu)C0QDx;Ph| zsT7?=`*oR~H8?sv!m%8>&$@>a$~N0c^cO}bL7zO`^WXYe>HF-k=K76 n4u>B;aQ>H(`CkwHk6wQRq)8i`wLvO}00000NkvXXu0mjfg0vbj literal 0 HcmV?d00001 diff --git a/src/battle/jumpgate.c b/src/battle/jumpgate.c index 8fd5ede..ce46354 100644 --- a/src/battle/jumpgate.c +++ b/src/battle/jumpgate.c @@ -24,20 +24,25 @@ static void think(void); static void draw(void); static void handleFleeingEntities(void); static void addEscapeEffect(Entity *ent); +static void addNodes(Entity *jumpgate, long flags); +static void nodeDie(void); static SDL_Texture *portal; static float portalAngle; -Entity *spawnJumpgate(void) +Entity *spawnJumpgate(int side, long flags) { Entity *jumpgate = spawnEntity(); jumpgate->type = ET_JUMPGATE; - jumpgate->health = jumpgate->maxHealth = FPS; + jumpgate->health = jumpgate->maxHealth = 1; jumpgate->texture = getTexture("gfx/entities/jumpgate.png"); jumpgate->action = think; jumpgate->draw = draw; - jumpgate->flags |= EF_NO_MT_BOX; + jumpgate->side = side; + jumpgate->flags = EF_NO_MT_BOX+EF_IMMORTAL+EF_AI_IGNORE; + + addNodes(jumpgate, flags); portal = getTexture("gfx/entities/portal.png"); portalAngle = 0; @@ -47,6 +52,58 @@ Entity *spawnJumpgate(void) return jumpgate; } +static void addNodes(Entity *jumpgate, long flags) +{ + Entity *node; + SDL_Texture *nodeTexture; + int i; + + nodeTexture = getTexture("gfx/entities/jumpgateNode.png"); + + for (i = 0 ; i < 360 ; i += 36) + { + node = spawnEntity(); + STRNCPY(node->name, _("Jumpgate System Node"), MAX_NAME_LENGTH); + node->health = node->maxHealth = 75; + node->type = ET_COMPONENT; + node->offsetX = sin(TO_RAIDANS(i)) * 215; + node->offsetY = -cos(TO_RAIDANS(i)) * 215; + node->owner = jumpgate; + node->side = jumpgate->side; + node->texture = nodeTexture; + node->flags = EF_TAKES_DAMAGE; + node->die = nodeDie; + SDL_QueryTexture(node->texture, NULL, NULL, &node->w, &node->h); + + if (flags != -1) + { + node->flags |= flags; + } + + jumpgate->maxHealth++; + } + + jumpgate->health = jumpgate->maxHealth; +} + +static void nodeDie(void) +{ + self->alive = ALIVE_DEAD; + addSmallExplosion(); + playBattleSound(SND_EXPLOSION_1 + rand() % 4, self->x, self->y); + addDebris(self->x, self->y, 3 + rand() % 4); + + if (--battle.jumpgate->health == 1) + { + battle.jumpgate->flags |= EF_DISABLED; + + updateObjective("Jumpgate", TT_DESTROY); + updateCondition("Jumpgate", TT_DESTROY); + } + + runScriptFunction("JUMPGATE_HEALTH %d", battle.jumpgate->health); +} + int jumpgateEnabled(void) { return (battle.jumpgate && (!(battle.jumpgate->flags & EF_DISABLED))); @@ -54,7 +111,7 @@ int jumpgateEnabled(void) void activateJumpgate(int activate) { - if (battle.jumpgate) + if (battle.jumpgate && battle.jumpgate->health > 1) { if (activate) { diff --git a/src/battle/jumpgate.h b/src/battle/jumpgate.h index 194dc2e..860c56d 100644 --- a/src/battle/jumpgate.h +++ b/src/battle/jumpgate.h @@ -26,6 +26,13 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern int getDistance(int x1, int y1, int x2, int y2); extern void playBattleSound(int id, int x, int y); extern void blitRotated(SDL_Texture *texture, int x, int y, float angle); +extern char *getTranslatedString(char *string); +extern void addSmallExplosion(void); +extern void playBattleSound(int id, int x, int y); +extern void addDebris(int x, int y, int amount); +extern void runScriptFunction(char *format, ...); +extern void updateObjective(char *name, int type); +extern void updateCondition(char *name, int type); extern Battle battle; extern Entity *self; diff --git a/src/defs.h b/src/defs.h index f5eec66..7e5bf08 100644 --- a/src/defs.h +++ b/src/defs.h @@ -98,7 +98,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define EF_ROPED_ATTACHED (2 << 15) #define EF_NO_KILL_INC (2 << 16) #define EF_SHORT_RADAR_RANGE (2 << 17) -#define EF_NO_TARGET (2 << 18) +#define EF_NO_PLAYER_TARGET (2 << 18) +#define EF_AI_IGNORE (2 << 19) #define AIF_NONE 0 #define AIF_FOLLOWS_PLAYER (2 << 0) @@ -153,12 +154,12 @@ enum ET_FIGHTER, ET_ITEM, ET_WAYPOINT, + ET_COMPONENT, + ET_COMPONENT_GUN, + ET_COMPONENT_ENGINE, + ET_CAPITAL_SHIP, ET_JUMPGATE, - ET_MINE, - ET_CAPITAL_SHIP_GUN, - ET_CAPITAL_SHIP_COMPONENT, - ET_CAPITAL_SHIP_ENGINE, - ET_CAPITAL_SHIP + ET_MINE }; enum diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 039a509..50ee935 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -343,7 +343,7 @@ static void loadEntities(cJSON *node) number = getJSONValue(node, "number", 1); active = getJSONValue(node, "active", 1); scatter = getJSONValue(node, "scatter", 1); - side = getJSONValue(node, "side", SIDE_NONE); + side = lookup(getJSONValueStr(node, "side", "SIDE_NONE")); if (cJSON_GetObjectItem(node, "flags")) { @@ -360,7 +360,7 @@ static void loadEntities(cJSON *node) break; case ET_JUMPGATE: - e = spawnJumpgate(); + e = spawnJumpgate(side, flags); break; case ET_MINE: @@ -383,7 +383,7 @@ static void loadEntities(cJSON *node) STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH); } - if (flags != -1) + if (type != ET_JUMPGATE && flags != -1) { if (addFlags) { diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index eb36d89..b1a4d0a 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -34,7 +34,7 @@ extern void initPlayer(void); extern long flagsToLong(char *flags, int *add); extern Entity *spawnWaypoint(void); extern void selectWidget(const char *name, const char *group); -extern Entity *spawnJumpgate(void); +extern Entity *spawnJumpgate(int side, long flags); extern void failIncompleteObjectives(void); extern void completeConditions(void); extern void retreatEnemies(void);