static void init() { char display[MAX_VALUE_LENGTH]; Entity *e; setEntityAnimation(self, "STAND"); snprintf(display, MAX_VALUE_LENGTH, "%s_DISPLAY", self->objectiveName); e = getEntityByObjectiveName(display); if (e == NULL) { showErrorAndExit("Jigsaw Puzzle could not find display %s", display); } self->target = e; if (self->mental != -3) { self->touch = &touch; self->activate = &activate; } self->action = &entityWait; }
static void init() { char display[MAX_VALUE_LENGTH]; Entity *e; if (self->active == FALSE) { setEntityAnimation(self, "STAND"); snprintf(display, MAX_VALUE_LENGTH, "%s_DISPLAY", self->objectiveName); e = getEntityByObjectiveName(display); if (e == NULL) { showErrorAndExit("Code Door could not find display %s", display); } self->target = e; self->touch = &touch; self->activate = &activate; } if (strlen(self->requires) == 0) { setEntityAnimation(self, "WALK"); } self->action = &entityWait; }
static void init() { Entity *e; /* Set target to power generator */ e = getEntityByObjectiveName(self->requires); if (e == NULL) { showErrorAndExit("Energy Drainer could not find Entity %s", self->requires); } self->targetX = e->x + e->w / 2; self->targetY = e->y + e->h / 2; self->targetX -= self->w / 2; self->targetY -= self->h / 2; self->target = e; self->y = self->startY; self->action = &fly; self->mental = 1; createBeam(); }
static void initEnergyBar() { Entity *e = getFreeEntity(); if (e == NULL) { showErrorAndExit("No free slots to add the Awesome Boss Energy Bar"); } loadProperties("boss/awesome_boss_energy_bar", e); e->action = &energyBarWait; e->draw = &energyBarDraw; e->type = ENEMY; e->active = FALSE; e->head = self; setEntityAnimation(e, "STAND"); self->head = getEntityByObjectiveName("AWESOME_BOSS_METER"); if (self->head == NULL) { showErrorAndExit("Awesome Boss could not find meter"); } self->head->damage++; }
void killEntity(char *name) { Entity *e = getEntityByObjectiveName(name); if (e != NULL) { e->inUse = FALSE; } }
void getInventoryItemFromScript(char *line) { char command[15], itemName[MAX_VALUE_LENGTH], entityName[MAX_VALUE_LENGTH], quiet[MAX_VALUE_LENGTH]; int quantity, success, failure, quantityToRemove, read; Entity *e, *item; read = sscanf(line, "%s \"%[^\"]\" %d %d %s %d %d %s", command, itemName, &quantity, &quantityToRemove, entityName, &success, &failure, quiet); if (read < 7) { showErrorAndExit("HAS_ITEM or REMOVE command has wrong number of arguments"); } e = getEntityByObjectiveName(entityName); if (e == NULL) { showErrorAndExit("Could not find Entity %s to give item %s to", entityName, itemName); } item = getInventoryItemByObjectiveName(itemName); if (item != NULL && (item->health >= quantity || quantity == 1)) { if (strcmpignorecase(command, "REMOVE") == 0) { item->health -= quantityToRemove; updateTrigger(itemName, quantityToRemove); updateGlobalTrigger(itemName, quantityToRemove); if (item->health <= 0 || quantityToRemove == -1) { item->health = 0; removeInventoryItemByObjectiveName(itemName); if (read == 7) { setInfoBoxMessage(90, 255, 255, 255, _("Removed %s"), _(itemName)); } } } e->health = success; } else { e->health = failure; } }
void entityWalkToEntity(Entity *e, char *coords) { int read; char wait[10], anim[20], entityName[MAX_VALUE_LENGTH]; Entity *e2; read = sscanf(coords, "%s %s %s", entityName, wait, anim); e2 = getEntityByObjectiveName(entityName); if (e2 == NULL) { showErrorAndExit("Could not find Entity %s to walk to", entityName); } e->targetX = e2->x; e->targetY = e2->y; if (!(e->flags & FLY)) { e->targetY = e->y; } if (strcmpignorecase(wait, "WAIT") == 0) { e->action = &scriptEntityMoveToTarget; setScriptCounter(1); } else { e->action = &entityMoveToTarget; } e->face = (e->x < e->targetX) ? RIGHT : LEFT; if (read == 3) { setEntityAnimation(e, anim); } else { setEntityAnimation(e, "WALK"); } if (e->type == PLAYER) { syncWeaponShieldToPlayer(); } }
static void init() { Entity *e = getEntityByObjectiveName(self->requires); if (e == NULL) { showErrorAndExit("Balloon couldn't find target %s", self->requires); } self->face = RIGHT; self->target = e; self->target->flags |= HELPLESS; self->action = &hover; setEntityAnimationByID(self, self->mental); }
static void introWait() { if (self->head->mental == 5 && self->head->thinkTime == 0) { self->target = getEntityByObjectiveName(self->requires); if (self->target == NULL) { showErrorAndExit("Awesome Boss %s cannot find %s", self->objectiveName, self->requires); } self->action = &teleportOut; self->touch = &entityTouch; initEnergyBar(); } checkToMap(self); }
static void appear() { Entity *e = getEntityByObjectiveName("AZRIEL_GRAVE"); if (e == NULL) { showErrorAndExit("Azirel cannot find AZRIEL_GRAVE"); } self->layer = BACKGROUND_LAYER; self->y = e->y + e->h; self->active = FALSE; self->action = &createLightBeam; self->flags &= ~NO_DRAW; e->mental = 1; self->thinkTime = 120; }
static void init() { Entity *e; if (self->mental == 0) { e = getFreeEntity(); if (e == NULL) { showErrorAndExit("No free slots to add the Soul Merger Control Panel Energy Bar"); } loadProperties("boss/awesome_boss_energy_bar", e); e->action = &energyBarWait; e->draw = &energyBarDraw; e->type = ENEMY; e->head = self; setEntityAnimation(e, "STAND"); self->action = &entityWait; self->target = getEntityByObjectiveName(self->requires); if (self->target == NULL) { showErrorAndExit("Control Panel cannot find Soul Merger %s", self->requires); } self->activate = &activate; } }
void addDecorationFromScript(char *line) { char decorationName[MAX_VALUE_LENGTH], entityName[MAX_VALUE_LENGTH]; Entity *e; sscanf(line, "%s \"%[^\"]\"", decorationName, entityName); if (strcmpignorecase(entityName, "Edgar") == 0) { e = &player; } else { e = getEntityByObjectiveName(entityName); } if (e == NULL) { showErrorAndExit("Decoration could not find Entity %s", entityName); } addDecoration(decorationName, e->x + e->w / 2, e->y + e->h / 2); }
int patchEntities(double versionFile, char *mapName) { char patchFile[MAX_PATH_LENGTH], *line, *savePtr, itemName[MAX_VALUE_LENGTH]; char key[MAX_VALUE_LENGTH], value[MAX_VALUE_LENGTH]; int skipping = FALSE, x, y, read, found, saveMap; unsigned char *buffer; Entity *e; EntityList *el, *entities; Target *t; savePtr = NULL; snprintf(patchFile, sizeof(patchFile), "data/patch/%0.2f.dat", versionFile); saveMap = TRUE; if (existsInPak(patchFile) == TRUE) { buffer = loadFileFromPak(patchFile); line = strtok_r((char *)buffer, "\n", &savePtr); while (line != NULL) { if (line[strlen(line) - 1] == '\n') { line[strlen(line) - 1] = '\0'; } if (line[strlen(line) - 1] == '\r') { line[strlen(line) - 1] = '\0'; } sscanf(line, "%s", itemName); if (strcmpignorecase(itemName, "MAP_NAME") == 0) { sscanf(line, "%*s %s\n", itemName); skipping = strcmpignorecase(itemName, mapName) == 0 ? FALSE : TRUE; } else if (strcmpignorecase(itemName, "MODIFY_OBJECTIVE") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\" \"%[^\"]\"", key, value); modifyObjective(key, value); } else if (strcmpignorecase(itemName, "REMOVE_OBJECTIVE") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\"", key); removeObjective(key); } else if (strcmpignorecase(itemName, "REMOVE_TRIGGER") == 0 && skipping == FALSE) { sscanf(line, "%*s \"%[^\"]\"", key); removeGlobalTrigger(key); removeTrigger(key); } else if (strcmpignorecase(line, "ADD_ENTITY") == 0 && skipping == FALSE) { loadResources(savePtr); } else if (strcmpignorecase(itemName, "REMOVE_ENTITY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %s %d %d", itemName, &x, &y); found = FALSE; e = getEntityByObjectiveName(itemName); if (e != NULL) { e->inUse = FALSE; found = TRUE; } if (found == FALSE) { t = getTargetByName(itemName); if (t != NULL) { t->active = FALSE; found = TRUE; } } if (found == FALSE && read == 3) { e = getEntityByStartXY(x, y); if (e != NULL) { e->inUse = FALSE; found = TRUE; } } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %s %s %s", itemName, key, value); if (strcmpignorecase(itemName, "PLAYER") == 0) { e = &player; } else { e = getEntityByObjectiveName(itemName); } if (e != NULL) { if (strcmpignorecase(value, "NULL") == 0) { STRNCPY(value, "", sizeof(value)); } setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY_BY_START") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d %s %[^\n]s", &x, &y, key, value); e = getEntityByStartXY(x, y); if (e != NULL) { setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "UPDATE_ENTITY_BY_XY") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d %s %[^\n]s", &x, &y, key, value); e = getEntityByXY(x, y); if (e != NULL) { setProperty(e, key, value); } } else if (strcmpignorecase(itemName, "TRANSLATE_ENTITIES") == 0 && skipping == FALSE) { read = sscanf(line, "%*s %d %d", &x, &y); entities = getEntities(); player.x -= x; player.y -= y; for (el=entities->next;el!=NULL;el=el->next) { e = el->entity; e->x -= x; e->y -= y; if (e->startX - x > 0) { e->startX -= x; } if (e->startY - y > 0) { e->startY -= y; } if (e->endX - x > 0) { e->endX -= x; } if (e->endY - y > 0) { e->endY -= y; } } t = getTargets(); for (x=0;x<MAX_TARGETS;x++) { if (t[x].active == TRUE) { if (t[x].x - x > 0) { t[x].x -= x; } if (t[x].y - y > 0) { t[x].y -= y; } } } } else if (strcmpignorecase(itemName, "RENAME_MAP") == 0 && skipping == FALSE) { saveMap = FALSE; } line = strtok_r(NULL, "\n", &savePtr); } free(buffer); } return saveMap; }
static void addChains() { int i; Entity **chains, *chaos; chaos = getEntityByObjectiveName("CHAOS"); if (chaos == NULL) { showErrorAndExit("Chaos Chain Base cannot find Chaos"); } chains = malloc(self->mental * sizeof(Entity *)); if (chains == NULL) { showErrorAndExit("Failed to allocate a whole %d bytes for Chaos's chains...", self->mental * (int)sizeof(Entity *)); } for (i=self->mental-1;i>=0;i--) { chains[i] = getFreeEntity(); if (chains[i] == NULL) { showErrorAndExit("No free slots to add a Chaos Chain"); } loadProperties("item/chaos_chain", chains[i]); chains[i]->face = self->face; chains[i]->action = &chainWait; chains[i]->creditsAction = &creditsChainWait; chains[i]->draw = &drawLoopingAnimationToMap; setEntityAnimation(chains[i], "STAND"); } /* Link the sections */ for (i=self->mental-1;i>=0;i--) { if (i == 0) { self->target = chains[i]; } else { chains[i - 1]->target = chains[i]; } chains[i]->head = self; } free(chains); self->head = chaos; self->action = &chainBaseWait; self->creditsAction = &creditsChainBaseWait; }
static void entityWait() { int rand; Entity *disintegrationShield; self->thinkTime--; if (self->thinkTime <= 0 && player.health > 0) { if (self->startX == 0) { switch ((int)self->startY) { case 0: self->action = &callSummonersInit; break; case 3: self->action = &disintegrationAttackInit; break; default: self->action = &createShieldInit; break; } } else { disintegrationShield = getInventoryItemByObjectiveName("Disintegration Shield"); if (disintegrationShield == NULL) { disintegrationShield = getEntityByObjectiveName("Disintegration Shield"); } switch (disintegrationShield->health) { case 1: rand = prand() % 3; break; case 2: rand = prand() % 5; break; case 3: rand = prand() % 6; break; default: rand = 6; break; } if (getEntityByName("enemy/flame_statue") != NULL) { switch (rand) { case 0: self->action = &plasmaAttackInit; break; case 1: self->action = &flameWaveDropInit; break; case 2: self->action = &destroyFloorInit; break; case 3: self->action = &riftAttackInit; break; case 6: self->action = &finalAttackInit; break; default: self->action = &holdPersonInit; break; } } else { switch (rand) { case 0: self->action = &plasmaAttackInit; break; case 1: self->action = &flameWaveDropInit; break; case 2: self->action = &destroyFloorInit; break; case 3: self->action = &riftAttackInit; break; case 4: self->action = &holdPersonInit; break; case 6: self->action = &finalAttackInit; break; default: self->action = &statueAttackInit; break; } } } } hover(); }
static void doIntro() { char name[MAX_VALUE_LENGTH]; Entity *e; checkToMap(self); self->thinkTime--; self->endX = 1; self->flags |= LIMIT_TO_SCREEN; if (self->thinkTime <= 0) { self->flags |= DO_NOT_PERSIST; snprintf(name, sizeof(name), "boss/awesome_boss_%d", self->mental); e = addEnemy(name, self->x - 8 * self->mental, self->y - 64); e->face = RIGHT; e->active = TRUE; e->targetX = e->x; e->targetY = e->y; e->startX = e->x; e->startY = e->y; e->maxHealth = e->health = self->maxHealth; e->endX = self->mental; calculatePath(e->x, e->y, e->targetX, e->targetY, &e->dirX, &e->dirY); e->flags |= (NO_DRAW|HELPLESS|TELEPORTING|NO_END_TELEPORT_SOUND|LIMIT_TO_SCREEN); e->action = &introWait; e->head = self; playSoundToMap("sound/common/spell", -1, self->x, self->y, 0); self->thinkTime = 30; self->mental++; if (self->mental == 5) { self->target = getEntityByObjectiveName(self->requires); if (self->target == NULL) { showErrorAndExit("Awesome Boss %s cannot find %s", self->objectiveName, self->requires); } self->thinkTime = 60; self->action = &entityWait; } } }