1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-10 15:59:53 +00:00
hyperrogue/game.cpp

8875 lines
276 KiB
C++
Raw Normal View History

// Hyperbolic Rogue - Game routines
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
2015-08-08 13:57:52 +00:00
/** \file game.cpp
* \brief Routines for game itself: movement of PC and monsters, basic mechanics, etc.
*/
2015-08-08 13:57:52 +00:00
#include "hyper.h"
namespace hr {
2019-08-09 20:37:11 +00:00
#if HDR
enum eLastmovetype { lmSkip, lmMove, lmAttack, lmPush, lmTree, lmInstant };
extern eLastmovetype lastmovetype, nextmovetype;
enum eForcemovetype { fmSkip, fmMove, fmAttack, fmInstant, fmActivate };
extern eForcemovetype forcedmovetype;
#endif
2019-08-09 19:00:52 +00:00
EX int lastsafety;
EX int mutantphase;
EX int turncount;
EX int rosewave, rosephase;
EX int avengers, mirrorspirits, wandering_jiangshi, jiangshi_on_screen;
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX int gamerange_bonus = 0;
EX int gamerange() { return getDistLimit() + gamerange_bonus; }
2016-08-26 09:58:03 +00:00
cell *lastmove;
2019-05-28 23:09:38 +00:00
eLastmovetype lastmovetype, nextmovetype;
eForcemovetype forcedmovetype;
2015-08-08 13:57:52 +00:00
EX bool hauntedWarning;
EX bool survivalist;
2015-08-08 13:57:52 +00:00
EX bool hardcore = false;
EX int hardcoreAt;
2016-01-02 10:09:13 +00:00
2017-12-05 18:43:45 +00:00
set<int> snaketypes;
#if HDR
2017-09-30 09:46:41 +00:00
#define HF_BUG Flag(0)
#define HF_EARTH Flag(1)
#define HF_BIRD Flag(2)
#define HF_LEADER Flag(3)
#define HF_HEX Flag(4)
#define HF_WHIRLPOOL Flag(5)
#define HF_WATER Flag(6)
#define HF_AIR Flag(7)
#define HF_MUTANT Flag(8)
#define HF_OUTLAW Flag(9)
#define HF_WHIRLWIND Flag(10)
#define HF_ROSE Flag(11)
#define HF_DRAGON Flag(12)
#define HF_KRAKEN Flag(13)
#define HF_SHARK Flag(14)
#define HF_BATS Flag(15)
#define HF_REPTILE Flag(16)
#define HF_EAGLES Flag(17)
#define HF_SLOW Flag(18)
#define HF_FAST Flag(19)
#define HF_WARP Flag(20)
#define HF_MOUSE Flag(21)
#define HF_RIVER Flag(22)
#define HF_MIRROR Flag(23)
#define HF_VOID Flag(24)
#define HF_HUNTER Flag(25)
#define HF_FAILED_AMBUSH Flag(26)
2018-01-02 10:15:42 +00:00
#define HF_MAGNET Flag(27)
#define HF_HEXD Flag(28)
#define HF_ALT Flag(29)
#define HF_MONK Flag(30)
2018-12-21 13:41:23 +00:00
#define HF_WESTWALL Flag(31)
#endif
2018-01-02 10:15:42 +00:00
EX flagtype havewhat, hadwhat;
2016-01-02 10:09:13 +00:00
EX bool seenSevenMines = false;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool pureHardcore() { return hardcore && hardcoreAt < PUREHARDCORE_LEVEL; }
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool canmove = true;
2016-01-02 10:09:13 +00:00
EX int sagephase = 0;
2015-08-08 13:57:52 +00:00
/** number of Grails collected, to show you as a knight */
EX int knighted = 0;
2015-08-08 13:57:52 +00:00
EX bool usedSafety = false;
EX eLand safetyland;
EX int safetyseed;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
int showid = 0;
2016-01-02 10:09:13 +00:00
/** last move was invisible */
2019-08-09 21:24:33 +00:00
EX bool invismove = false;
/** last move was invisible due to Orb of Fish (thus Fish still see you)*/
EX bool invisfish = false;
2015-08-08 13:57:52 +00:00
EX int noiseuntil; // noise until the given turn
2015-08-08 13:57:52 +00:00
EX void createNoise(int t) {
2016-08-26 09:58:03 +00:00
noiseuntil = max(noiseuntil, turncount+t);
invismove = false;
if(shmup::on) shmup::visibleFor(100 * t);
}
2015-08-08 13:57:52 +00:00
EX int currentLocalTreasure;
2015-08-08 13:57:52 +00:00
EX bool landvisited[landtypes];
2015-08-08 13:57:52 +00:00
bool eq(short a, short b) { return a==b; }
/** for treasures, the number collected; for orbs, the number of charges */
2019-08-09 19:00:52 +00:00
EX array<int, ittypes> items;
/** how many instances of each monster type has been killed */
2019-08-09 19:00:52 +00:00
EX array<int, motypes> kills;
2018-01-25 16:20:41 +00:00
2019-08-09 21:24:33 +00:00
EX int explore[10], exploreland[10][landtypes], landcount[landtypes];
EX map<modecode_t, array<int, ittypes> > hiitems;
EX bool orbused[ittypes], lastorbused[ittypes];
/** should we center the screen on the PC? */
EX bool playermoved = true;
/** if false, make the PC look in direction cwt.spin (after attack); otherwise, make them look the other direction (after move) */
EX bool flipplayer = true;
/** did the player cheat? how many times? */
EX int cheater = 0;
2015-08-08 13:57:52 +00:00
/** this value is used when using Orb of Safety in the Camelot in Pure Tactics Mode */
EX int anthraxBonus = 0;
2015-08-08 13:57:52 +00:00
/** the list of all nearby cells, according to cpdist */
EX vector<cell*> dcal;
/** the list of all nearby cells, according to current pathdist */
EX vector<cell*> pathq;
2015-08-08 13:57:52 +00:00
/** offscreen cells to take care off */
EX vector<cell*> offscreen;
2016-01-02 10:09:13 +00:00
/** list of monsters to move (pathq restriced to monsters) */
EX vector<cell*> pathqm;
2015-08-08 13:57:52 +00:00
/** list of cells that the monsters are targetting (PCs, allies, Thumpers, etc.) */
EX vector<cell*> targets;
/** monsters of specific types to move */
2017-07-22 23:33:27 +00:00
vector<cell*> worms, ivies, ghosts, golems, hexsnakes;
2015-08-08 13:57:52 +00:00
/** temporary changes during bfs */
vector<pair<cell*, eMonster>> tempmonsters;
2015-08-08 13:57:52 +00:00
/** additional direction information for BFS algorithms.
* It remembers from where we have got to this location
* the opposite cell will be added to the queue first,
* which helps the AI.
**/
EX vector<int> reachedfrom;
2015-08-08 13:57:52 +00:00
/** monsters to move, ordered by the number of possible good moves */
2019-03-02 23:43:31 +00:00
vector<cell*> movesofgood[MAX_EDGE+1];
2015-08-08 13:57:52 +00:00
/** The position of the first cell in dcal in distance 7. New wandering monsters can be generated in dcal[first7..]. */
EX int first7;
2015-08-08 13:57:52 +00:00
/** Cellwalker describing the single player. Also used temporarily in shmup and multiplayer modes. */
EX cellwalker cwt;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX inline cell*& singlepos() { return cwt.at; }
EX inline bool singleused() { return !(shmup::on || multi::players > 1); }
2015-08-08 13:57:52 +00:00
2019-08-10 17:30:21 +00:00
/** the main random number generator for the game.
*
* All the random calls related to the game mechanics (land generation, AI...) should use hrngen.
*
* Random calls not related to the game mechanics (graphical effects) should not use hrngen.
*
* This ensures that the game should unfold exactly the same if given the same seed and the same input.
*/
EX std::mt19937 hrngen;
2016-01-02 10:09:13 +00:00
2019-08-10 17:30:21 +00:00
/** initialize \link hrngen \endlink */
2019-08-09 19:00:52 +00:00
EX void shrand(int i) {
hrngen.seed(i);
2016-01-02 10:09:13 +00:00
}
2019-08-10 17:30:21 +00:00
/** generate a large number with \link hrngen \endlink */
2019-08-09 19:00:52 +00:00
EX int hrandpos() { return hrngen() & HRANDMAX; }
2016-08-26 09:58:03 +00:00
2019-08-10 17:30:21 +00:00
/** A random integer from [0..i), generated from \link hrngen \endlink.
* We are using our own implementations rather than ones from <random>,
* to make sure that they return the same values on different compilers.
**/
2019-08-09 19:00:52 +00:00
EX int hrand(int i) {
unsigned d = hrngen() - hrngen.min();
long long m = (long long) (hrngen.max() - hrngen.min()) + 1;
m /= i;
d /= m;
if(d < (unsigned) i) return d;
return hrand(i);
2016-01-02 10:09:13 +00:00
}
2019-08-09 23:56:00 +00:00
#if HDR
template<class T, class... U> T pick(T x, U... u) { std::initializer_list<T> i = {x,u...}; return *(i.begin() + hrand(1+sizeof...(u))); }
template<class T> void hrandom_shuffle(T* x, int n) { for(int k=1; k<n; k++) swap(x[k], x[hrand(k+1)]); }
#endif
2019-08-10 17:30:21 +00:00
/** Use \link hrngen \endlink to generate a floating point number between 0 and 1.
*/
2019-08-09 19:00:52 +00:00
EX ld hrandf() {
return (hrngen() - hrngen.min()) / (hrngen.max() + 1.0 - hrngen.min());
2017-12-16 08:03:50 +00:00
}
2019-08-10 17:30:21 +00:00
/** Returns an integer corresponding to the current state of \link hrngen \endlink.
*/
2019-08-09 19:00:52 +00:00
EX int hrandstate() {
std::mt19937 r2 = hrngen;
return r2() & HRANDMAX;
}
2019-08-09 19:00:52 +00:00
EX void initcell(cell *c) {
2015-08-08 13:57:52 +00:00
c->mpdist = INFD; // minimum distance from the player, ever
c->cpdist = INFD; // current distance from the player
2017-03-23 10:53:57 +00:00
c->pathdist = PINFD;// current distance from the player, along paths (used by yetis)
2016-08-26 09:58:03 +00:00
c->landparam = 0; c->landflags = 0; c->wparam = 0;
c->listindex = -1;
2015-08-08 13:57:52 +00:00
c->wall = waNone;
c->item = itNone;
c->monst = moNone;
c->bardir = NODIR;
2016-08-26 09:58:03 +00:00
c->mondir = NODIR;
c->barleft = c->barright = laNone;
2015-08-08 13:57:52 +00:00
c->land = laNone;
c->ligon = 0;
2016-01-02 10:09:13 +00:00
c->stuntime = 0;
c->monmirror = 0;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool doesnotFall(cell *c) {
2017-03-23 10:53:57 +00:00
if(c->wall == waChasm) return false;
else if(cellUnstable(c) && !in_gravity_zone(c)) {
2017-03-23 10:53:57 +00:00
fallingFloorAnimation(c);
c->wall = waChasm;
return false;
}
return true;
}
2019-08-09 19:00:52 +00:00
EX bool doesFall(cell *c) { return !doesnotFall(c); }
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool doesFallSound(cell *c) {
2017-03-23 10:53:57 +00:00
if(c->land != laMotion && c->land != laZebra)
playSound(c, "trapdoor");
return !doesnotFall(c);
}
2019-08-09 19:00:52 +00:00
EX bool itemHidden(cell *c) {
2017-03-23 10:53:57 +00:00
return isWatery(c) && !(shmup::on && shmup::boatAt(c));
}
2019-08-09 19:00:52 +00:00
EX bool playerInWater() {
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i) && isWatery(playerpos(i)) && !playerInBoat(i))
return true;
return false;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool itemHiddenFromSight(cell *c) {
2017-03-23 10:53:57 +00:00
return isWatery(c) && !items[itOrbInvis] && !(items[itOrbFish] && playerInWater())
&& !(shmup::on && shmup::boatAt(c));
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX int numplayers() {
2017-03-23 10:53:57 +00:00
return multi::players;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX cell *playerpos(int i) {
2017-03-23 10:53:57 +00:00
if(shmup::on) return shmup::playerpos(i);
if(multi::players > 1) return multi::player[i].at;
2017-03-23 10:53:57 +00:00
return singlepos();
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool allPlayersInBoats() {
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i) && playerpos(i)->wall != waBoat) return true;
2016-01-02 10:09:13 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX int whichPlayerOn(cell *c) {
2017-03-23 10:53:57 +00:00
if(singleused()) return c == singlepos() ? 0 : -1;
2016-01-02 10:09:13 +00:00
for(int i=0; i<numplayers(); i++)
2017-03-23 10:53:57 +00:00
if(playerpos(i) == c) return i;
return -1;
}
2019-08-09 19:00:52 +00:00
EX bool isPlayerOn(cell *c) {
2017-03-23 10:53:57 +00:00
return whichPlayerOn(c) >= 0;
}
2019-08-09 19:00:52 +00:00
EX bool isPlayerInBoatOn(cell *c, int i) {
2017-03-23 10:53:57 +00:00
return
(playerpos(i) == c && (
c->wall == waBoat || c->wall == waStrandedBoat || (shmup::on && shmup::playerInBoat(i))
));
}
2019-08-09 19:00:52 +00:00
EX bool playerInBoat(int i) {
2017-03-23 10:53:57 +00:00
return isPlayerInBoatOn(playerpos(i), i);
}
2019-08-09 19:00:52 +00:00
EX bool isPlayerInBoatOn(cell *c) {
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) if(isPlayerInBoatOn(c, i)) return true;
2016-01-02 10:09:13 +00:00
return false;
}
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX void destroyBoats(cell *c, cell *c2, bool strandedToo) {
2017-03-23 10:53:57 +00:00
if(c->wall == waBoat) placeWater(c, c2);
if(strandedToo && c->wall == waStrandedBoat) c->wall = waNone;
shmup::destroyBoats(c);
}
2019-08-09 19:00:52 +00:00
EX bool playerInPower() {
2017-03-23 10:53:57 +00:00
if(singleused())
return singlepos()->land == laPower || singlepos()->land == laHalloween;
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i) && (playerpos(i)->land == laPower || playerpos(i)->land == laHalloween))
return true;
2016-01-02 10:09:13 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX eItem localTreasureType() {
2017-03-23 10:53:57 +00:00
lastland = singlepos()->land;
2015-08-08 13:57:52 +00:00
return treasureType(lastland);
}
2019-08-09 19:00:52 +00:00
EX void countLocalTreasure() {
2015-08-08 13:57:52 +00:00
eItem i = localTreasureType();
currentLocalTreasure = i ? items[i] : 0;
2018-06-22 12:47:24 +00:00
if(i != itHyperstone) for(int i=0; i<isize(dcal); i++) {
2016-08-26 09:58:03 +00:00
cell *c2 = dcal[i];
if(c2->cpdist > 3) break;
eItem i2 = treasureType(c2->land);
if(i2 && items[i2] < currentLocalTreasure)
currentLocalTreasure = items[i2];
}
2016-01-02 10:09:13 +00:00
}
2019-08-09 21:24:33 +00:00
#if HDR
static const int NO_TREASURE = 1;
static const int NO_YENDOR = 2;
static const int NO_GRAIL = 4;
static const int NO_LOVE = 8;
#endif
2019-08-09 21:08:42 +00:00
EX int gold(int no IS(0)) {
2017-07-12 16:03:53 +00:00
int i = 0;
if(!(no & NO_YENDOR)) i += items[itOrbYendor] * 50;
if(!(no & NO_GRAIL)) i += items[itHolyGrail] * 10;
if(!(no & NO_LOVE)) {
bool love = items[itOrbLove];
2017-07-22 23:33:27 +00:00
#if CAP_INV
2017-07-12 16:03:53 +00:00
if(inv::on && inv::remaining[itOrbLove])
love = true;
#endif
#if CAP_DAILY
if(daily::on) love = false;
2017-07-12 16:03:53 +00:00
#endif
if(love) i += 30;
}
if(!(no & NO_TREASURE))
for(int t=0; t<ittypes; t++)
if(itemclass(eItem(t)) == IC_TREASURE)
i += items[t];
return i;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX int maxgold() {
2015-08-08 13:57:52 +00:00
int mg = 0;
for(int i=0; i<ittypes; i++)
if(itemclass(eItem(i)) == IC_TREASURE && items[i] > mg)
mg = items[i];
return mg;
}
2016-08-26 09:58:03 +00:00
int* killtable[] = {
&kills[moYeti], &kills[moWolf], &
kills[moRanger], &kills[moTroll], &kills[moGoblin], &
kills[moWorm], &kills[moDesertman], &kills[moIvyRoot], &
kills[moMonkey], &kills[moEagle], &kills[moSlime], &kills[moSeep], &
kills[moRunDog], &
kills[moCultist], &kills[moTentacle], &kills[moPyroCultist], &
kills[moLesser], &kills[moGreater], &
kills[moZombie], &kills[moGhost], &kills[moNecromancer], &
kills[moHedge], &kills[moFireFairy], &
kills[moCrystalSage], &kills[moShark], &kills[moGreaterShark], &
kills[moMiner], &kills[moFlailer], &kills[moLancer], &
kills[moVineSpirit], &kills[moVineBeast], &
kills[moBug0], &kills[moBug1], &kills[moBug2], &
kills[moDarkTroll], &kills[moEarthElemental], &
kills[moWitch], &kills[moEvilGolem], &kills[moWitchFlash], &kills[moWitchFire], &
kills[moWitchWinter], &kills[moWitchSpeed], &
kills[moCultistLeader], &
kills[moPirate], &kills[moCShark], &kills[moParrot], &
kills[moHexSnake], &kills[moRedTroll], &
kills[moPalace], &kills[moSkeleton], &kills[moFatGuard], &kills[moVizier], &
kills[moViking], &kills[moFjordTroll], &kills[moWaterElemental], &
kills[moAlbatross], &kills[moBomberbird], &
kills[moAirElemental], &kills[moFireElemental], &
2017-03-23 10:53:57 +00:00
kills[moGargoyle], &kills[moFamiliar], &kills[moOrangeDog], &
2016-08-26 09:58:03 +00:00
items[itMutant], &kills[moMetalBeast], &kills[moMetalBeast2], &
kills[moOutlaw], &kills[moForestTroll], &kills[moStormTroll], &
kills[moRedFox], &kills[moWindCrow], &
kills[moFalsePrincess], &kills[moRoseLady], &
kills[moRoseBeauty], &
kills[moRatling], &kills[moRatlingAvenger], &
kills[moDragonHead], &
2017-03-23 10:53:57 +00:00
kills[moGadfly], &kills[moSparrowhawk], &kills[moResearcher],
&kills[moKrakenH], &kills[moDraugr],
&kills[moBat], &kills[moReptile],
&kills[moHerdBull], &kills[moSleepBull], &kills[moRagingBull],
&kills[moButterfly],
2017-07-25 01:02:54 +00:00
&kills[moNarciss], &kills[moMirrorSpirit],
2017-09-30 09:46:41 +00:00
&kills[moHunterDog], &kills[moIceGolem], &kills[moVoidBeast],
2017-10-08 09:12:03 +00:00
&kills[moJiangshi], &kills[moTerraWarrior],
&kills[moSalamander], &kills[moLavaWolf],
2018-01-04 20:24:03 +00:00
&kills[moSwitch1], &kills[moSwitch2],
&kills[moMonk], &kills[moCrusher], &kills[moHexDemon], &kills[moAltDemon], &kills[moPair],
2018-10-25 00:43:14 +00:00
&kills[moBrownBug], &kills[moAcidBird],
2018-12-23 16:41:12 +00:00
&kills[moFallingDog], &kills[moVariantWarrior], &kills[moWestHawk],
2016-08-26 09:58:03 +00:00
NULL
};
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX int tkills() {
2016-08-26 09:58:03 +00:00
int res = 0;
for(int i=0; killtable[i]; i++) res += killtable[i][0];
return res;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX int killtypes() {
2016-08-26 09:58:03 +00:00
int res = 0;
for(int i=0; killtable[i]; i++) if(killtable[i][0]) res++;
return res;
2015-08-08 13:57:52 +00:00
}
2019-08-10 00:16:48 +00:00
#if HDR
enum eGravity { gsNormal, gsLevitation, gsAnti };
#endif
EX eGravity gravity_state, last_gravity_state;
EX bool bird_disruption(cell *c) {
return c->cpdist <= 5 && items[itOrbGravity];
}
2019-08-09 19:00:52 +00:00
EX bool in_gravity_zone(cell *c) {
return gravity_state && c->cpdist <= 5;
}
int gravity_zone_diff(cell *c) {
if(in_gravity_zone(c)) {
if(gravity_state == gsLevitation) return 0;
if(gravity_state == gsAnti) return -1;
}
return 1;
}
bool isJWall(cell *c) {
return isWall(c) || c->monst == passive_switch;
}
eGravity get_static_gravity(cell *c) {
if(isGravityLand(c->land))
return gsLevitation;
if(among(c->wall, waArrowTrap, waFireTrap, waClosePlate, waOpenPlate, waTrapdoor))
return gsNormal;
forCellEx(c2, c) if(isJWall(c2))
return gsAnti;
if(isWatery(c) || isChasmy(c) || among(c->wall, waMagma, waMineUnknown, waMineMine, waMineOpen))
return gsLevitation;
return gsNormal;
}
eGravity get_move_gravity(cell *c, cell *c2) {
if(isGravityLand(c->land) && isGravityLand(c2->land)) {
int d = gravityLevelDiff(c, c2);
if(d > 0) return gsNormal;
if(d == 0) return gsLevitation;
if(d < 0) return gsAnti;
return gsNormal;
}
else {
if(snakelevel(c) != snakelevel(c2)) {
int d = snakelevel(c2) - snakelevel(c);
if(d > 0) return gsAnti;
if(d == -3) return gsLevitation;
return gsNormal;
}
forCellEx(c3, c) if(isJWall(c3))
return gsAnti;
forCellEx(c3, c2) if(isJWall(c3))
return gsAnti;
if(isWatery(c2) && c->wall == waBoat && !againstCurrent(c2, c))
return gsNormal;
if(isWatery(c2) || isChasmy(c2) || among(c2->wall, waMagma, waMineUnknown, waMineMine, waMineOpen) || anti_alchemy(c2, c))
return gsLevitation;
return gsNormal;
}
}
2019-08-09 19:00:52 +00:00
EX bool isWarped(cell *c) {
return isWarpedType(c->land) || (!inmirrororwall(c->land) && (items[itOrb37] && c->cpdist <= 4));
}
2019-08-09 19:00:52 +00:00
EX bool nonAdjacent(cell *c, cell *c2) {
2017-12-18 20:15:03 +00:00
if(isWarped(c) && isWarped(c2) && warptype(c) == warptype(c2)) {
2016-08-26 09:58:03 +00:00
/* int i = neighborId(c, c2);
cell *c3 = c->modmove(i+1), *c4 = c->modmove(i-1);
2016-08-26 09:58:03 +00:00
if(c3 && !isTrihepta(c3)) return false;
if(c4 && !isTrihepta(c4)) return false; */
return true;
}
return false;
2015-08-08 13:57:52 +00:00
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool nonAdjacentPlayer(cell *c, cell *c2) {
2017-03-23 10:53:57 +00:00
return nonAdjacent(c, c2) && !markOrb(itOrb37);
}
2019-08-09 19:00:52 +00:00
EX bool thruVine(cell *c, cell *c2) {
2016-08-26 09:58:03 +00:00
return (cellHalfvine(c) && c2->wall == c->wall && c2 != c);
// ((c->wall == waFloorC || c->wall == waFloorD) && c2->wall == c->wall && !c2->item && !c->item);
2016-01-02 10:09:13 +00:00
}
// === MOVEMENT FUNCTIONS ===
// w = from->move(d)
2019-08-09 19:00:52 +00:00
EX bool againstCurrent(cell *w, cell *from) {
2016-01-02 10:09:13 +00:00
if(from->land != laWhirlpool) return false;
if(againstWind(from, w)) return false; // wind is stronger than current
2018-08-09 17:28:53 +00:00
if(!eubinary && (!from->master->alt || !w->master->alt)) return false;
2016-01-02 10:09:13 +00:00
int dfrom = celldistAlt(from);
int dw = celldistAlt(w);
if(dw < dfrom) return false;
if(dfrom < dw) return true;
for(int d=0; d<from->type; d++)
if(from->move(d) == w) {
cell *c3 = from->modmove(d-1);
2016-01-02 10:09:13 +00:00
if(!c3) return false;
return celldistAlt(c3) < dfrom;
}
return false;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool boatGoesThrough(cell *c) {
2016-08-26 09:58:03 +00:00
if(isGravityLand(c->land)) return false;
2016-01-02 10:09:13 +00:00
return
2017-03-23 10:53:57 +00:00
(c->wall == waNone && c->land != laMotion && c->land != laZebra && c->land != laReptile) ||
2016-08-26 09:58:03 +00:00
isAlchAny(c) ||
2017-03-23 10:53:57 +00:00
c->wall == waCavefloor || c->wall == waFrozenLake || isReptile(c->wall) ||
2016-01-02 10:09:13 +00:00
c->wall == waDeadfloor || c->wall == waCIsland || c->wall == waCIsland2 ||
c->wall == waMineUnknown || c->wall == waMineMine || c->wall == waMineOpen ||
2017-10-08 12:02:03 +00:00
c->wall == waBonfireOff || c->wall == waFire || c->wall == waPartialFire ||
c->wall == waArrowTrap;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void placeWater(cell *c, cell *c2) {
2017-10-08 12:02:03 +00:00
destroyTrapsOn(c);
2016-01-02 10:09:13 +00:00
if(isWatery(c)) ;
2016-08-26 09:58:03 +00:00
else if(c2 && isAlchAny(c2))
2016-01-02 10:09:13 +00:00
c->wall = c2->wall;
else if(isIcyLand(c))
c->wall = waLake;
else
c->wall = waSea;
2017-03-23 10:53:57 +00:00
// destroy the ancient treasure!
if(c->item == itBarrow) c->item = itNone;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX int incline(cell *cfrom, cell *cto) {
2016-01-02 10:09:13 +00:00
return snakelevel(cto) - snakelevel(cfrom);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
#define F(x) checkflags(flags,x)
EX bool checkflags(flagtype flags, flagtype x) {
2016-08-26 09:58:03 +00:00
if(flags & x) return true;
if(flags & P_ISPLAYER) {
if((x & P_WINTER) && markOrb(itOrbWinter)) return true;
if((x & P_IGNORE37) && markOrb(itOrb37)) return true;
if((x & P_FISH) && markOrb(itOrbFish)) return true;
if((x & P_MARKWATER) && markOrb(itOrbWater)) return true;
2017-03-23 10:53:57 +00:00
if((x & P_AETHER) && markOrb2(itOrbAether) && !(flags&P_NOAETHER)) return true;
2016-08-26 09:58:03 +00:00
}
if(flags & P_ISFRIEND) if(items[itOrbEmpathy])
if(checkflags(flags ^ P_ISPLAYER ^ P_ISFRIEND, x) && markOrb(itOrbEmpathy))
return true;
return false;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool strictlyAgainstGravity(cell *w, cell *from, bool revdir, flagtype flags) {
2017-03-23 10:53:57 +00:00
return
cellEdgeUnstable(w, flags) && cellEdgeUnstable(from, flags) &&
!(shmup::on && from == w) && gravityLevelDiff(from, w) != (revdir?-1:1) * gravity_zone_diff(from);
}
2019-08-09 19:00:52 +00:00
EX bool anti_alchemy(cell *w, cell *from) {
bool alch1 = w->wall == waFloorA && from && from->wall == waFloorB && !w->item && !from->item;
alch1 |= w->wall == waFloorB && from && from->wall == waFloorA && !w->item && !from->item;
return alch1;
2017-03-23 10:53:57 +00:00
}
2019-08-09 21:24:33 +00:00
#if HDR
#define P_MONSTER Flag(0) // can move through monsters
#define P_MIRROR Flag(1) // can move through mirrors
#define P_REVDIR Flag(2) // reverse direction movement
#define P_WIND Flag(3) // can move against the wind
#define P_GRAVITY Flag(4) // can move against the gravity
#define P_ISPLAYER Flag(5) // player-only moves (like the Round Table jump)
#define P_ONPLAYER Flag(6) // always can step on the player
#define P_FLYING Flag(7) // is flying
#define P_BULLET Flag(8) // bullet can fly through more things
#define P_MIRRORWALL Flag(9) // mirror images go through mirror walls
#define P_JUMP1 Flag(10) // first part of a jump
#define P_JUMP2 Flag(11) // second part of a jump
#define P_TELE Flag(12) // teleport onto
#define P_BLOW Flag(13) // Orb of Air -- blow, or push
#define P_AETHER Flag(14) // aethereal
#define P_FISH Flag(15) // swimming
#define P_WINTER Flag(16) // fire resistant
#define P_USEBOAT Flag(17) // can use boat
#define P_NOAETHER Flag(18) // disable AETHER
#define P_FRIENDSWAP Flag(19) // can move on friends (to swap with tem)
#define P_ISFRIEND Flag(20) // is a friend (can use Empathy + Winter/Aether/Fish combo)
#define P_LEADER Flag(21) // can push statues and use boats
#define P_MARKWATER Flag(22) // mark Orb of Water as used
#define P_EARTHELEM Flag(23) // Earth Elemental
#define P_WATERELEM Flag(24) // Water Elemental
#define P_IGNORE37 Flag(25) // ignore the triheptagonal board
#define P_CHAIN Flag(26) // for chaining moves with boats
#define P_DEADLY Flag(27) // suicide moves allowed
#define P_ROSE Flag(28) // rose smell
#define P_CLIMBUP Flag(29) // allow climbing up
#define P_CLIMBDOWN Flag(30) // allow climbing down
#define P_REPTILE Flag(31) // is reptile
#define P_VOID Flag(32) // void beast
#define P_PHASE Flag(33) // phasing movement
#define P_PULLMAGNET Flag(34) // pull the other part of the magnet
#endif
2019-08-09 19:00:52 +00:00
EX bool passable(cell *w, cell *from, flagtype flags) {
2016-08-26 09:58:03 +00:00
bool revdir = (flags&P_REVDIR);
2017-09-30 09:46:41 +00:00
bool vrevdir = revdir ^ bool(flags&P_VOID);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(from && from != w && nonAdjacent(from, w) && !F(P_IGNORE37 | P_BULLET)) return false;
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) {
cell *pp = playerpos(i);
if(!pp) continue;
if(w == pp && F(P_ONPLAYER)) return true;
if(from == pp && F(P_ONPLAYER) && F(P_REVDIR)) return true;
2018-02-27 22:43:21 +00:00
if(from && !((flags & P_ISPLAYER) && pp->monst)) {
2017-09-30 09:46:41 +00:00
int i = vrevdir ? incline(w, from) : incline(from, w);
if(in_gravity_zone(w)) {
if(gravity_state == gsLevitation) i = 0;
if(gravity_state == gsAnti && i > 1) i = 1;
}
2017-03-23 10:53:57 +00:00
if(i < -1 && F(P_ROSE)) return false;
if((i > 1) && !F(P_JUMP1 | P_JUMP2 | P_BULLET | P_FLYING | P_BLOW | P_CLIMBUP | P_AETHER | P_REPTILE))
return false;
if((i < -2) && !F(P_DEADLY | P_JUMP1 | P_JUMP2 | P_BULLET | P_FLYING | P_BLOW | P_CLIMBDOWN | P_AETHER | P_REPTILE))
return false;
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(F(P_ROSE)) {
if(airdist(w) < 3) return false;
if(againstWind(w,from)) return false;
}
2016-01-02 10:09:13 +00:00
2017-09-30 09:46:41 +00:00
if(from && strictlyAgainstGravity(w, from, vrevdir, flags)
2019-05-05 15:37:51 +00:00
&& !((flags & P_ISPLAYER) && shmup::on)
2017-03-23 10:53:57 +00:00
&& !F(P_GRAVITY | P_BLOW | P_JUMP1 | P_JUMP2 | P_FLYING | P_BULLET | P_AETHER)
) return false;
2016-01-02 10:09:13 +00:00
2017-09-30 09:46:41 +00:00
if(from && (vrevdir ? againstWind(from,w) : againstWind(w, from)) && !F(P_WIND | P_BLOW | P_JUMP1 | P_JUMP2 | P_BULLET | P_AETHER)) return false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(revdir && from && w->monst && passable(from, w, flags &~ (P_REVDIR|P_MONSTER)))
2016-01-02 10:09:13 +00:00
return true;
2017-03-23 10:53:57 +00:00
if(!shmup::on && sword::at(w, flags & P_ISPLAYER) && !F(P_DEADLY | P_BULLET | P_ROSE))
return false;
2016-08-26 09:58:03 +00:00
bool alch1 = anti_alchemy(w, from);
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(alch1) {
bool alchok = (in_gravity_zone(w) || in_gravity_zone(from));
alchok = alchok || (F(P_JUMP1 | P_JUMP2 | P_FLYING | P_TELE | P_BLOW | P_AETHER | P_BULLET)
&& !F(P_ROSE));
2017-03-23 10:53:57 +00:00
if(!alchok) return false;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
if(from && thruVine(from, w) && !F(P_AETHER)) return false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(w->monst == moMouse && F(P_JUMP1)) ;
else if(w->monst && isFriendly(w) && F(P_FRIENDSWAP)) ;
else if(w->monst && !F(P_MONSTER)) return false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(w->wall == waMirror || w->wall == waCloud)
return F(P_MIRROR | P_AETHER);
2017-07-16 21:00:55 +00:00
if(w->wall == waMirrorWall)
return F(P_MIRRORWALL);
2016-08-26 09:58:03 +00:00
if(F(P_BULLET)) {
2017-10-08 09:12:03 +00:00
if(isFire(w) || w->wall == waBonfireOff || cellHalfvine(w) ||
w->wall == waMagma ||
2016-08-26 09:58:03 +00:00
w->wall == waAncientGrave || w->wall == waFreshGrave || w->wall == waRoundTable)
return true;
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(F(P_LEADER)) {
if(from && from->wall == waBoat && isWatery(w) && from->item == itOrbYendor)
return false;
2016-08-26 09:58:03 +00:00
if(from && from->wall == waBoat && isWateryOrBoat(w) && !againstCurrent(w, from))
return true;
if(from && isWatery(from) && w->wall == waBoat && F(P_CHAIN))
return true;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(from && isWatery(from) && isWatery(w) && F(P_CHAIN) && !againstCurrent(w, from))
return true;
if(w->wall == waBigStatue && from && canPushStatueOn(from)) return true;
}
if(F(P_EARTHELEM)) {
// cannot go through Living Caves...
if(w->wall == waCavefloor) return false;
// but can dig through...
if(w->wall == waDeadwall || w->wall == waDune || w->wall == waStone)
return true;
// and can swim through...
if(w->wall == waSea && w->land == laLivefjord)
return true;
}
if(F(P_WATERELEM)) {
if(isWatery(w) || boatGoesThrough(w) ||
2017-03-23 10:53:57 +00:00
w->wall == waBoat ||
2016-08-26 09:58:03 +00:00
w->wall == waDeadTroll || w->wall == waDeadTroll2) return true;
2017-03-23 10:53:57 +00:00
return false;
2016-08-26 09:58:03 +00:00
}
if(isThorny(w->wall) && F(P_BLOW | P_DEADLY)) return true;
2017-10-08 09:12:03 +00:00
if(isFire(w) || w->wall == waMagma) {
if(w->wall == waMagma && in_gravity_zone(w)) ;
else if(!F(P_AETHER | P_WINTER | P_BLOW | P_JUMP1 | P_BULLET | P_DEADLY)) return false;
}
if(in_gravity_zone(w) && gravity_state == gsAnti && !isGravityLand(w->land) && (!from || !isGravityLand(from->land)))
if(!F(P_AETHER | P_BLOW | P_JUMP1 | P_BULLET | P_FLYING)) {
bool next_to_wall = false;
forCellEx(c2, w) if(isJWall(c2)) next_to_wall = true;
if(from) forCellEx(c2, from) if(isJWall(c2)) next_to_wall = true;
if(!next_to_wall && (!from || incline(from, w) * (vrevdir?-1:1) <= 0)) return false;
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if(isWatery(w)) {
if(in_gravity_zone(w)) ;
else if(from && from->wall == waBoat && F(P_USEBOAT) &&
(!againstCurrent(w, from) || F(P_MARKWATER)) && !(from->item == itOrbYendor)) ;
2017-03-23 10:53:57 +00:00
else if(!F(P_AETHER | P_FISH | P_FLYING | P_BLOW | P_JUMP1 | P_BULLET | P_DEADLY | P_REPTILE)) return false;
}
if(isChasmy(w)) {
if(in_gravity_zone(w)) ;
else if(!F(P_AETHER | P_FLYING | P_BLOW | P_JUMP1 | P_BULLET | P_DEADLY | P_REPTILE)) return false;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
if(w->wall == waRoundTable && from && from->wall != waRoundTable && (flags & P_ISPLAYER)) return true;
2016-08-26 09:58:03 +00:00
if(isNoFlight(w) && F(P_FLYING | P_BLOW | P_JUMP1)) return false;
2017-03-23 10:53:57 +00:00
if(isWall(w)) {
// a special case: empathic aethereal beings cannot go through Round Table
// (but truly aetheral beings can)
if(w->wall == waRoundTable) {
if(!(flags & P_AETHER)) return false;
}
else if(!F(P_AETHER)) return false;
}
2016-08-26 09:58:03 +00:00
return true;
2016-01-02 10:09:13 +00:00
}
EX vector<pair<cell*, int> > airmap;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int airdist(cell *c) {
2017-03-23 10:53:57 +00:00
if(!(havewhat & HF_AIR)) return 3;
2016-08-26 09:58:03 +00:00
vector<pair<cell*, int> >::iterator it =
lower_bound(airmap.begin(), airmap.end(), make_pair(c,0));
if(it != airmap.end() && it->first == c) return it->second;
return 3;
}
2019-08-09 19:00:52 +00:00
EX ld calcAirdir(cell *c) {
2016-08-26 09:58:03 +00:00
if(!c || c->monst == moAirElemental || !passable(c, NULL, P_BLOW))
2019-02-26 13:08:51 +00:00
return 0;
2016-01-02 10:09:13 +00:00
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-01-02 10:09:13 +00:00
if(c2 && c2->monst == moAirElemental) {
2019-02-26 13:08:51 +00:00
return c->c.spin(i) * 2 * M_PI / c2->type;
2016-01-02 10:09:13 +00:00
}
}
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-01-02 10:09:13 +00:00
if(!c2) continue;
2016-08-26 09:58:03 +00:00
if(!passable(c2, c, P_BLOW | P_MONSTER)) continue;
if(!passable(c, c2, P_BLOW | P_MONSTER)) continue;
2016-01-02 10:09:13 +00:00
for(int i=0; i<c2->type; i++) {
cell *c3 = c2->move(i);
2016-01-02 10:09:13 +00:00
if(c3 && c3->monst == moAirElemental) {
2019-02-26 13:08:51 +00:00
return c2->c.spin(i) * 2 * M_PI / c3->type;
2016-01-02 10:09:13 +00:00
}
}
}
2019-02-26 13:08:51 +00:00
return 0;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool againstWind(cell *cto, cell *cfrom) {
2016-08-26 09:58:03 +00:00
if(!cfrom || !cto) return false;
2017-09-30 09:46:41 +00:00
int dcto = airdist(cto), dcfrom = airdist(cfrom);
if(dcto < dcfrom) return true;
2019-02-17 17:33:15 +00:00
#if CAP_FIELD
if(cfrom->land == laBlizzard && !shmup::on && cto->land == laBlizzard && dcto == 3 && dcfrom == 3) {
2017-09-30 09:46:41 +00:00
char vfrom = windmap::at(cfrom);
char vto = windmap::at(cto);
int z = (vfrom-vto) & 255;
if(z >= windmap::NOWINDBELOW && z < windmap::NOWINDFROM)
return true;
}
2019-02-17 17:33:15 +00:00
#endif
2016-08-26 09:58:03 +00:00
whirlwind::calcdirs(cfrom);
int d = neighborId(cfrom, cto);
if(whirlwind::winddir(d) == -1) return true;
2016-01-02 10:09:13 +00:00
return false;
}
bool ghostmove(eMonster m, cell* to, cell* from) {
2016-08-26 09:58:03 +00:00
if(!isGhost(m) && nonAdjacent(to, from)) return false;
2017-03-23 10:53:57 +00:00
if(sword::at(to, 0)) return false;
if(!shmup::on && isPlayerOn(to)) return false;
2016-08-26 09:58:03 +00:00
if(to->monst && !(to->monst == moTentacletail && isGhost(m) && m != moFriendlyGhost)
&& !(to->monst == moTortoise && isGhost(m) && m != moFriendlyGhost))
2016-01-02 10:09:13 +00:00
return false;
if((m == moWitchGhost || m == moWitchWinter) && to->land != laPower)
return false;
if(isGhost(m))
2019-11-02 19:28:02 +00:00
for(int i=0; i<to->type; i++) if(to->move(i)) {
if(inmirror(to->move(i))) return false;
if(to->move(i) && to->move(i) != from && isGhost(to->move(i)->monst) &&
(to->move(i)->monst == moFriendlyGhost) == (m== moFriendlyGhost))
2016-01-02 10:09:13 +00:00
return false;
2017-07-16 21:00:55 +00:00
}
2016-01-02 10:09:13 +00:00
if(isGhost(m) || m == moWitchGhost) return true;
if(m == moGreaterShark) return isWatery(to);
2016-08-26 09:58:03 +00:00
if(m == moWitchWinter)
return passable(to, from, P_WINTER | P_ONPLAYER);
2016-01-02 10:09:13 +00:00
return false;
}
bool slimepassable(cell *w, cell *c) {
2016-08-26 09:58:03 +00:00
if(w == c || !c) return true;
int u = neighborId(c, w);
2016-08-26 09:58:03 +00:00
if(nonAdjacent(w,c)) return false;
2016-01-02 10:09:13 +00:00
if(isPlayerOn(w)) return true;
int group = slimegroup(c);
if(!group) return false;
int ogroup = slimegroup(w);
if(!ogroup) return false;
bool hv = (group == ogroup);
2017-03-23 10:53:57 +00:00
if(sword::at(w, 0)) return false;
2016-01-02 10:09:13 +00:00
if(w->item) return false;
// only travel to halfvines correctly
if(cellHalfvine(c)) {
int i=0;
for(int t=0; t<c->type; t++) if(c->move(t) && c->move(t)->wall == c->wall) i=t;
2016-01-02 10:09:13 +00:00
int z = i-u; if(z<0) z=-z; z%=6;
if(z>1) return false;
2017-03-23 10:53:57 +00:00
hv=(group == ogroup);
2016-01-02 10:09:13 +00:00
}
// only travel from halfvines correctly
if(cellHalfvine(w)) {
int i=0;
for(int t=0; t<w->type; t++) if(w->move(t) && w->move(t)->wall == w->wall) i=t;
int z = i-c->c.spin(u); if(z<0) z=-z; z%=6;
2016-01-02 10:09:13 +00:00
if(z>1) return false;
2017-03-23 10:53:57 +00:00
hv=(group == ogroup);
2016-01-02 10:09:13 +00:00
}
if(!hv) return false;
return true;
}
2017-03-23 10:53:57 +00:00
bool sharkpassable(cell *w, cell *c) {
if(w == c || !c) return true;
if(nonAdjacent(w,c)) return false;
if(isPlayerOn(w)) return true;
if(!isWatery(w)) return false;
if(sword::at(w, 0)) return false;
// don't go against the current
if(isWateryOrBoat(w) && isWateryOrBoat(c))
return !againstCurrent(w, c);
return true;
}
2019-08-09 19:00:52 +00:00
EX bool canPushStatueOn(cell *c) {
return passable(c, NULL, P_MONSTER) && !snakelevel(c) &&
!isWorm(c->monst) && !isReptile(c->wall) && !peace::on &&
!among(c->wall, waBoat, waFireTrap, waArrowTrap);
2016-01-02 10:09:13 +00:00
}
EX void moveBoat(const movei& mi) {
eWall x = mi.t->wall; mi.t->wall = mi.s->wall; mi.s->wall = x;
mi.t->mondir = mi.rev_dir_or(NODIR);
moveItem(mi.s, mi.t, false);
animateMovement(mi, LAYER_BOAT);
2016-01-02 10:09:13 +00:00
}
EX void moveBoatIfUsingOne(const movei& mi) {
if(mi.s->wall == waBoat && isWatery(mi.t)) moveBoat(mi);
else if(mi.s->wall == waBoat && boatGoesThrough(mi.t) && isFriendly(mi.t) && markEmpathy(itOrbWater)) {
placeWater(mi.t, mi.s);
moveBoat(mi);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
2018-01-02 10:15:42 +00:00
eMonster otherpole(eMonster m) {
return eMonster(m ^ moNorthPole ^ moSouthPole);
}
bool againstMagnet(cell *c1, cell *c2, eMonster m) { // (from, to)
if(false) forCellEx(c3, c2) {
if(c3 == c1) continue;
if(c3->monst == m)
2017-12-30 14:12:15 +00:00
return true;
/* if(c3->monst == otherpole(m) && c3->move(c3->mondir) != c1) {
2018-01-02 10:15:42 +00:00
int i = 0;
forCellEx(c4, c3) if(c4->monst == m) i++;
if(i == 2) return true;
} */
}
if(c1->monst == m && !isNeighbor(c2, c1->move(c1->mondir)))
2018-01-02 10:15:42 +00:00
return true;
2017-12-30 14:12:15 +00:00
forCellEx(c3, c1)
2018-01-02 10:15:42 +00:00
if(c3->monst != m && isMagneticPole(c3->monst))
2017-12-30 14:12:15 +00:00
if(!isNeighbor(c3, c2))
return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX bool againstPair(cell *c1, cell *c2, eMonster m) { // (from, to)
if(c1->monst == m && !isNeighbor(c2, c1->move(c1->mondir)))
2018-01-02 10:15:42 +00:00
return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX bool notNearItem(cell *c) {
2018-01-02 10:15:42 +00:00
forCellCM(c2, c) if(c2->item) return false;
return true;
}
2019-08-09 19:00:52 +00:00
EX bool passable_for(eMonster m, cell *w, cell *from, flagtype extra) {
2017-03-23 10:53:57 +00:00
if(w->monst && !(extra & P_MONSTER) && !isPlayerOn(w))
2016-01-02 10:09:13 +00:00
return false;
if(m == moWolf) {
2017-10-10 10:42:30 +00:00
return (isIcyLand(w) || w->land == laVolcano) && (isPlayerOn(w) || passable(w, from, extra));
2016-01-02 10:09:13 +00:00
}
2018-01-02 10:15:42 +00:00
if(isMagneticPole(m))
return !(w && from && againstMagnet(from, w, m)) && passable(w, from, extra);
if(m == moPair)
return !(w && from && againstPair(from, w, m)) && passable(w, from, extra);
2017-12-30 14:12:15 +00:00
if(m == passive_switch) return false;
2019-03-30 16:51:37 +00:00
if(minf[m].mgroup == moYeti || isBug(m) || isDemon(m) || m == moHerdBull || m == moMimic || m == moAsteroid) {
2017-03-23 10:53:57 +00:00
if((isWitch(m) || m == moEvilGolem) && w->land != laPower && w->land != laHalloween)
2016-01-02 10:09:13 +00:00
return false;
2016-08-26 09:58:03 +00:00
return passable(w, from, extra);
2016-01-02 10:09:13 +00:00
}
if(m == moDragonHead && prairie::isriver(w))
return false;
2017-03-23 10:53:57 +00:00
if(isShark(m))
return sharkpassable(w, from);
2016-01-02 10:09:13 +00:00
if(isSlimeMover(m))
return slimepassable(w, from);
2017-03-23 10:53:57 +00:00
if(m == moKrakenH) {
if(extra & P_ONPLAYER) {
if(isPlayerOn(w)) return true;
}
if((extra & P_ONPLAYER) && isPlayerOn(w))
return true;
2018-05-04 10:49:50 +00:00
if(kraken_pseudohept(w) || kraken_pseudohept(from)) return false;
2017-03-23 10:53:57 +00:00
if(w->wall != waBoat && !slimepassable(w, from)) return false;
forCellEx(w2, w) if(w2->wall != waBoat && !passable(w2, w, P_FISH | P_MONSTER)) return false;
return true;
}
2016-01-02 10:09:13 +00:00
if(m == moEarthElemental)
2016-08-26 09:58:03 +00:00
return passable(w, from, extra | P_EARTHELEM);
2016-01-02 10:09:13 +00:00
if(m == moWaterElemental)
2016-08-26 09:58:03 +00:00
return passable(w, from, extra | P_WATERELEM);
2016-01-02 10:09:13 +00:00
if(m == moGreaterShark)
return isWatery(w) || w->wall == waBoat || w->wall == waFrozenLake;
2016-08-26 09:58:03 +00:00
if(isGhostMover(m) || m == moFriendlyGhost)
2016-01-02 10:09:13 +00:00
return ghostmove(m, w, from);
// for the purpose of Shmup this is correct
2016-08-26 09:58:03 +00:00
if(m == moTameBomberbird)
return passable(w, from, extra | P_FLYING | P_ISFRIEND);
if(m == moHexSnake)
return !pseudohept(w) && passable(w, from, extra|P_WIND|P_FISH);
if(isBird(m)) {
if(bird_disruption(w) && (!from || bird_disruption(from)) && markOrb(itOrbGravity))
return passable(w, from, extra);
else
return passable(w, from, extra | P_FLYING);
}
2017-03-23 10:53:57 +00:00
if(m == moReptile)
return passable(w, from, extra | P_REPTILE);
2016-08-26 09:58:03 +00:00
if(isDragon(m))
return passable(w, from, extra | P_FLYING | P_WINTER);
if(m == moAirElemental)
return passable(w, from, extra | P_FLYING | P_WIND);
if(isLeader(m)) {
if(from && from->wall == waBoat && from->item == itCoral && !from->monst) return false; // don't move Corals!
return passable(w, from, extra | P_LEADER);
}
2016-01-02 10:09:13 +00:00
if(isPrincess(m))
2016-08-26 09:58:03 +00:00
return passable(w, from, extra | P_ISFRIEND | P_USEBOAT);
2016-01-02 10:09:13 +00:00
if(isGolemOrKnight(m))
2016-08-26 09:58:03 +00:00
return passable(w, from, extra | P_ISFRIEND);
if(isWorm(m))
2017-03-23 10:53:57 +00:00
return passable(w, from, extra) && !cellUnstable(w) && ((m != moWorm && m != moTentacle) || !cellEdgeUnstable(w));
2017-09-30 09:46:41 +00:00
if(m == moVoidBeast)
return passable(w, from, extra | P_VOID);
if(m == moHexDemon) {
if(extra & P_ONPLAYER) {
if(isPlayerOn(w)) return true;
}
2018-05-04 10:41:36 +00:00
return !pseudohept(w) && passable(w, from, extra);
}
if(m == moAltDemon) {
if(extra & P_ONPLAYER) {
if(isPlayerOn(w)) return true;
}
2018-05-04 10:41:36 +00:00
return (!w || !from || w==from || pseudohept(w) || pseudohept(from)) && passable(w, from, extra);
}
if(m == moMonk) {
if(extra & P_ONPLAYER) {
if(isPlayerOn(w)) return true;
}
2018-01-02 10:15:42 +00:00
return notNearItem(w) && passable(w, from, extra);
}
2016-01-02 10:09:13 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX eMonster movegroup(eMonster m) { return minf[m].mgroup; }
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void useup(cell *c) {
2016-01-02 10:09:13 +00:00
c->wparam--;
if(c->wparam == 0) {
2017-03-23 10:53:57 +00:00
drawParticles(c, c->wall == waFire ? 0xC00000 : winf[c->wall].color, 10, 50);
2016-01-02 10:09:13 +00:00
if(c->wall == waTempFloor)
c->wall = waChasm;
else if(c->wall == waTempBridge || c->wall == waTempBridgeBlocked || c->wall == waBurningDock || c->land == laBrownian)
2016-01-02 10:09:13 +00:00
placeWater(c, c);
else {
2016-01-02 10:09:13 +00:00
c->wall = c->land == laCaribbean ? waCIsland2 : waNone;
}
2016-01-02 10:09:13 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX int realstuntime(cell *c) {
2016-08-26 09:58:03 +00:00
if(isMutantIvy(c)) return (c->stuntime - mutantphase) & 15;
return c->stuntime;
2016-01-02 10:09:13 +00:00
}
2019-09-29 23:51:16 +00:00
EX bool childbug = false;
2016-08-26 09:58:03 +00:00
/** Is `w` killed if the part of an ivy `killed` is killed? */
2019-08-09 19:00:52 +00:00
EX bool isChild(cell *w, cell *killed) {
2017-03-23 10:53:57 +00:00
if(isAnyIvy(w->monst)) {
2016-08-26 09:58:03 +00:00
int lim = 0;
// printf("w = %p mondir = %d **\n", w, w->mondir);
while(w != killed && w->mondir != NODIR) {
lim++; if(lim == 100000) {
childbug = true;
printf("childbug!\n");
w->item = itBuggy; break;
}
2017-03-23 10:53:57 +00:00
if(!isAnyIvy(w->monst)) {
2016-08-26 09:58:03 +00:00
return false;
}
w = w->move(w->mondir);
2016-08-26 09:58:03 +00:00
// printf("w = %p mondir = %d\n", w, w->mondir);
}
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
return w == killed;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool logical_adjacent(cell *c1, eMonster m1, cell *c2) {
if(!c1 || !c2) return true; // cannot really check
eMonster m2 = c2->monst;
if(!isNeighbor(c1, c2))
return false;
if(thruVine(c1, c2) && !attackThruVine(m1) && !attackThruVine(m2) &&
!checkOrb(m1, itOrbAether) && !checkOrb(m2, itOrbAether))
return false;
if(nonAdjacent(c1, c2) && !attackNonAdjacent(m1) && !attackNonAdjacent(m2) &&
!checkOrb(m1, itOrb37) && !checkOrb(m1, itOrbAether) && !checkOrb(m2, itOrbAether))
return false;
return true;
}
2019-08-09 19:00:52 +00:00
EX bool arrow_stuns(eMonster m) {
2018-12-16 23:04:59 +00:00
return among(m, moCrusher, moMonk, moAltDemon, moHexDemon, moGreater, moGreaterM, moHedge);
}
2019-08-09 19:00:52 +00:00
EX bool canAttack(cell *c1, eMonster m1, cell *c2, eMonster m2, flagtype flags) {
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// cannot eat worms
if((flags & AF_EAT) && isWorm(m2)) return false;
2017-12-30 14:12:15 +00:00
if(m1 == passive_switch || m2 == passive_switch) return false;
2016-08-26 09:58:03 +00:00
if((flags & AF_GETPLAYER) && isPlayerOn(c2)) m2 = moPlayer;
if(!m2) return false;
2017-07-04 13:38:33 +00:00
if(m2 == moPlayer && peace::on) return false;
2018-12-16 23:04:59 +00:00
if((flags & AF_MUSTKILL) && attackJustStuns(c2, flags, m1))
return false;
2016-08-26 09:58:03 +00:00
if((flags & AF_ONLY_FRIEND) && m2 != moPlayer && !isFriendly(c2)) return false;
if((flags & AF_ONLY_FBUG) && m2 != moPlayer && !isFriendlyOrBug(c2)) return false;
if((flags & AF_ONLY_ENEMY) && (m2 == moPlayer || isFriendlyOrBug(c2))) return false;
2018-01-02 10:15:42 +00:00
2018-12-16 23:04:59 +00:00
if(m1 == moArrowTrap && arrow_stuns(m2)) return true;
2018-01-02 10:15:42 +00:00
if(among(m2, moAltDemon, moHexDemon, moPair, moCrusher, moNorthPole, moSouthPole, moMonk) && !(flags & (AF_EAT | AF_MAGIC | AF_BULL | AF_CRUSH)))
return false;
if(m2 == moHedge && !(flags & (AF_STAB | AF_TOUGH | AF_EAT | AF_MAGIC | AF_LANCE | AF_SWORD_INTO | AF_HORNS | AF_BULL | AF_CRUSH)))
2016-08-26 09:58:03 +00:00
if(!checkOrb(m1, itOrbThorns)) return false;
2017-07-22 23:33:27 +00:00
// krakens do not try to fight even with Discord
if((m1 == moKrakenT || m1 == moKrakenH) &&
(m2 == moKrakenT || m2 == moKrakenH))
return false;
if(m2 == moDraugr && !(flags & (AF_SWORD | AF_MAGIC | AF_SWORD_INTO | AF_HORNS | AF_CRUSH))) return false;
2017-03-23 10:53:57 +00:00
// if(m2 == moHerdBull && !(flags & AF_MAGIC)) return false;
2018-01-02 10:15:42 +00:00
if(isBull(m2) && !(flags & (AF_MAGIC | AF_HORNS | AF_SWORD_INTO | AF_CRUSH))) return false;
if(m2 == moButterfly && !(flags & (AF_MAGIC | AF_BULL | AF_HORNS | AF_SWORD_INTO | AF_CRUSH))) return false;
2017-03-23 10:53:57 +00:00
if(!(flags & AF_NOSHIELD) && ((flags & AF_NEXTTURN) ? checkOrb2 : checkOrb)(m2, itOrbShield)) return false;
2016-08-26 09:58:03 +00:00
if((flags & AF_STAB) && m2 != moHedge)
if(!checkOrb(m1, itOrbThorns)) return false;
if(flags & AF_BACK) {
if(m2 == moFlailer && !c2->stuntime) flags |= AF_IGNORE_UNARMED;
else if(m2 == moVizier && !isUnarmed(m1)) ;
else return false;
}
if(flags & AF_APPROACH) {
if(m2 == moLancer) ;
2017-03-23 10:53:57 +00:00
else if((flags & AF_HORNS) && checkOrb(m1, itOrbHorns)) ;
2016-08-26 09:58:03 +00:00
else return false;
}
if(!(flags & AF_IGNORE_UNARMED) && isUnarmed(m1)) return false;
if(m2 == moGreater || m2 == moGreaterM)
2018-01-02 10:15:42 +00:00
if(!(flags & (AF_MAGIC | AF_SWORD_INTO | AF_HORNS | AF_CRUSH))) return false;
2016-08-26 09:58:03 +00:00
if(!(flags & (AF_GUN | AF_SWORD | AF_SWORD_INTO | AF_MAGIC)))
if(c1 != c2 && !logical_adjacent(c1, m1, c2)) return false;
2016-08-26 09:58:03 +00:00
if(!(flags & (AF_LANCE | AF_STAB | AF_BACK | AF_APPROACH | AF_GUN | AF_MAGIC)))
2016-08-26 09:58:03 +00:00
if(c1 && c2 && againstRose(c1, c2) && !ignoresSmell(m1))
return false;
2017-03-23 10:53:57 +00:00
if(m2 == moShadow && !(flags & AF_SWORD)) return false;
2016-08-26 09:58:03 +00:00
if(isWorm(m2) && m2 != moTentacleGhost && !isDragon(m2)) return false;
// dragon can't attack itself, or player who mounted it
if(c1 && c2 && isWorm(c1->monst) && isWorm(c2->monst) && wormhead(c1) == wormhead(c2)
2017-03-23 10:53:57 +00:00
&& m1 != moTentacleGhost && m2 != moTentacleGhost)
2016-08-26 09:58:03 +00:00
return false;
// if(m2 == moTortoise && !(flags & AF_MAGIC)) return false;
if(m2 == moRoseBeauty)
if(!(flags & (AF_MAGIC | AF_LANCE | AF_GUN | AF_SWORD_INTO | AF_BULL | AF_CRUSH)))
2017-03-23 10:53:57 +00:00
if(!isMimic(m1))
if(!checkOrb(m1, itOrbBeauty) && !checkOrb(m1, itOrbAether) && !checkOrb(m1, itOrbShield))
2016-08-26 09:58:03 +00:00
if(!c1 || !c2 || !withRose(c1,c2))
return false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(m2 == moFlailer && !c2->stuntime)
2018-01-02 10:15:42 +00:00
if(!(flags & (AF_MAGIC | AF_TOUGH | AF_EAT | AF_HORNS | AF_LANCE | AF_BACK | AF_SWORD_INTO | AF_BULL | AF_CRUSH))) return false;
2016-08-26 09:58:03 +00:00
if(m2 == moVizier && c2->hitpoints > 1 && !c2->stuntime)
2018-01-02 10:15:42 +00:00
if(!(flags & (AF_MAGIC | AF_TOUGH | AF_EAT | AF_HORNS | AF_LANCE | AF_BACK | AF_FAST | AF_BULL | AF_CRUSH))) return false;
2016-08-26 09:58:03 +00:00
return true;
2016-01-02 10:09:13 +00:00
}
2019-08-09 23:31:44 +00:00
#if HDR
struct stalemate1 {
eMonster who;
cell *moveto;
cell *killed;
cell *pushto;
cell *comefrom;
cell *swordlast[2], *swordtransit[2], *swordnext[2];
bool isKilled(cell *c);
stalemate1(eMonster w, cell *mt, cell *ki, cell *pt, cell *cf) : who(w), moveto(mt), killed(ki), pushto(pt), comefrom(cf) {}
};
#endif
2017-03-23 10:53:57 +00:00
bool stalemate1::isKilled(cell *w) {
2016-08-26 09:58:03 +00:00
if(w->monst == moNone || w == killed) return true;
if(!moveto) return false;
2017-03-23 10:53:57 +00:00
for(int b=0; b<2; b++)
if((w == swordnext[b] || w == swordtransit[b]) && canAttack(moveto, who, w, w->monst, AF_SWORD))
return true;
if(logical_adjacent(moveto, who, w) && moveto != comefrom) {
2017-03-23 10:53:57 +00:00
int wid = neighborId(moveto, w);
int wfrom = neighborId(moveto, comefrom);
int flag = AF_APPROACH;
if(wid >= 0 && wfrom >= 0 && anglestraight(moveto, wfrom, wid)) flag |= AF_HORNS;
2017-03-23 10:53:57 +00:00
if(canAttack(moveto, who, w, w->monst, flag)) return true;
}
2016-08-26 09:58:03 +00:00
2017-09-30 09:46:41 +00:00
if(isNeighbor(w, comefrom) && comefrom == moveto && killed) {
int d1 = neighborId(comefrom, w);
int d2 = neighborId(comefrom, killed);
int di = angledist(comefrom->type, d1, d2);
if(di && items[itOrbSide1-1+di] && canAttack(moveto, who, w, w->monst, AF_SIDE))
return true;
}
if(logical_adjacent(comefrom, who, w) && logical_adjacent(moveto, who, w) && moveto != comefrom)
2017-03-23 10:53:57 +00:00
if(canAttack(moveto, who, w, w->monst, AF_STAB))
2016-08-26 09:58:03 +00:00
return true;
2017-07-22 23:33:27 +00:00
if(who == moPlayer && (killed || moveto != comefrom) && mirror::isKilledByMirror(w)) return true;
2016-08-26 09:58:03 +00:00
if(w->monst == moIvyHead || w->monst == moIvyBranch || isMutantIvy(w))
return isChild(w, killed);
if(isDragon(w->monst) && killed && isDragon(killed->monst) && killed->hitpoints) {
cell *head1 = dragon::findhead(w);
cell *head2 = dragon::findhead(killed);
if(head1 == head2 && dragon::totalhp(head1) ==1) return true;
}
if((w->monst == moPair || isMagneticPole(w->monst)) && killed && w->move(w->mondir) == killed)
return true;
2017-03-23 10:53:57 +00:00
if(w->monst == moKrakenT && killed && killed->monst == moKrakenT && killed->hitpoints) {
cell *head1 = w->move(w->mondir);
cell *head2 = killed->move(killed->mondir);
2017-03-23 10:53:57 +00:00
if(head1 == head2 && kraken::totalhp(head1) == 1) return true;
}
2016-08-26 09:58:03 +00:00
return false;
2016-01-02 10:09:13 +00:00
}
2019-08-09 23:31:44 +00:00
EX namespace stalemate {
EX bool isKilled(cell *w) {
for(int f=0; f<isize(moves); f++)
if(moves[f].isKilled(w)) return true;
return false;
};
EX }
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool isNeighbor(cell *c1, cell *c2) {
for(int i=0; i<c1->type; i++) if(c1->move(i) == c2) return true;
2016-01-02 10:09:13 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX bool isNeighborCM(cell *c1, cell *c2) {
2017-03-23 10:53:57 +00:00
for(int i=0; i<c1->type; i++) if(createMov(c1, i) == c2) return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX int neighborId(cell *ofWhat, cell *whichOne) {
for(int i=0; i<ofWhat->type; i++) if(ofWhat->move(i) == whichOne) return i;
2016-01-02 10:09:13 +00:00
return -1;
}
// how many monsters are near
eMonster who_kills_me;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool flashWouldKill(cell *c, flagtype extra) {
2016-01-02 10:09:13 +00:00
for(int t=0; t<c->type; t++) {
cell *c2 = c->move(t);
2016-01-02 10:09:13 +00:00
for(int u=0; u<c2->type; u++) {
cell *c3 = c2->move(u);
2015-08-08 13:57:52 +00:00
if(isWorm(c3)) continue; // immune to Flash
if(c3->monst == moEvilGolem) continue; // evil golems don't count
2017-03-23 10:53:57 +00:00
if(c3 != c && (c3->monst || isPlayerOn(c3)) && !stalemate::isKilled(c3)) {
2016-08-26 09:58:03 +00:00
bool b = canAttack(NULL, moWitchFlash, c3, c3->monst, AF_MAGIC | extra);
if(b) return true;
2015-08-08 13:57:52 +00:00
}
}
}
return false;
}
2019-08-09 19:00:52 +00:00
EX vector<cell*> gun_targets(cell *c) {
manual_celllister cl;
vector<int> dists;
cl.add(c); dists.push_back(0);
for(int i=0; i<isize(dists); i++) {
cell *c1 = cl.lst[i];
if(dists[i] <= 2)
forCellEx(c2, c1)
if(passable(c2, c1, P_BULLET | P_FLYING | P_MONSTER))
if(cl.add(c2)) dists.push_back(dists[i] + 1);
2016-08-26 09:58:03 +00:00
}
return cl.lst;
2016-08-26 09:58:03 +00:00
}
2019-08-09 23:31:44 +00:00
EX namespace stalemate {
EX vector<stalemate1> moves;
EX bool nextturn;
2017-10-29 11:46:57 +00:00
2019-08-09 23:31:44 +00:00
EX bool isMoveto(cell *c) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(moves); i++) if(moves[i].moveto == c) return true;
2017-03-23 10:53:57 +00:00
return false;
}
2019-08-09 23:31:44 +00:00
EX bool isKilledDirectlyAt(cell *c) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(moves); i++) if(moves[i].killed == c) return true;
2017-03-23 10:53:57 +00:00
return false;
}
2019-08-09 23:31:44 +00:00
EX bool isPushto(cell *c) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(moves); i++) if(moves[i].pushto == c) return true;
2017-03-23 10:53:57 +00:00
return false;
}
2019-08-09 23:31:44 +00:00
EX }
2017-03-23 10:53:57 +00:00
bool onboat(stalemate1& sm) {
cell *c = sm.moveto;
cell *cf = sm.comefrom;
return (c->wall == waBoat) || (cf->wall == waBoat && c->wall == waSea);
}
2019-08-09 19:00:52 +00:00
EX bool krakensafe(cell *c) {
2017-03-23 10:53:57 +00:00
return items[itOrbFish] || items[itOrbAether] ||
(c->item == itOrbFish && c->wall == waBoat) ||
(c->item == itOrbAether && c->wall == waBoat);
}
2017-12-30 14:12:15 +00:00
2019-08-09 19:00:52 +00:00
EX eMonster active_switch() {
2017-12-30 14:12:15 +00:00
return eMonster(passive_switch ^ moSwitch1 ^ moSwitch2);
}
2018-01-02 10:15:42 +00:00
EX vector<cell*> crush_now, crush_next;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool monstersnear(stalemate1& sm) {
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
cell *c = sm.moveto;
2016-08-26 09:58:03 +00:00
bool eaten = false;
if(hardcore && sm.who == moPlayer) return false;
2017-12-30 14:12:15 +00:00
2015-08-08 13:57:52 +00:00
int res = 0;
bool fast = false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
elec::builder b;
if(elec::affected(c)) { who_kills_me = moLightningBolt; res++; }
2017-10-04 19:26:26 +00:00
if(c->wall == waArrowTrap && c->wparam == 2) {
who_kills_me = moArrowTrap; res++;
2017-10-04 19:26:26 +00:00
}
2018-01-02 10:15:42 +00:00
for(auto c1: crush_now) if(c == c1) {
who_kills_me = moCrusher; res++;
2018-01-02 10:15:42 +00:00
}
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(sm.who == moPlayer || items[itOrbEmpathy]) {
fast = (items[itOrbSpeed] && (items[itOrbSpeed] & 1));
2019-11-16 02:39:14 +00:00
if(sm.who == moPlayer && sm.moveto->item == itOrbSpeed && !items[itOrbSpeed]) fast = true;
2015-08-08 13:57:52 +00:00
}
if(havewhat&HF_OUTLAW) {
for(cell *c1: gun_targets(c))
if(c1->monst == moOutlaw && !c1->stuntime && !stalemate::isKilled(c1)) {
res++; who_kills_me = moOutlaw;
}
}
2015-08-08 13:57:52 +00:00
for(int t=0; t<c->type; t++) {
cell *c2 = c->move(t);
2015-08-08 13:57:52 +00:00
// consider monsters who attack from distance 2
if(c2) forCellEx(c3, c2) if(c3 != c) {
2015-08-08 13:57:52 +00:00
// only these monsters can attack from two spots...
if(!among(c3->monst, moLancer, moWitchSpeed, moWitchFlash))
2016-08-26 09:58:03 +00:00
continue;
// take logical_adjacent into account
if(c3->monst != moWitchFlash)
if(!logical_adjacent(c3, c3->monst, c2) || !logical_adjacent(c2, c3->monst, c))
continue;
if(elec::affected(c3) || stalemate::isKilled(c3)) continue;
2019-07-28 09:09:33 +00:00
if(c3->stuntime > (sm.who == moPlayer ? 0 : 1)) continue;
2015-08-08 13:57:52 +00:00
// speedwitches can only attack not-fastened monsters,
// others can only attack if the move is not fastened
if(c3->monst == moWitchSpeed && items[itOrbSpeed]) continue;
if(c3->monst != moWitchSpeed && fast) continue;
// cannot attack if the immediate cell is impassable (except flashwitches)
if(c3->monst != moWitchFlash) {
if(!passable(c2, c3, stalemate::isKilled(c2)?P_MONSTER:0)) continue;
2016-01-02 10:09:13 +00:00
if(isPlayerOn(c2) && items[itOrbFire]) continue;
2015-08-08 13:57:52 +00:00
}
// flashwitches cannot attack if it would kill another enemy
2017-03-23 10:53:57 +00:00
if(c3->monst == moWitchFlash && flashWouldKill(c3, 0)) continue;
res++, who_kills_me = c3->monst;
2015-08-08 13:57:52 +00:00
}
// consider normal monsters
2016-08-26 09:58:03 +00:00
if(c2 &&
2017-03-23 10:53:57 +00:00
isArmedEnemy(c2, sm.who) &&
2016-08-26 09:58:03 +00:00
!stalemate::isKilled(c2) &&
(c2->monst != moLancer || isUnarmed(sm.who) || !logical_adjacent(c, sm.who, c2))) {
2017-03-23 10:53:57 +00:00
eMonster m = c2->monst;
2016-08-26 09:58:03 +00:00
if(elec::affected(c2)) continue;
2015-08-08 13:57:52 +00:00
if(fast && c2->monst != moWitchSpeed) continue;
2017-03-23 10:53:57 +00:00
// Krakens just destroy boats
if(c2->monst == moKrakenT && onboat(sm)) {
if(krakensafe(c)) continue;
else if(warningprotection(XLAT("This move appears dangerous -- are you sure?")) && res == 0) m = moWarning;
2017-03-23 10:53:57 +00:00
else continue;
}
2015-08-08 13:57:52 +00:00
// they cannot attack through vines
2017-03-23 10:53:57 +00:00
if(!canAttack(c2, c2->monst, c, sm.who, AF_NEXTTURN)) continue;
2016-08-26 09:58:03 +00:00
if(c2->monst == moWorm || c2->monst == moTentacle || c2->monst == moHexSnake) {
if(passable_for(c2->monst, c, c2, 0))
eaten = true;
else if(c2->monst != moHexSnake) continue;
}
res++, who_kills_me = m;
2015-08-08 13:57:52 +00:00
}
}
2017-03-23 10:53:57 +00:00
if(sm.who == moPlayer && res && (markOrb2(itOrbShield) || markOrb2(itOrbShell)) && !eaten)
2016-01-02 10:09:13 +00:00
res = 0;
2017-03-23 10:53:57 +00:00
if(sm.who == moPlayer && res && markOrb2(itOrbDomination) && c->monst)
2016-08-26 09:58:03 +00:00
res = 0;
2016-01-02 10:09:13 +00:00
return !!res;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool monstersnear2();
2017-03-23 10:53:57 +00:00
EX int lastkills;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool multimove() {
2017-03-23 10:53:57 +00:00
if(multi::cpid == 0) lastkills = tkills();
if(!multi::playerActive(multi::cpid)) return !monstersnear2();
cellwalker bcwt = cwt;
cwt = multi::player[multi::cpid];
bool b = movepcto(multi::whereto[multi::cpid]);
if(b) {
multi::aftermove = true;
multi::player[multi::cpid] = cwt;
multi::whereto[multi::cpid].d = MD_UNDECIDED;
int curkills = tkills();
multi::kills[multi::cpid] += (curkills - lastkills);
lastkills = curkills;
}
cwt = bcwt;
return b;
}
EX namespace multi {
EX bool checkonly = false;
EX bool aftermove;
EX }
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool swordConflict(const stalemate1& sm1, const stalemate1& sm2) {
2017-03-23 10:53:57 +00:00
if(items[itOrbSword] || items[itOrbSword2])
for(int b=0; b<2; b++)
if(sm1.comefrom == sm2.swordlast[b] || sm1.comefrom == sm2.swordtransit[b] || sm1.comefrom == sm2.swordnext[b])
if(sm1.moveto == sm2.swordlast[b] || sm1.moveto == sm2.swordtransit[b] || sm1.moveto == sm2.swordnext[b])
return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX bool monstersnear2() {
2017-03-23 10:53:57 +00:00
multi::cpid++;
bool b = false;
2017-03-23 10:53:57 +00:00
bool recorduse[ittypes];
for(int i=0; i<ittypes; i++) recorduse[i] = orbused[i];
if(multi::cpid == multi::players || multi::players == 1 || multi::checkonly) {
2017-12-30 23:08:55 +00:00
dynamicval<eMonster> sw(passive_switch, passive_switch);
// check for safe orbs and switching first
for(auto &sm: stalemate::moves) if(sm.who == moPlayer) {
2017-12-30 23:08:55 +00:00
if(hasSafeOrb(sm.moveto)) {
2017-03-23 10:53:57 +00:00
multi::cpid--; return 0;
}
2017-12-30 23:08:55 +00:00
if(sm.moveto->item && itemclass(sm.moveto->item) == IC_TREASURE)
passive_switch = active_switch();
if(items[itOrbMagnetism]) forCellEx(c2, sm.moveto)
if(canPickupItemWithMagnetism(c2, sm.comefrom)) {
if(itemclass(c2->item) == IC_TREASURE)
passive_switch = active_switch();
if(hasSafeOrb(c2)) {
multi::cpid--;
2017-12-30 23:08:55 +00:00
return 0;
}
2017-12-30 23:08:55 +00:00
}
}
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(stalemate::moves); i++)
for(int j=0; j<isize(stalemate::moves); j++) if(i != j) {
2017-03-23 10:53:57 +00:00
if(swordConflict(stalemate::moves[i], stalemate::moves[j])) {
b = true;
who_kills_me = moEnergySword;
2017-03-23 10:53:57 +00:00
}
if(multi::player[i].at == multi::player[j].at)
{ b = true; who_kills_me = moFireball; }
if(celldistance(multi::player[i].at, multi::player[j].at) > 8)
{ b = true; who_kills_me = moAirball; }
2017-03-23 10:53:57 +00:00
}
2018-06-22 12:47:24 +00:00
for(int i=0; !b && i<isize(stalemate::moves); i++)
2017-03-23 10:53:57 +00:00
b = monstersnear(stalemate::moves[i]);
}
else b = !multimove();
multi::cpid--;
for(int i=0; i<ittypes; i++) orbused[i] = recorduse[i];
return b;
}
2019-08-09 19:00:52 +00:00
EX bool monstersnear(cell *c, cell *nocount, eMonster who, cell *pushto, cell *comefrom) {
2017-07-04 13:38:33 +00:00
if(peace::on) return 0; // you are safe
2017-03-23 10:53:57 +00:00
stalemate1 sm(who, c, nocount, pushto, comefrom);
if(who == moPlayer) for(int b=0; b<2; b++) sm.swordlast[b] = sword::pos(multi::cpid, b);
cell *none = NULL;
cell **wcw = &cwt.at;
2017-03-23 10:53:57 +00:00
if(who != moPlayer) wcw = &none;
else if(multi::players > 1) wcw = &multi::player[multi::cpid].at;
2017-03-23 10:53:57 +00:00
dynamicval<cell*> x5(*wcw, c);
2016-08-26 09:58:03 +00:00
dynamicval<bool> x6(stalemate::nextturn, true);
dynamicval<sword::sworddir> x7(sword::dir[multi::cpid],
who == moPlayer ? sword::shift(comefrom, c, sword::dir[multi::cpid]) :
sword::dir[multi::cpid]);
2017-03-23 10:53:57 +00:00
for(int b=0; b<2; b++) {
if(who == moPlayer) {
sm.swordnext[b] = sword::pos(multi::cpid, b);
sm.swordtransit[b] = NULL;
if(sm.swordnext[b] && sm.swordnext[b] != sm.swordlast[b] && !isNeighbor(sm.swordlast[b], sm.swordnext[b])) {
forCellEx(c2, sm.swordnext[b])
if(c2 != c && c2 != comefrom && isNeighbor(c2, S3==3 ? sm.swordlast[b] : *wcw))
2017-10-30 11:20:45 +00:00
sm.swordtransit[b] = c2;
if(S3 == 4)
forCellEx(c2, c)
if(c2 != comefrom && isNeighbor(c2, sm.swordlast[b]))
sm.swordtransit[b] = c2;
}
}
else {
sm.swordnext[b] = sm.swordtransit[b] = NULL;
2017-10-30 11:20:45 +00:00
}
2017-03-23 10:53:57 +00:00
}
stalemate::moves.push_back(sm);
// dynamicval<eMonster> x7(stalemate::who, who);
bool b;
2016-08-26 09:58:03 +00:00
if(who == moPlayer && c->wall == waBigStatue) {
eWall w = comefrom->wall;
c->wall = waNone;
2017-03-23 10:53:57 +00:00
if(doesnotFall(comefrom)) comefrom->wall = waBigStatue;
b = monstersnear2();
2016-08-26 09:58:03 +00:00
comefrom->wall = w;
c->wall = waBigStatue;
2016-01-02 10:09:13 +00:00
}
2018-12-16 23:04:59 +00:00
else if(who == moPlayer && isPushable(c->wall)) {
eWall w = c->wall;
2016-08-26 09:58:03 +00:00
c->wall = waNone;
2017-03-23 10:53:57 +00:00
b = monstersnear2();
2018-12-16 23:04:59 +00:00
c->wall = w;
2016-01-02 10:09:13 +00:00
}
2018-06-12 20:40:06 +00:00
else {
b = monstersnear2();
}
2017-03-23 10:53:57 +00:00
stalemate::moves.pop_back();
return b;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool petrify(cell *c, eWall walltype, eMonster m) {
destroyHalfvine(c);
destroyTrapsOn(c);
playSound(c, "die-troll");
2017-09-30 09:46:41 +00:00
if(walltype == waIcewall && !isIcyLand(c->land))
return false;
if(c->land == laWestWall) return false;
if(isWateryOrBoat(c) && c->land == laWhirlpool) {
c->wall = waSea;
2017-09-30 09:46:41 +00:00
return false;
}
2018-07-30 07:34:48 +00:00
if(c->wall == waRoundTable) return false;
if(walltype == waGargoyle && cellUnstableOrChasm(c))
walltype = waGargoyleFloor;
else if(walltype == waGargoyle && isWatery(c))
walltype = waGargoyleBridge;
else if(walltype == waPetrified && isWatery(c))
walltype = waPetrifiedBridge;
else if((c->wall == waTempBridge || c->wall == waTempBridgeBlocked) && c->land == laWhirlpool) {
c->wall = waTempBridgeBlocked;
2017-09-30 09:46:41 +00:00
return true;
}
else if(!doesnotFall(c)) {
fallingFloorAnimation(c, walltype, m);
2017-09-30 09:46:41 +00:00
return true;
}
if(isReptile(c->wall)) kills[moReptile]++;
destroyHalfvine(c);
c->wall = walltype;
c->wparam = m;
c->item = itNone;
2017-09-30 09:46:41 +00:00
return true;
}
2016-08-26 09:58:03 +00:00
2019-08-09 19:00:52 +00:00
EX void killIvy(cell *c, eMonster who) {
2015-08-08 13:57:52 +00:00
if(c->monst == moIvyDead) return;
if(checkOrb(who, itOrbStone)) petrify(c, waPetrified, c->monst);
2016-08-26 09:58:03 +00:00
c->monst = moIvyDead; // NEWYEARFIX
for(int i=0; i<c->type; i++) if(c->move(i))
if(isIvy(c->move(i)) && c->move(i)->mondir == c->c.spin(i))
killIvy(c->move(i), who);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void prespill(cell* c, eWall t, int rad, cell *from) {
2016-08-26 09:58:03 +00:00
if(againstWind(c, from)) return;
2015-08-08 13:57:52 +00:00
// these monsters block spilling
if(c->monst == moSeep || c->monst == moVineSpirit || c->monst == moShark ||
2016-01-02 10:09:13 +00:00
c->monst == moGreaterShark || c->monst == moParrot || c->monst == moCShark)
2015-08-08 13:57:52 +00:00
return;
// turn statues into Slimes!
if(among(c->wall, waBigStatue, waTerraWarrior) && t != waNone) {
2015-08-08 13:57:52 +00:00
c->wall = waNone;
c->monst = moSlimeNextTurn;
}
// slimedeath spill
if((c->monst == moSlime || c->monst == moSlimeNextTurn) && t == waNone) {
2017-03-23 10:53:57 +00:00
c->wall = waNone; attackMonster(c, 0, moNone);
2015-08-08 13:57:52 +00:00
}
if(c->wall == waClosedGate) {
c->wall = waPalace;
return;
}
// no slime in Whirlpool
if(c->land == laWhirlpool) return;
2015-08-08 13:57:52 +00:00
// these walls block spilling completely
2016-08-26 09:58:03 +00:00
if(c->wall == waIcewall || c->wall == waBarrier || c->wall == waWarpGate ||
2017-03-23 10:53:57 +00:00
c->wall == waDeadTroll || c->wall == waDeadTroll2 ||
2016-01-02 10:09:13 +00:00
c->wall == waDune || c->wall == waAncientGrave ||
c->wall == waThumperOff || c->wall == waThumperOn ||
2015-08-08 13:57:52 +00:00
c->wall == waFreshGrave || c->wall == waColumn || c->wall == waPartialFire ||
c->wall == waDeadwall || c->wall == waWaxWall || c->wall == waCamelot || c->wall == waRoundTable ||
2016-01-02 10:09:13 +00:00
c->wall == waBigStatue || c->wall == waRed1 || c->wall == waRed2 || c->wall == waRed3 ||
2017-03-23 10:53:57 +00:00
c->wall == waTower ||
c->wall == waPalace ||
2016-01-02 10:09:13 +00:00
c->wall == waPlatform || c->wall == waStone || c->wall == waTempWall ||
c->wall == waTempFloor || c->wall == waTempBridge || c->wall == waPetrifiedBridge || c->wall == waTempBridgeBlocked ||
2016-08-26 09:58:03 +00:00
c->wall == waSandstone || c->wall == waCharged || c->wall == waGrounded ||
2017-03-23 10:53:57 +00:00
c->wall == waMetal || c->wall == waSaloon || c->wall == waFan ||
c->wall == waBarrowDig || c->wall == waBarrowWall ||
c->wall == waMirrorWall)
2015-08-08 13:57:52 +00:00
return;
2018-12-16 23:04:59 +00:00
if(c->wall == waFireTrap) {
if(c->wparam == 0) c->wparam = 1;
return;
}
if(c->wall == waExplosiveBarrel)
explodeBarrel(c);
2017-10-08 12:02:03 +00:00
destroyTrapsOn(c);
2015-08-08 13:57:52 +00:00
// these walls block further spilling
if(c->wall == waCavewall || cellUnstable(c) || c->wall == waSulphur ||
c->wall == waSulphurC || c->wall == waLake || c->wall == waChasm ||
2016-08-26 09:58:03 +00:00
c->wall == waBigTree || c->wall == waSmallTree || c->wall == waTemporary ||
2016-01-02 10:09:13 +00:00
c->wall == waVinePlant || isFire(c) || c->wall == waBonfireOff || c->wall == waVineHalfA || c->wall == waVineHalfB ||
c->wall == waCamelotMoat || c->wall == waSea || c->wall == waCTree ||
2016-08-26 09:58:03 +00:00
c->wall == waRubble || c->wall == waGargoyleFloor || c->wall == waGargoyle ||
c->wall == waRose || c->wall == waPetrified || c->wall == waPetrifiedBridge || c->wall == waRuinWall)
2015-08-08 13:57:52 +00:00
t = waTemporary;
if(c->wall == waSulphur) {
// remove the center as it would not look good
for(int i=0; i<c->type; i++) if(c->move(i) && c->move(i)->wall == waSulphurC)
c->move(i)->wall = waSulphur;
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
if(isReptile(c->wall)) {
if(c->monst || isPlayerOn(c)) kills[moReptile]++;
else c->monst = moReptile, c->stuntime = 3, c->hitpoints = 3;
}
2015-08-08 13:57:52 +00:00
destroyHalfvine(c);
if(c->wall == waTerraWarrior) kills[waTerraWarrior]++;
2015-08-08 13:57:52 +00:00
c->wall = t;
// destroy items...
c->item = itNone;
// block spill
if(t == waTemporary) return;
// cwt.at->item = itNone;
if(rad) for(int i=0; i<c->type; i++) if(c->move(i))
prespill(c->move(i), t, rad-1, c);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void spillfix(cell* c, eWall t, int rad) {
2015-08-08 13:57:52 +00:00
if(c->wall == waTemporary) c->wall = t;
if(rad) for(int i=0; i<c->type; i++) if(c->move(i))
spillfix(c->move(i), t, rad-1);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void spill(cell* c, eWall t, int rad) {
2016-08-26 09:58:03 +00:00
prespill(c,t,rad, c); spillfix(c,t,rad);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void degradeDemons() {
2015-08-08 13:57:52 +00:00
addMessage(XLAT("You feel more experienced in demon fighting!"));
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2015-08-08 13:57:52 +00:00
for(int i=0; i<dcs; i++) {
cell *c = dcal[i];
if(c->monst == moGreaterM || c->monst == moGreater)
achievement_gain("DEMONSLAYER");
if(c->monst == moGreaterM) c->monst = moLesserM;
if(c->monst == moGreater) c->monst = moLesser;
2016-01-02 10:09:13 +00:00
shmup::degradeDemons();
2015-08-08 13:57:52 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX bool earthFloor(cell *c) {
2016-01-02 10:09:13 +00:00
if(c->monst) return false;
if(c->wall == waDeadwall) { c->wall = waDeadfloor; return true; }
if(c->wall == waDune) { c->wall = waNone; return true; }
2017-10-08 12:02:03 +00:00
if(c->wall == waStone && c->land != laTerracotta) { c->wall = waNone; return true; }
if(c->wall == waAncientGrave || c->wall == waFreshGrave || c->wall == waRuinWall) {
2016-01-02 10:09:13 +00:00
c->wall = waNone;
return true;
}
if((c->wall == waSea || c->wall == waNone) && c->land == laOcean) {
c->wall = waCIsland;
return true;
}
if(c->wall == waSea && c->land == laCaribbean) {
c->wall = waCIsland;
return true;
}
2017-03-23 10:53:57 +00:00
if(c->wall == waSea && c->land == laWarpSea)
2016-08-26 09:58:03 +00:00
c->wall = waNone;
2017-03-23 10:53:57 +00:00
if(c->wall == waBoat && c->land == laWarpSea)
2016-08-26 09:58:03 +00:00
c->wall = waStrandedBoat;
2017-10-08 12:02:03 +00:00
if(c->wall == waMercury) {
c->wall = waNone;
return true;
}
2017-03-23 10:53:57 +00:00
if((c->wall == waBarrowDig || c->wall == waBarrowWall) && c->land == laBurial) {
c->item = itNone;
c->wall = waNone;
return true;
}
if(c->wall == waPlatform && c->land == laMountain) {
c->wall = waNone;
return true;
}
2017-10-10 12:24:39 +00:00
if(c->wall == waChasm && c->land == laHunting) {
2017-10-08 12:02:03 +00:00
c->wall = waNone;
return true;
}
2016-01-02 10:09:13 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX bool earthWall(cell *c) {
2016-01-02 10:09:13 +00:00
if(c->wall == waDeadfloor || c->wall == waDeadfloor2 || c->wall == waEarthD) {
c->item = itNone;
c->wall = waDeadwall;
return true;
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
if(c->wall == waNone && c->land == laMountain) {
c->wall = waPlatform;
return true;
}
2015-08-08 13:57:52 +00:00
if(c->wall == waNone && c->land == laDesert) {
c->item = itNone;
c->wall = waDune;
2016-01-02 10:09:13 +00:00
return true;
}
if(c->wall == waNone && c->land == laRuins) {
c->item = itNone;
c->wall = waRuinWall;
return true;
}
2016-01-02 10:09:13 +00:00
if(c->wall == waNone && isElemental(c->land)) {
c->item = itNone;
c->wall = waStone;
return true;
2015-08-08 13:57:52 +00:00
}
2016-01-02 10:09:13 +00:00
if(c->wall == waNone && c->land == laRedRock) {
c->item = itNone;
c->wall = waRed3;
return true;
}
if(c->wall == waNone && c->land == laSnakeNest) {
c->item = itNone;
c->wall = waRed3;
return true;
}
2017-03-23 10:53:57 +00:00
if(c->wall == waNone && c->land == laBurial) {
c->item = itNone;
c->wall = waBarrowDig;
return true;
}
2017-10-10 12:24:39 +00:00
if(c->wall == waNone && c->land == laHunting) {
2017-10-08 12:02:03 +00:00
c->item = itNone;
c->wall = waChasm;
return true;
}
if(c->wall == waNone && c->land == laTerracotta) {
c->wall = waMercury;
return true;
}
if(c->wall == waArrowTrap && c->land == laTerracotta) {
destroyTrapsOn(c);
c->wall = waMercury;
return true;
}
2016-01-02 10:09:13 +00:00
if(c->wall == waCIsland || c->wall == waCIsland2 || (c->wall == waNone && c->land == laOcean)) {
c->item = itNone;
c->wall = waSea;
if(c->land == laOcean) c->landparam = 40;
return true;
}
return false;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool snakepile(cell *c, eMonster m) {
if(c->wall == waSea && c->land == laOcean) {
c->land = laBrownian, c->landparam = 0;
}
if(c->land == laWestWall) return false;
2018-10-25 00:43:14 +00:00
if(c->land == laBrownian) {
if(c->wall == waNone) {
#if CAP_COMPLEX2
c->landparam += brownian::level;
#endif
return true;
}
if(c->wall == waSea || c->wall == waBoat) {
c->wall = waNone;
c->landparam++;
return true;
}
}
2018-02-13 19:22:16 +00:00
if(c->item && c->wall != waRed3) c->item = itNone;
2016-01-02 10:09:13 +00:00
if(c->wall == waRed1 || c->wall == waOpenGate) c->wall = waRed2;
else if(c->wall == waRed2) c->wall = waRed3;
2017-03-23 10:53:57 +00:00
else if(doesFall(c)) return false;
2016-08-26 09:58:03 +00:00
else if((c->wall == waSea && c->land == laLivefjord))
c->wall = waNone;
else if((c->wall == waSea && isWarpedType(c->land)))
2016-08-26 09:58:03 +00:00
c->wall = waNone;
else if(isGravityLand(c->land)) {
if(m == moHexSnake)
c->wall = waPlatform;
else
c->wall = waDeadTroll2;
}
else if(c->wall == waNone || isAlchAny(c) ||
2016-01-02 10:09:13 +00:00
c->wall == waCIsland || c->wall == waCIsland2 ||
c->wall == waOpenPlate || c->wall == waClosePlate ||
2017-03-23 10:53:57 +00:00
c->wall == waMineUnknown || c->wall == waMineOpen || isReptile(c->wall)) {
if(isReptile(c->wall)) kills[moReptile]++;
2016-01-02 10:09:13 +00:00
c->wall = waRed1;
if(among(m, moDarkTroll, moBrownBug)) c->wall = waDeadfloor2;
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
else if(c->wall == waDeadfloor)
c->wall = waDeadfloor2;
2016-08-26 09:58:03 +00:00
else if(c->wall == waDeadfloor2) {
2017-03-23 10:53:57 +00:00
if(m == moDarkTroll && c->land == laDeadCaves) return false;
2016-08-26 09:58:03 +00:00
else
c->wall = waDeadwall;
}
2016-01-02 10:09:13 +00:00
else if(c->wall == waRubble || c->wall == waGargoyleFloor || c->wall == waGargoyleBridge ||
c->wall == waTempFloor || c->wall == waTempBridge || c->wall == waPetrifiedBridge) {
if(c->land == laWhirlpool) return false;
2016-01-02 10:09:13 +00:00
c->wall = waRed2;
2016-08-26 09:58:03 +00:00
if(m == moDarkTroll) c->wall = waDeadwall;
}
2016-01-02 10:09:13 +00:00
else if(c->wall == waCavefloor) c->wall = waCavewall;
2016-08-26 09:58:03 +00:00
else if(c->wall == waSea && c->land == laCaribbean) c->wall = waCIsland;
2017-03-23 10:53:57 +00:00
else if(c->wall == waSea && c->land == laWhirlpool) return false;
2016-08-26 09:58:03 +00:00
else if(c->wall == waSea) c->wall = waNone;
2016-01-02 10:09:13 +00:00
else if(isWateryOrBoat(c) || c->wall == waFrozenLake) c->wall = waNone;
else if(isWateryOrBoat(c) || c->wall == waFrozenLake) c->wall = waNone;
else if(cellHalfvine(c)) {
destroyHalfvine(c, waRed1);
2016-08-26 09:58:03 +00:00
if(c->wall == waRed1 && m == moDarkTroll) c->wall = waDeadfloor2;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else return false;
return true;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool makeflame(cell *c, int timeout, bool checkonly) {
if(!checkonly) destroyTrapsOn(c);
2016-01-02 10:09:13 +00:00
if(itemBurns(c->item)) {
if(checkonly) return true;
if(c->cpdist <= 7)
addMessage(XLAT("%The1 burns!", c->item));
c->item = itNone;
2016-01-02 10:09:13 +00:00
}
if(cellUnstable(c)) {
if(checkonly) return true;
2017-03-23 10:53:57 +00:00
doesFall(c);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else if(c->wall == waChasm || c->wall == waOpenGate || c->wall == waRed2 || c->wall == waRed3 ||
c->wall == waTower)
2016-01-02 10:09:13 +00:00
return false;
else if(c->wall == waBoat) {
if(isPlayerOn(c) && markOrb(itOrbWinter)) {
addMessage(XLAT("%the1 protects your boat!", itOrbWinter));
}
2016-01-02 10:09:13 +00:00
if(checkonly) return true;
if(c->cpdist <= 7)
addMessage(XLAT("%The1 burns!", winf[c->wall].name));
2017-03-23 10:53:57 +00:00
drawFireParticles(c, 24);
2016-08-26 09:58:03 +00:00
placeWater(c, c);
2016-01-02 10:09:13 +00:00
if(isIcyLand(c)) HEAT(c) += 1;
}
else if(c->wall == waNone && c->land == laCocytus) {
if(checkonly) return true;
c->wall = waLake, HEAT(c) += 1;
}
2018-12-16 23:04:59 +00:00
else if(c->wall == waFireTrap) {
if(checkonly) return true;
if(c->wparam == 0) c->wparam = 1;
}
2016-08-26 09:58:03 +00:00
else if(c->wall == waFrozenLake) {
2016-01-02 10:09:13 +00:00
if(checkonly) return true;
2017-03-23 10:53:57 +00:00
drawParticles(c, MELTCOLOR, 8, 8);
2016-01-02 10:09:13 +00:00
c->wall = waLake, HEAT(c) += 1;
}
else if(c->wall == waIcewall) {
if(checkonly) return true;
2017-03-23 10:53:57 +00:00
drawParticles(c, MELTCOLOR, 8, 8);
2016-01-02 10:09:13 +00:00
c->wall = waNone;
}
else if(c->wall == waMineMine) {
if(checkonly) return true;
explodeMine(c);
}
2016-08-26 09:58:03 +00:00
else if(c->wall != waCTree && c->wall != waBigTree && c->wall != waSmallTree &&
c->wall != waVinePlant && !passable(c, NULL, P_MONSTER | P_MIRROR) &&
c->wall != waSaloon && c->wall != waRose) return false;
2017-03-23 10:53:57 +00:00
// reptiles are able to use the water to put the fire off
else if(c->wall == waReptileBridge) return false;
2017-12-29 00:10:47 +00:00
else if(c->wall == waDock) {
if(checkonly) return true;
c->wall = waBurningDock;
c->wparam = 3;
return false;
}
2016-01-02 10:09:13 +00:00
else {
eWall w = eternalFire(c) ? waEternalFire : waFire;
2017-03-23 10:53:57 +00:00
if(!checkonly) drawFireParticles(c, 10);
2016-01-02 10:09:13 +00:00
if(w == c->wall) return false;
if(checkonly) return true;
2017-03-23 10:53:57 +00:00
if(isReptile(c->wall)) kills[moReptile]++;
2016-01-02 10:09:13 +00:00
destroyHalfvine(c);
if(!isFire(c)) c->wparam = 0;
c->wall = w;
c->wparam = max(c->wparam, (char) timeout);
2019-04-08 12:54:52 +00:00
if(c->land == laBrownian) c->landparam = 0;
2016-01-02 10:09:13 +00:00
}
return true;
}
2019-08-09 19:00:52 +00:00
EX void explosion(cell *c, int power, int central) {
2017-03-23 10:53:57 +00:00
playSound(c, "explosion");
drawFireParticles(c, 30, 150);
2018-10-25 00:43:14 +00:00
brownian::dissolve_brownian(c, 2);
2018-12-16 23:04:59 +00:00
makeflame(c, central, false);
2016-01-02 10:09:13 +00:00
2018-10-25 00:43:14 +00:00
forCellEx(c2, c) {
2017-10-08 12:02:03 +00:00
destroyTrapsOn(c2);
2018-10-25 00:43:14 +00:00
brownian::dissolve_brownian(c2, 1);
2016-01-02 10:09:13 +00:00
if(c2->wall == waRed2 || c2->wall == waRed3)
c2->wall = waRed1;
2017-03-23 10:53:57 +00:00
else if(c2->wall == waDeadTroll || c2->wall == waDeadTroll2 || c2->wall == waPetrified || c2->wall == waGargoyle) {
2016-01-02 10:09:13 +00:00
c2->wall = waNone;
2018-12-16 23:04:59 +00:00
makeflame(c2, power/2, false);
2016-01-02 10:09:13 +00:00
}
else if(c2->wall == waPetrifiedBridge || c2->wall == waGargoyleBridge) {
placeWater(c, c);
}
2016-08-26 09:58:03 +00:00
else if(c2->wall == waPalace || c2->wall == waOpenGate || c2->wall == waClosedGate ||
c2->wall == waSandstone || c2->wall == waMetal || c2->wall == waSaloon || c2->wall == waRuinWall) {
2016-01-02 10:09:13 +00:00
c2->wall = waNone;
2018-12-16 23:04:59 +00:00
makeflame(c2, power/2, false);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else if(c2->wall == waTower)
c2->wall = waRubble;
else if(c2->wall == waBarrowWall)
c2->wall = waBarrowDig;
else if(c2->wall == waBarrowDig)
c2->wall = waNone;
2018-12-16 23:04:59 +00:00
else if(c2->wall == waFireTrap) {
if(c2->wparam == 0)
c2->wparam = 1;
}
else if(c2->wall == waExplosiveBarrel)
explodeBarrel(c2);
else makeflame(c2, power, false);
2016-01-02 10:09:13 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void explodeMine(cell *c) {
2018-12-16 23:04:59 +00:00
if(c->wall != waMineMine)
return;
c->wall = waMineOpen;
explosion(c, 20, 20);
auto_teleport_charges();
2018-12-16 23:04:59 +00:00
}
2019-08-09 19:00:52 +00:00
EX void explodeBarrel(cell *c) {
2018-12-16 23:04:59 +00:00
if(c->wall != waExplosiveBarrel)
return;
c->wall = waNone;
explosion(c, 20, 20);
}
2019-08-09 19:00:52 +00:00
EX bool mayExplodeMine(cell *c, eMonster who) {
2017-03-23 10:53:57 +00:00
if(c->wall != waMineMine) return false;
if(ignoresPlates(who)) return false;
explodeMine(c);
return true;
}
2019-08-09 19:00:52 +00:00
EX void stunMonster(cell *c2, eMonster killer, flagtype flags) {
2017-06-18 16:51:46 +00:00
int newtime = (
2016-01-02 10:09:13 +00:00
c2->monst == moFatGuard ? 2 :
2017-03-23 10:53:57 +00:00
c2->monst == moSkeleton && c2->land != laPalace && c2->land != laHalloween ? 7 :
c2->monst == moTerraWarrior ? min(int(c2->stuntime + 8 - c2->hitpoints), 7) :
2016-08-26 09:58:03 +00:00
isMetalBeast(c2->monst) ? 7 :
c2->monst == moTortoise ? 7 :
2017-03-23 10:53:57 +00:00
c2->monst == moReptile ? 7 :
isPrincess(c2->monst) ? 6 :
// spear stunning
isBull(c2->monst) ? 3 :
(c2->monst == moGreater || c2->monst == moGreaterM) ? 5 :
c2->monst == moButterfly ? 2 :
c2->monst == moDraugr ? 1 :
c2->monst == moVizier ? 0 :
2017-03-23 10:53:57 +00:00
c2->monst == moHedge ? 1 :
c2->monst == moFlailer ? 1 :
2017-10-08 09:12:03 +00:00
c2->monst == moSalamander ? 6 :
2018-10-25 00:43:14 +00:00
c2->monst == moBrownBug ? 3 :
2016-01-02 10:09:13 +00:00
3);
2018-12-16 23:04:59 +00:00
if(killer == moArrowTrap) newtime = min(newtime + 3, 7);
2018-10-25 00:43:14 +00:00
if(!isMetalBeast(c2->monst) && !among(c2->monst, moSkeleton, moReptile, moSalamander, moTortoise, moBrownBug)) {
2017-10-04 19:26:26 +00:00
c2->hitpoints--;
if(c2->monst == moPrincess)
playSound(c2, princessgender() ? "hit-princess" : "hit-prince");
}
2017-06-18 16:51:46 +00:00
if(c2->stuntime < newtime) c2->stuntime = newtime;
2017-03-23 10:53:57 +00:00
if(isBull(c2->monst)) c2->mondir = NODIR;
checkStunKill(c2);
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool attackJustStuns(cell *c2, flagtype f, eMonster attacker) {
if(f & AF_HORNS)
return hornStuns(c2);
2018-12-16 23:04:59 +00:00
else if(attacker == moArrowTrap && arrow_stuns(c2->monst))
return true;
else if((f & AF_SWORD) && c2->monst == moSkeleton)
return false;
else if(f & (AF_CRUSH | AF_MAGIC | AF_FALL | AF_EAT | AF_GUN))
return false;
else
return isStunnable(c2->monst) && c2->hitpoints > 1;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void flameHalfvine(cell *c, int val) {
2016-01-02 10:09:13 +00:00
if(itemBurns(c->item)) {
addMessage(XLAT("%The1 burns!", c->item));
2016-01-02 10:09:13 +00:00
c->item = itNone;
}
c->wall = waPartialFire;
c->wparam = val;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void minerEffect(cell *c) {
2017-03-23 10:53:57 +00:00
eWall ow = c->wall;
2016-08-26 09:58:03 +00:00
if(c->wall == waOpenGate || c->wall == waFrozenLake || c->wall == waBoat ||
c->wall == waStrandedBoat ||
c->wall == waCIsland || c->wall == waCIsland2 || c->wall == waTrapdoor ||
c->wall == waGiantRug) ;
else if(c->wall == waMineUnknown || c->wall == waMineMine || c->wall == waMineOpen)
c->wall = waMineOpen;
else if(c->wall == waRed2) c->wall = waRed1;
else if(c->wall == waRed3) c->wall = waRed2;
2017-03-23 10:53:57 +00:00
else if(isReptile(c->wall))
c->wparam = 1; // wake up next turn
2016-08-26 09:58:03 +00:00
else if(c->wall == waTempFloor) c->wall = waChasm;
else if(c->wall == waTempBridge || c->wall == waPetrifiedBridge || c->wall == waTempBridgeBlocked)
placeWater(c, NULL);
2017-03-23 10:53:57 +00:00
else if(doesFall(c))
ow = waNone;
2016-08-26 09:58:03 +00:00
else
c->wall = waNone;
2017-03-23 10:53:57 +00:00
if(c->wall != ow && ow) drawParticles(c, winf[ow].color, 16);
2016-08-26 09:58:03 +00:00
}
2019-08-09 19:00:52 +00:00
EX void killMutantIvy(cell *c, eMonster who) {
if(checkOrb(who, itOrbStone)) petrify(c, waPetrified, moMutant);
2017-03-23 10:53:57 +00:00
removeIvy(c);
for(int i=0; i<c->type; i++)
if(c->move(i)->mondir == c->c.spin(i) && (isMutantIvy(c->move(i)) || c->move(i)->monst == moFriendlyIvy))
killMutantIvy(c->move(i), who);
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX void killMonster(cell *c, eMonster who, flagtype deathflags IS(0)) {
2015-08-08 13:57:52 +00:00
eMonster m = c->monst;
2019-05-12 23:57:40 +00:00
DEBBI(DF_TURN, ("killmonster ", dnameof(m)));
2015-08-08 13:57:52 +00:00
if(!m) return;
2017-03-23 10:53:57 +00:00
if(m == moKrakenH) return;
if(m == moKrakenT) {
if(c->hitpoints && m == moKrakenT) kills[moKrakenT]++;
c->hitpoints = 0;
c->stuntime = 1;
cell *head = kraken::head(c);
if(kraken::totalhp(head) == 0) kraken::kill(head, who);
return;
}
2016-08-26 09:58:03 +00:00
if(isDragon(m)) {
2017-03-23 10:53:57 +00:00
if(c->hitpoints && m != moDragonHead) kills[moDragonTail]++;
2016-08-26 09:58:03 +00:00
c->hitpoints = 0;
c->stuntime = 1;
cell *head = dragon::findhead(c);
2017-03-23 10:53:57 +00:00
if(dragon::totalhp(head) == 0) dragon::kill(head, who);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
if(isWorm(c) && m != moTentacleGhost) return;
2016-08-26 09:58:03 +00:00
bool fallanim = (deathflags & AF_FALL) && m != moMimic;
int pcount = fallanim ? 0 : 16;
2015-08-08 13:57:52 +00:00
if(m == moShadow) return;
2016-08-26 09:58:03 +00:00
2019-08-09 23:07:39 +00:00
#if CAP_HISTORY
2017-03-23 10:53:57 +00:00
if(!isBug(m) && !isAnyIvy(m)) {
history::killhistory.push_back(make_pair(c,m));
2016-08-26 09:58:03 +00:00
}
#endif
2015-08-08 13:57:52 +00:00
if(m == moGolemMoved) m = moGolem;
if(m == moKnightMoved) m = moKnight;
if(m == moSlimeNextTurn) m = moSlime;
if(m == moLesserM) m = moLesser;
if(m == moGreater) m = moLesser;
if(m == moGreaterM) m = moLesser;
2016-01-02 10:09:13 +00:00
if(isPrincess(m)) m = moPrincess;
if(m == moTentacleGhost) m = moGhost;
2017-09-30 09:46:41 +00:00
if(m == moHunterGuard) m = moHunterDog;
2017-10-15 22:15:54 +00:00
if(m == moHunterChanging) m = moHunterDog;
if(m == moWolfMoved) m = moWolf;
if(!isBulletType(m)) kills[m]++;
2017-03-23 10:53:57 +00:00
if(saved_tortoise_on(c)) c->item = itNone;
2017-03-23 10:53:57 +00:00
if(!c->item) if(m == moButterfly && (deathflags & AF_BULL))
c->item = itBull;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(isRatling(m) && c->wall == waBoat) {
bool avenge = false;
for(int i=0; i<c->type; i++) if(!isWarpedType(c->move(i)->land))
2016-08-26 09:58:03 +00:00
avenge = true;
2017-03-23 10:53:57 +00:00
if(avenge) { avengers += 2; }
2016-08-26 09:58:03 +00:00
}
if(m == moMirrorSpirit && who != moMimic && !(deathflags & (AF_MAGIC | AF_CRUSH))) {
2017-07-22 23:33:27 +00:00
kills[m]--;
mirrorspirits++;
}
2017-03-23 10:53:57 +00:00
if(isMutantIvy(m) || m == moFriendlyIvy) {
pcount = 0;
killMutantIvy(c, who);
2016-08-26 09:58:03 +00:00
}
if(m == moPrincess) {
princess::info *i = princess::getPrincessInfo(c);
if(i) {
2016-01-02 10:09:13 +00:00
i->princess = NULL;
2017-03-23 10:53:57 +00:00
if(i->bestdist == OUT_OF_PALACE) {
items[itSavedPrincess]--;
2017-07-16 21:00:55 +00:00
if(items[itSavedPrincess] < 0) {
printf("princess below 0\n");
items[itSavedPrincess] = 0;
}
2017-07-12 16:03:53 +00:00
if(items[itSavedPrincess] == 0 && !inv::on) {
2017-03-23 10:53:57 +00:00
items[itOrbLove] = 0;
2017-07-12 16:03:53 +00:00
princess::reviveAt = gold(NO_LOVE) + 20;
2017-03-23 10:53:57 +00:00
}
}
2016-01-02 10:09:13 +00:00
if(princess::challenge) showMissionScreen();
}
}
if(m == moGargoyle && c->wall != waMineMine) {
bool connected = false;
2016-08-26 09:58:03 +00:00
if(isGravityLand(c->land)) {
2016-01-02 10:09:13 +00:00
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-01-02 10:09:13 +00:00
if(c2->wall == waPlatform || c2->wall == waGargoyle || c2->wall == waBarrier ||
2017-03-23 10:53:57 +00:00
c2->wall == waDeadTroll || c2->wall == waDeadTroll2 || c2->wall == waTrunk ||
c2->wall == waPetrified || isAlchAny(c2->wall))
2016-01-02 10:09:13 +00:00
connected = true;
}
}
else {
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-01-02 10:09:13 +00:00
if(!cellUnstableOrChasm(c2) && !isWatery(c2)) connected = true;
}
}
if(connected) petrify(c, waGargoyle, m), pcount = 0;
2016-01-02 10:09:13 +00:00
}
2017-09-30 09:46:41 +00:00
if(m == moIceGolem) {
if(petrify(c, waIcewall, m)) pcount = 0;
heat::affect(c, -1);
forCellEx(c2, c) heat::affect(c2, -.5);
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(m == moTroll) {
petrify(c, waDeadTroll, m); pcount = 0;
for(int i=0; i<c->type; i++) if(c->move(i)) {
c->move(i)->item = itNone;
if(c->move(i)->wall == waDeadwall || c->move(i)->wall == waDeadfloor2) c->move(i)->wall = waCavewall;
if(c->move(i)->wall == waDeadfloor) c->move(i)->wall = waCavefloor;
2015-08-08 13:57:52 +00:00
}
}
2016-08-26 09:58:03 +00:00
if(m == moFjordTroll || m == moForestTroll || m == moStormTroll) {
petrify(c, waDeadTroll2, m);
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
if(m == moMiner) {
2017-03-23 10:53:57 +00:00
pcount = 32;
playSound(c, "splash" + pick12());
2015-08-08 13:57:52 +00:00
destroyHalfvine(c);
2016-08-26 09:58:03 +00:00
minerEffect(c);
2018-10-25 00:43:14 +00:00
brownian::dissolve_brownian(c, 1);
for(int i=0; i<c->type; i++) if(passable(c->move(i), c, P_MONSTER | P_MIRROR | P_CLIMBUP | P_CLIMBDOWN)) {
destroyHalfvine(c->move(i));
minerEffect(c->move(i));
2018-10-25 00:43:14 +00:00
brownian::dissolve_brownian(c->move(i), 1);
if(c->move(i)->monst == moSlime || c->move(i)->monst == moSlimeNextTurn)
killMonster(c->move(i), who);
2015-08-08 13:57:52 +00:00
}
}
2017-03-23 10:53:57 +00:00
if(m == moOrangeDog) {
if(pcount) for(int i=0; i<8; i++) {
drawParticle(c, 0xFFFFFF);
drawParticle(c, 0x202020);
}
pcount = 0;
}
if(m == moDraugr) {
if(pcount) drawParticles(c, 0x804000, 8);
pcount = 0;
}
if(m == moPalace) {
if(pcount) {
pcount = 4;
for(int i=0; i<12; i++) drawParticle(c, 0x20C020);
}
}
if(m == moPrincess) {
playSound(c, princessgender() ? "die-princess" : "die-prince");
}
if(m == moVineBeast)
petrify(c, waVinePlant, m), pcount = 0;
if(isBird(m)) moveEffect(movei(c, FALL), moDeadBird);
2018-10-25 00:43:14 +00:00
if(m == moAcidBird) {
playSound(c, "die-bomberbird");
pcount = 64;
#if CAP_COMPLEX2
brownian::dissolve(c, 1);
#endif
}
2016-01-02 10:09:13 +00:00
if(m == moBomberbird || m == moTameBomberbird) {
2017-03-23 10:53:57 +00:00
pcount = 0;
playSound(c, "die-bomberbird");
2016-01-02 10:09:13 +00:00
if(c->wall == waNone || c->wall == waMineUnknown || c->wall == waMineOpen ||
c->wall == waCavefloor || c->wall == waDeadfloor || c->wall == waDeadfloor2 ||
c->wall == waRubble || c->wall == waGargoyleFloor ||
c->wall == waCIsland || c->wall == waCIsland2 ||
2017-03-23 10:53:57 +00:00
c->wall == waStrandedBoat || c->wall == waRed1 || c->wall == waGiantRug) {
2016-01-02 10:09:13 +00:00
c->wall = waMineMine;
2017-03-23 10:53:57 +00:00
if(c->item) explodeMine(c);
else if(c->land == laMinefield) c->landparam = 1;
2017-03-23 10:53:57 +00:00
}
2016-01-02 10:09:13 +00:00
else if(c->wall == waFrozenLake)
c->wall = waLake;
else if(c->wall == waGargoyleBridge)
placeWater(c, c);
else if(c->wall == waRed3 || c->wall == waRed2) {
c->wall = waRed1;
for(int i=0; i<c->type; i++) if(c->move(i)->wall == waRed3)
c->move(i)->wall = waRed2;
2016-01-02 10:09:13 +00:00
c->item = itNone;
}
2017-03-23 10:53:57 +00:00
eWall w = c->wall;
if(isFire(c) || c->wall == waRose || isReptile(c->wall)) {
2016-01-02 10:09:13 +00:00
c->wall = waMineMine;
explodeMine(c);
2017-03-23 10:53:57 +00:00
if(isReptile(w)) kills[moReptile]++;
if(w == waReptile) c->wall = waChasm;
if(w == waReptileBridge) placeWater(c, NULL);
}
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
if(m == moVineSpirit) {
2017-03-23 10:53:57 +00:00
pcount = 32;
playSound(c, "die-vinespirit");
2015-08-08 13:57:52 +00:00
destroyHalfvine(c);
2016-01-02 10:09:13 +00:00
if(!isFire(c)) c->wall = waNone;
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
if(m == moRedTroll) {
playSound(c, "die-troll");
if(doesFall(c)) fallingFloorAnimation(c, waRed1, m), pcount = 0;
else if(snakepile(c, m)) pcount = 0;
}
2018-10-25 00:43:14 +00:00
if(m == moBrownBug) {
if(doesFall(c)) ;
else if(snakepile(c, m)) pcount = 0;
}
2016-08-26 09:58:03 +00:00
if(m == moDarkTroll) {
2017-03-23 10:53:57 +00:00
playSound(c, "die-troll");
if(doesFall(c)) fallingFloorAnimation(c, waDeadwall, m), pcount = 0;
else if(c->wall == waRed1 || c->wall == waRed2 || c->wall == waRed3)
c->wall = waDeadwall, pcount = 0;
else if(snakepile(c, m))
pcount = 0;
2016-08-26 09:58:03 +00:00
}
if(isWitch(m) && (isFire(c) || passable(c, NULL, P_MONSTER)) && !c->item) {
2015-08-08 13:57:52 +00:00
if(m == moWitchFire) c->item = itOrbFire;
if(m == moWitchFlash) c->item = itOrbFlash;
2017-03-23 10:53:57 +00:00
if(m == moWitchGhost) c->item = itOrbAether;
2015-08-08 13:57:52 +00:00
if(m == moWitchWinter) c->item = itOrbWinter;
if(m == moWitchSpeed) c->item = itOrbSpeed;
2016-01-02 10:09:13 +00:00
if(isFire(c) && itemBurns(c->item))
2015-08-08 13:57:52 +00:00
c->item = itNone;
}
if(checkOrb(who, itOrbStone))
petrify(c, waPetrified, m), pcount = 0;
2017-03-23 10:53:57 +00:00
if(m == moFireFairy) {
drawFireParticles(c, 16); pcount = 0;
playSound(c, "die-fairy");
playSound(c, "fire");
2016-01-02 10:09:13 +00:00
makeflame(c, 50, false);
2017-03-23 10:53:57 +00:00
}
if(c->monst == moMetalBeast2 && !c->item && who == moLightningBolt && c->wall != waPetrified && c->wall != waChasm)
c->item = itFulgurite; // this is actually redundant in many cases
if(m == moPyroCultist && c->item == itNone && c->wall != waChasm && c->wall != waPetrified) {
2015-08-08 13:57:52 +00:00
// a reward for killing him before he shoots!
c->item = itOrbDragon;
}
2016-08-26 09:58:03 +00:00
if(m == moOutlaw && (c->item == itNone || c->item == itRevolver) && c->wall != waChasm)
c->item = itBounty;
2016-01-02 10:09:13 +00:00
// note: an Orb appears underwater!
if(m == moWaterElemental && c->item == itNone)
c->item = itOrbWater;
2016-08-26 09:58:03 +00:00
if(m == moPirate && isOnCIsland(c) && c->item == itNone && (
2018-08-09 17:28:53 +00:00
eubinary ||
2017-10-28 23:57:34 +00:00
(c->master->alt && celldistAlt(c) <= 2-getDistLimit()) ||
isHaunted(c->land)) && !cryst) {
2016-01-02 10:09:13 +00:00
bool toomany = false;
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-08-26 09:58:03 +00:00
if(c2 && c2->item == itCompass) toomany = true;
if(c2 && BITRUNCATED) for(int j=0; j<c2->type; j++)
if(c2->move(j) && c2->move(j)->item == itCompass)
2016-01-02 10:09:13 +00:00
toomany = true;
}
if(!toomany) c->item = itCompass;
}
2017-03-23 10:53:57 +00:00
if(m == moSlime) {
pcount = 0;
drawParticles(c, winf[c->wall].color, 80, 200);
playSound(c, "splash" + pick12());
c->monst = moNone;
spill(c, c->wall, 2);
}
2015-08-08 13:57:52 +00:00
// if(c->monst == moShark) c->heat += 1;
// if(c->monst == moGreaterShark) c->heat += 10;
if(isIcyLand(c)) {
2016-01-02 10:09:13 +00:00
if(m == moCultist) HEAT(c) += 3;
if(m == moPyroCultist) HEAT(c) += 6;
if(m == moLesser) HEAT(c) += 10;
2015-08-08 13:57:52 +00:00
}
if(m == moLesser && !(kills[m] % 10))
degradeDemons();
if(isIvy(c)) {
2017-03-23 10:53:57 +00:00
pcount = 0;
2015-08-08 13:57:52 +00:00
eMonster m = c->monst;
/*if((m == moIvyBranch || m == moIvyHead) && c->move(c->mondir)->monst == moIvyRoot)
2015-08-08 13:57:52 +00:00
ivynext(c, moIvyNext); */
2017-03-23 10:53:57 +00:00
killIvy(c, who);
2015-08-08 13:57:52 +00:00
if(m == moIvyBranch || m == moIvyHead || m == moIvyNext) {
int qty = 0;
cell *c2 = c->move(c->mondir);
2015-08-08 13:57:52 +00:00
for(int i=0; i<c2->type; i++)
if(c2->move(i)->monst == moIvyWait && c2->move(i)->mondir == c2->c.spin(i))
2015-08-08 13:57:52 +00:00
qty++;
if(c->move(c->mondir)->monst == moIvyRoot || qty) {
2015-08-08 13:57:52 +00:00
c->monst = moIvyNext;
/* c->monst = moIvyHead;
ivynext(c);
if(c->monst == moIvyHead) c->monst = moIvyNext;
else c->monst = moNone; */
}
else {
c->move(c->mondir)->monst = moIvyHead;
2015-08-08 13:57:52 +00:00
}
}
}
2016-01-02 10:09:13 +00:00
else if(c->monst == moTentacleGhost)
c->monst = moTentacletail;
2015-08-08 13:57:52 +00:00
else c->monst = moNone;
if(m == moPair && c->move(c->mondir)->monst == moPair)
killMonster(c->move(c->mondir), who, deathflags);
2018-01-02 10:15:42 +00:00
if(isMagneticPole(m) && c->move(c->mondir)->monst == otherpole(m))
killMonster(c->move(c->mondir), who, deathflags);
2018-01-02 10:15:42 +00:00
2015-08-08 13:57:52 +00:00
if(m == moEarthElemental) earthWall(c);
2016-08-26 09:58:03 +00:00
if(m == moAlbatross && items[itOrbLuck])
useupOrb(itOrbLuck, items[itOrbLuck] / 2);
if(m == moAirElemental) {
airmap.clear();
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(dcal); i++)
2016-08-26 09:58:03 +00:00
if(dcal[i]->monst == moAirElemental)
airmap.push_back(make_pair(dcal[i],0));
buildAirmap();
}
if(m == moMimic) {
for(auto& m: mirror::mirrors) if(c == m.second.at) {
drawParticles(c, mirrorcolor(m.second.mirrored), pcount);
if(c->wall == waMirrorWall)
drawParticles(c, mirrorcolor(!m.second.mirrored), pcount);
}
pcount = 0;
}
2017-03-23 10:53:57 +00:00
drawParticles(c, minf[m].color, pcount);
if(fallanim) {
2017-03-23 10:53:57 +00:00
fallingMonsterAnimation(c, m);
}
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void fightmessage(eMonster victim, eMonster attacker, bool stun, flagtype flags) {
2017-03-23 10:53:57 +00:00
if(isBird(attacker)) {
playSound(NULL, "hit-axe"+pick123());
addMessage(XLAT("%The1 claws %the2!", attacker, victim));
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
else if(isGhost(attacker))
addMessage(XLAT("%The1 scares %the2!", attacker, victim));
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
else if(isSlimeMover(attacker) && !stun) {
playSound(NULL, "hit-crush"+pick123());
addMessage(XLAT("%The1 eats %the2!", attacker, victim));
}
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
else if(flags & AF_EAT) {
playSound(NULL, "hit-crush"+pick123());
addMessage(XLAT("%The1 eats %the2!", attacker, victim));
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
else if(attacker == moLancer) {
playSound(NULL, "hit-rose");
addMessage(XLAT("%The1 pierces %the2!", attacker, victim));
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
else if(attacker == moEarthElemental) {
playSound(NULL, "hit-crush"+pick123());
addMessage(XLAT("%The1 punches %the2!", attacker, victim));
}
else if(attacker == moPlayer) {
if(flags & (AF_SWORD | AF_SWORD_INTO)) {
playSound(NULL, "hit-axe"+pick123());
addMessage(XLAT("You slash %the1.", victim));
if(victim == moGoblin)
achievement_gain("GOBLINSWORD");
}
else if(victim == moKrakenT || victim == moDragonTail || victim == moDragonHead) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("You hit %the1.", victim)); // normal
}
else if(stun && victim == moVizier) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("You hit %the1.", victim)); // normal
}
else if(stun) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("You stun %the1.", victim)); // normal
}
else if(isNonliving(victim)) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("You destroy %the1.", victim)); // normal
}
else if(flags & AF_STAB) {
playSound(NULL, "hit-axe"+pick123());
addMessage(XLAT("You stab %the1.", victim)); // normal
}
else if(flags & AF_APPROACH) {
playSound(NULL, "hit-sword"+pick123());
if(victim == moLancer)
addMessage(XLAT("You trick %the1.", victim)); // normal
else
addMessage(XLAT("You pierce %the1.", victim)); // normal
}
2017-07-04 13:38:33 +00:00
else if(!peace::on) {
2017-03-23 10:53:57 +00:00
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("You kill %the1.", victim)); // normal
}
}
else {
if(victim == moKrakenT || victim == moDragonTail || victim == moDragonHead) {
playSound(NULL, "hit-crush"+pick123());
addMessage(XLAT("%The1 hits %the2.", attacker, victim)); // normal
}
else if(stun && victim == moVizier) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("%The1 hits %the2.", attacker, victim)); // normal
}
else if(stun) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("%The1 attacks %the2!", attacker, victim)); // normal
}
else if(isNonliving(victim)) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("%The1 destroys %the2!", attacker, victim)); // normal
}
else if(flags & AF_STAB) {
playSound(NULL, "hit-axe"+pick123());
addMessage(XLAT("%The1 stabs %the2.", attacker, victim));
}
else if(flags & AF_APPROACH) {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("%The1 tricks %the2.", attacker, victim));
}
else {
playSound(NULL, "hit-sword"+pick123());
addMessage(XLAT("%The1 kills %the2!", attacker, victim));
}
}
}
2019-08-09 21:24:33 +00:00
EX void fallMonster(cell *c, flagtype flags IS(0)) {
2017-03-23 10:53:57 +00:00
attackMonster(c, flags, moNone);
}
2019-08-09 19:00:52 +00:00
EX bool notthateasy(eMonster m) {
2017-03-23 10:53:57 +00:00
return
isMultitile(m) || isStunnable(m) || m == moDraugr;
}
2019-08-09 19:00:52 +00:00
EX bool attackMonster(cell *c, flagtype flags, eMonster killer) {
2017-03-23 10:53:57 +00:00
if((flags & AF_GETPLAYER) && isPlayerOn(c)) {
killThePlayerAt(killer, c, flags);
return true;
}
eMonster m = c->monst;
int tk = tkills();
int tkt = killtypes();
2018-12-16 23:04:59 +00:00
bool dostun = attackJustStuns(c, flags, killer);
2017-03-23 10:53:57 +00:00
2017-06-18 16:51:46 +00:00
if((flags & AF_BULL) && c->monst == moVizier && c->hitpoints > 1) {
dostun = true;
c->stuntime = 2;
}
2017-03-23 10:53:57 +00:00
bool eu = landUnlocked(laElementalWall);
bool tu = landUnlocked(laTrollheim);
2017-03-23 10:53:57 +00:00
if(flags & AF_MSG) fightmessage(m, killer, dostun, flags);
if(dostun)
2018-12-16 23:04:59 +00:00
stunMonster(c, killer, flags);
2017-03-23 10:53:57 +00:00
else
killMonster(c, killer, flags);
2017-07-04 13:38:33 +00:00
if(peace::on) return false;
2017-03-23 10:53:57 +00:00
int ntk = tkills();
int ntkt = killtypes();
if(tkt < R20 && ntkt >= R20 && in_full_game()) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You hear a distant roar!"));
playSound(NULL, "message-roar");
}
if(tk == 0 && ntk > 0 && in_full_game() && !cheater) {
2017-03-23 10:53:57 +00:00
if(notthateasy(m))
addMessage(XLAT("Quite tough, for your first fight."));
else {
bool more = false;
forCellEx(c2, cwt.at) forCellEx(c3, c2)
if(c3->monst) more = true;
if(!more)
addMessage(XLAT("That was easy, but groups could be dangerous."));
}
2017-03-23 10:53:57 +00:00
}
2019-06-17 08:13:08 +00:00
if(tk < 10 && ntk >= 10 && in_full_game() && !big_unlock)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Good to know that your fighting skills serve you well in this strange world."));
if(tk < R100/2 && ntk >= R100/2 && in_full_game())
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You wonder where all these monsters go, after their death..."));
if(tk < R100 && ntk >= R100 && in_full_game())
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel that the souls of slain enemies pull you to the Graveyard..."));
if(!tu && landUnlocked(laTrollheim) && in_full_game()) {
2017-03-23 10:53:57 +00:00
playSound(c, "message-troll");
addMessage(XLAT("%The1 says, \"I die, but my clan in Trollheim will avenge me!\"", m));
}
if(!eu && landUnlocked(laElementalWall) && in_full_game())
2017-03-23 10:53:57 +00:00
addMessage(XLAT("After killing %the1, you feel able to reach the Elemental Planes!", m));
if(m == moVizier && c->monst != moVizier && kills[moVizier] == 1 && in_full_game()) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Hmm, he has been training in the Emerald Mine. Interesting..."));
princess::forceMouse = true;
}
if(m == moIvyRoot && ntk>tk)
achievement_gain("IVYSLAYER");
return ntk > tk;
}
EX void pushMonster(const movei& mi) {
moveMonster(mi);
auto& cf = mi.s;
auto& ct = mi.t;
2018-10-25 00:43:14 +00:00
if(ct->monst == moBrownBug) {
int t = snakelevel(ct) - snakelevel(cf);
if(t > 0)
ct->stuntime = min(ct->stuntime + 2 * t, 7);
}
2019-04-05 11:42:18 +00:00
if(isBull(ct->monst)) ct->monst = moRagingBull;
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool destroyHalfvine(cell *c, eWall newwall IS(waNone), int tval IS(6)) {
2017-03-23 10:53:57 +00:00
if(cellHalfvine(c)) {
for(int t=0; t<c->type; t++) if(c->move(t)->wall == c->wall) {
if(newwall == waPartialFire) flameHalfvine(c->move(t), tval);
else if(newwall == waRed1) c->move(t)->wall = waVinePlant;
else c->move(t)->wall = newwall;
2015-08-08 13:57:52 +00:00
}
2016-01-02 10:09:13 +00:00
if(newwall == waPartialFire) flameHalfvine(c, tval);
2015-08-08 13:57:52 +00:00
else c->wall = newwall;
return true;
}
return false;
}
2019-08-09 19:00:52 +00:00
EX int coastvalEdge(cell *c) { return coastval(c, laIvoryTower); }
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int gravityLevel(cell *c) {
2017-03-23 10:53:57 +00:00
if(c->land == laIvoryTower || c->land == laEndorian)
return coastval(c, laIvoryTower);
if(c->land == laDungeon)
return -coastval(c, laIvoryTower);
if(c->land == laMountain)
return 1-celldistAlt(c);
return 0;
}
2019-08-09 19:00:52 +00:00
EX int gravityLevelDiff(cell *c, cell *d) {
2018-12-21 13:41:23 +00:00
if(c->land != laWestWall || d->land != laWestWall)
return gravityLevel(c) - gravityLevel(d);
2019-01-11 01:23:44 +00:00
if(shmup::on) return 0;
int nid = neighborId(c, d);
int id1 = parent_id(c, 1, coastvalEdge) + 1;
int di1 = angledist(c->type, id1, nid);
int id2 = parent_id(c, -1, coastvalEdge) - 1;
int di2 = angledist(c->type, id2, nid);
if(di1 < di2) return 1;
if(di1 > di2) return -1;
return 0;
2018-12-21 13:41:23 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool canUnstable(eWall w, flagtype flags) {
2017-03-23 10:53:57 +00:00
return w == waNone || w == waCanopy || w == waOpenPlate || w == waClosePlate ||
w == waOpenGate || ((flags & MF_STUNNED) && (w == waLadder || w == waTrunk || w == waSolidBranch || w == waWeakBranch
|| w == waBigBush || w == waSmallBush));
}
2019-08-09 19:00:52 +00:00
EX bool cellEdgeUnstable(cell *c, flagtype flags IS(0)) {
2017-03-23 10:53:57 +00:00
if(!isGravityLand(c->land) || !canUnstable(c->wall, flags)) return false;
2019-01-11 01:23:44 +00:00
if(shmup::on && c->land == laWestWall) return false;
2019-03-23 15:29:16 +00:00
forCellEx(c2, c) {
if(isAnyIvy(c2->monst) &&
2017-03-23 10:53:57 +00:00
c->land == laMountain && !(flags & MF_IVY)) return false;
2019-03-23 15:29:16 +00:00
int d = gravityLevelDiff(c, c2);
if(d == gravity_zone_diff(c)) {
if(againstWind(c2, c)) return false;
if(!passable(c2, NULL, P_MONSTER | P_DEADLY))
2016-08-26 09:58:03 +00:00
return false;
2019-03-23 15:29:16 +00:00
if(isWorm(c2))
2016-08-26 09:58:03 +00:00
return false;
}
2019-05-08 16:33:08 +00:00
if(WDIM == 3) {
2019-03-23 15:29:16 +00:00
if(d == 0 && !passable(c2, NULL, P_MONSTER | P_DEADLY)) return false;
if(d == -1 && !passable(c2, NULL, P_MONSTER | P_DEADLY)) forCellEx(c3, c2) if(c3 != c && gravityLevelDiff(c3, c) == 0) return false;
}
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
return true;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
// find worms and ivies
2019-08-09 19:00:52 +00:00
EX void settemp(cell *c) {
tempmonsters.emplace_back(c, (eMonster) c->monst);
c->monst = moNone;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void findWormIvy(cell *c) {
2016-08-26 09:58:03 +00:00
while(true) {
if(c->monst == moWorm || c->monst == moTentacle || c->monst == moWormwait || c->monst == moTentaclewait ||
c->monst == moTentacleEscaping) {
worms.push_back(c); settemp(c);
break;
}
else if(c->monst == moHexSnake) {
hexsnakes.push_back(c); settemp(c);
}
else if(c->monst == moWormtail || c->monst == moHexSnakeTail) {
bool bug = true;
for(int i=0; i<c->type; i++) {
cell* c2 = c->move(i);
if(c2 && isWorm(c2) && c2->mondir != NODIR && c2->move(c2->mondir) == c) {
2016-08-26 09:58:03 +00:00
settemp(c);
c = c2;
bug = false;
}
}
if(bug) break;
}
else if(c->monst == moIvyWait) {
cell* c2 = c->move(c->mondir);
2016-08-26 09:58:03 +00:00
settemp(c); c=c2;
}
else if(c->monst == moIvyHead) {
ivies.push_back(c); settemp(c);
break;
}
else if(c->monst == moIvyBranch || c->monst == moIvyRoot) {
bool bug = true;
for(int i=0; i<c->type; i++) {
cell* c2 = c->move(i);
if(c2 && (c2->monst == moIvyHead || c2->monst == moIvyBranch) && c2->move(c2->mondir) == c) {
2016-08-26 09:58:03 +00:00
settemp(c);
c = c2;
bug = false;
}
}
if(bug) break;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else break;
2015-08-08 13:57:52 +00:00
}
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
bool bugsfighting;
2016-01-02 10:09:13 +00:00
EX bool keepLightning = false;
2016-01-02 10:09:13 +00:00
EX int statuecount;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
int tidalphase;
2016-01-02 10:09:13 +00:00
EX int tidalsize, tide[200];
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void calcTidalPhase() {
2016-08-26 09:58:03 +00:00
if(!tidalsize) {
for(int i=0; i<5; i++) tide[tidalsize++] = 1;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=1; i<4; i++) for(int j=0; j<3; j++)
tide[tidalsize++] = i;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=4; i<7; i++) for(int j=0; j<2; j++)
tide[tidalsize++] = i;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=7; i<20; i++)
tide[tidalsize++] = i;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=20; i<23; i++) for(int j=0; j<2; j++)
tide[tidalsize++] = i;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=23; i<26; i++) for(int j=0; j<3; j++)
tide[tidalsize++] = i;
for(int i=0; i+i<tidalsize; i++) tide[tidalsize++] = 27 - tide[i];
/* printf("tidalsize = %d\n", tidalsize);
for(int i=0; i<tidalsize; i++) printf("%d ", tide[i]);
printf("\n"); */
}
tidalphase = tide[
(shmup::on ? shmup::curtime/600 : turncount)
% tidalsize];
2017-07-04 13:38:33 +00:00
if(peace::on)
tidalphase = 5 + tidalphase / 6;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX int tidespeed() {
2016-08-26 09:58:03 +00:00
return tide[(turncount+6) % tidalsize] - tidalphase;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
bool recalcTide;
2016-01-02 10:09:13 +00:00
#if HDR
2016-08-26 09:58:03 +00:00
#define SEADIST LHU.bytes[0]
#define LANDDIST LHU.bytes[1]
#define CHAOSPARAM LHU.bytes[2]
#endif
2016-01-02 10:09:13 +00:00
2019-02-17 17:33:15 +00:00
#if CAP_FIELD
2019-08-09 19:00:52 +00:00
EX int lavatide(cell *c, int t) {
int tc = (shmup::on ? shmup::curtime/400 : turncount);
return (windmap::at(c) + (tc+t)*4) & 255;
2017-09-30 09:46:41 +00:00
}
2019-02-17 17:33:15 +00:00
#endif
2017-09-30 09:46:41 +00:00
2019-08-09 19:00:52 +00:00
EX void checkTide(cell *c) {
2016-08-26 09:58:03 +00:00
if(c->land == laOcean) {
int t = c->landparam;
if(chaosmode) {
char& csd(c->SEADIST); if(csd == 0) csd = 7;
char& cld(c->LANDDIST); if(cld == 0) cld = 7;
int seadist=csd, landdist=cld;
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-08-26 09:58:03 +00:00
if(!c2) continue;
if(c2->land == laBarrier || c2->land == laOceanWall) ;
else if(c2->land == laOcean)
seadist = min(seadist, c2->SEADIST ? c2->SEADIST+1 : 7),
landdist = min(landdist, c2->LANDDIST ? c2->LANDDIST+1 : 7);
else if(isSealand(c2->land)) seadist = 1;
else landdist = 1;
}
if(seadist < csd) csd = seadist, recalcTide = true;
if(landdist < cld) cld = landdist, recalcTide = true;
if(seadist == 1 && landdist == 1) t = 15;
else t = c->CHAOSPARAM = 1 + (29 * (landdist-1)) / (seadist+landdist-2);
}
if(c->wall == waStrandedBoat || c->wall == waBoat)
c->wall = t >= tidalphase ? waBoat : waStrandedBoat;
if(c->wall == waSea || c->wall == waNone)
c->wall = t >= tidalphase ? waSea : waNone;
if(isFire(c) && t >= tidalphase)
c->wall = waSea;
2015-08-08 13:57:52 +00:00
}
2019-02-17 17:33:15 +00:00
#if CAP_FIELD
2017-10-08 09:12:03 +00:00
if(c->land == laVolcano) {
int id = lavatide(c, 0);
2017-10-08 09:12:03 +00:00
if(id < 96) {
if(c->wall == waNone || isWateryOrBoat(c) || c->wall == waVinePlant || isAlch(c)) {
if(isWateryOrBoat(c) || isAlch(c))
2017-10-10 12:59:19 +00:00
playSound(c, "steamhiss");
c->wall = waMagma;
if(itemBurns(c->item)) {
addMessage(XLAT("%The1 burns!", c->item)), c->item = itNone;
2017-10-10 12:59:19 +00:00
playSound(c, "steamhiss", 30);
}
}
2017-10-08 09:12:03 +00:00
}
else if(c->wall == waMagma) c->wall = waNone;
2017-09-30 09:46:41 +00:00
}
2019-02-17 17:33:15 +00:00
#endif
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void buildAirmap() {
2018-06-22 12:47:24 +00:00
for(int k=0; k<isize(airmap); k++) {
2016-08-26 09:58:03 +00:00
int d = airmap[k].second;
if(d == 2) break;
cell *c = airmap[k].first;
for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-08-26 09:58:03 +00:00
if(!c2) continue;
if(!passable(c2, c, P_BLOW | P_MONSTER)) continue;
if(!passable(c, c2, P_BLOW | P_MONSTER)) continue;
airmap.push_back(make_pair(c2, d+1));
2016-01-02 10:09:13 +00:00
}
}
2016-08-26 09:58:03 +00:00
sort(airmap.begin(), airmap.end());
2016-01-02 10:09:13 +00:00
}
/** current state of the rose scent
* rosemap[c] &3 can be:
* 0 - wave not reached
* 1 - wave expanding
* 2 - wave phase 1
* 3 - wave phase 2
*/
EX map<cell*, int> rosemap;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int rosedist(cell *c) {
2017-03-23 10:53:57 +00:00
if(!(havewhat&HF_ROSE)) return 0;
2016-08-26 09:58:03 +00:00
int&r (rosemap[c]);
if((r&7) == 7) return 0;
if(r&3) return (r&3)-1;
return 0;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool againstRose(cell *cfrom, cell *cto) {
2016-08-26 09:58:03 +00:00
if(rosedist(cfrom) != 1) return false;
if(cto && rosedist(cto) == 2) return false;
return true;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool withRose(cell *cfrom, cell *cto) {
2016-08-26 09:58:03 +00:00
if(rosedist(cfrom) != 1) return false;
if(rosedist(cto) != 2) return false;
return true;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void buildRosemap() {
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
rosephase++; rosephase &= 7;
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if((havewhat&HF_ROSE) && !rosephase) {
2016-08-26 09:58:03 +00:00
rosewave++;
2018-06-22 12:47:24 +00:00
for(int k=0; k<isize(dcal); k++) {
2016-08-26 09:58:03 +00:00
cell *c = dcal[k];
if(c->wall == waRose && c->cpdist <= gamerange() - 2)
2016-08-26 09:58:03 +00:00
rosemap[c] = rosewave * 8 + 2;
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
for(map<cell*, int>::iterator it = rosemap.begin(); it != rosemap.end(); it++) {
cell *c = it->first;
int r = it->second;
if(r < (rosewave) * 8) continue;
if((r&7) == 2) if(c->wall == waRose || !isWall(c)) for(int i=0; i<c->type; i++) {
cell *c2 = c->move(i);
2016-08-26 09:58:03 +00:00
if(!c2) continue;
// if(snakelevel(c2) <= snakelevel(c) - 2) continue;
if(!passable(c2, c, P_BLOW | P_MONSTER | P_ROSE)) continue;
int& r2 = rosemap[c2];
if(r2 < r) r2 = r-1;
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
for(map<cell*, int>::iterator it = rosemap.begin(); it != rosemap.end(); it++) {
int& r = it->second;
if((r&7) == 1 || (r&7) == 2 || (r&7) == 3) r++;
if(airdist(it->first) < 3 || whirlwind::cat(it->first)) r |= 7;
2018-01-25 16:16:36 +00:00
if(it->first->land == laBlizzard) r |= 7;
forCellEx(c2, it->first) if(airdist(c2) < 3) r |= 7;
2015-08-08 13:57:52 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX int getDistLimit() { return cgi.base_distlimit; }
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool nogoSlow(cell *to, cell *from) {
2018-12-21 13:41:23 +00:00
if(cellEdgeUnstable(to) && gravityLevelDiff(to, from) >= 0) return true;
2017-03-23 10:53:57 +00:00
if(cellUnstable(to)) return true;
return false;
}
// pathdist begin
2019-08-09 20:07:03 +00:00
EX cell *pd_from;
EX int pd_range;
2018-04-11 11:16:40 +00:00
2019-08-09 19:00:52 +00:00
EX void onpath(cell *c, int d) {
c->pathdist = d;
pathq.push_back(c);
}
2019-08-09 19:00:52 +00:00
EX void onpath(cell *c, int d, int sp) {
c->pathdist = d;
pathq.push_back(c);
reachedfrom.push_back(sp);
}
2019-08-09 19:00:52 +00:00
EX void clear_pathdata() {
for(auto c: pathq) c->pathdist = PINFD;
pathq.clear();
pathqm.clear();
reachedfrom.clear();
}
2019-08-09 20:37:11 +00:00
EX int pathlock = 0;
2019-08-09 19:00:52 +00:00
EX void compute_graphical_distance() {
if(pathlock) { printf("path error: compute_graphical_distance\n"); }
cell *c1 = centerover ? centerover : pd_from ? pd_from : cwt.at;
2018-04-11 11:16:40 +00:00
int sr = get_sightrange_ambush();
if(pd_from == c1 && pd_range == sr) return;
clear_pathdata();
2018-04-11 11:16:40 +00:00
pd_from = c1;
pd_range = sr;
c1->pathdist = 0;
pathq.push_back(pd_from);
2018-06-22 12:47:24 +00:00
for(int qb=0; qb<isize(pathq); qb++) {
2018-04-11 11:16:40 +00:00
cell *c = pathq[qb];
if(c->pathdist == pd_range) break;
if(qb == 0) forCellCM(c1, c) ;
2018-04-11 11:16:40 +00:00
forCellEx(c1, c)
if(c1->pathdist == PINFD)
onpath(c1, c->pathdist + 1);
2018-04-11 11:16:40 +00:00
}
}
2018-04-11 11:16:40 +00:00
2019-08-09 19:00:52 +00:00
EX void computePathdist(eMonster param) {
2017-03-23 10:53:57 +00:00
for(cell *c: targets)
onpath(c, isPlayerOn(c) ? 0 : 1, hrand(c->type));
2017-03-23 10:53:57 +00:00
2018-06-22 12:47:24 +00:00
int qtarg = isize(targets);
int limit = gamerange();
2017-03-23 10:53:57 +00:00
2018-06-22 12:47:24 +00:00
for(int qb=0; qb < isize(pathq); qb++) {
2017-03-23 10:53:57 +00:00
cell *c = pathq[qb];
2019-10-27 01:48:50 +00:00
int fd = reachedfrom[qb] + c->type/2;
2017-03-23 10:53:57 +00:00
if(c->monst && !isBug(c) && !(isFriendly(c) && !c->stuntime)) {
pathqm.push_back(c);
continue; // no paths going through monsters
}
2018-02-27 22:43:21 +00:00
if(isMounted(c) && !isPlayerOn(c)) {
// don't treat the Worm you are riding as passable
pathqm.push_back(c);
continue;
2017-03-23 10:53:57 +00:00
}
if(c->cpdist > limit && !(c->land == laTrollheim && turncount < c->landparam)) continue;
2017-03-23 10:53:57 +00:00
int d = c->pathdist;
if(d == PINFD - 1) continue;
for(int j=0; j<c->type; j++) {
int i = (fd+j) % c->type;
// printf("i=%d cd=%d\n", i, c->move(i)->cpdist);
cell *c2 = c->move(i);
2017-03-23 10:53:57 +00:00
if(c2 && c2->pathdist == PINFD &&
passable(c2, (qb<qtarg) && !nonAdjacent(c,c2) && !thruVine(c,c2) ?NULL:c, P_MONSTER | P_REVDIR)) {
2017-03-23 10:53:57 +00:00
if(qb >= qtarg) {
if(param == moTortoise && nogoSlow(c, c2)) continue;
if(param == moIvyRoot && strictlyAgainstGravity(c, c2, false, MF_IVY)) continue;
if(param == moWorm && (cellUnstable(c) || cellEdgeUnstable(c) || prairie::no_worms(c))) continue;
if(items[itOrbLava] && c2->cpdist <= 5 && pseudohept(c) && makeflame(c2, 1, true))
continue;
2017-03-23 10:53:57 +00:00
}
onpath(c2, d+1, c->c.spin(i));
2017-03-23 10:53:57 +00:00
}
}
}
}
2019-08-09 20:07:03 +00:00
#if HDR
struct pathdata {
void checklock() {
if(pd_from) pd_from = NULL, clear_pathdata();
if(pathlock) printf("path error\n");
pathlock++;
}
~pathdata() {
pathlock--;
clear_pathdata();
}
pathdata(eMonster m) {
checklock();
computePathdist(m);
}
pathdata(int i) {
checklock();
}
};
#endif
2017-03-23 10:53:57 +00:00
// pathdist end
EX vector<pair<cell*, int> > butterflies;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX void addButterfly(cell *c) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(butterflies); i++)
2017-03-23 10:53:57 +00:00
if(butterflies[i].first == c) {
butterflies[i].second = 0;
return;
}
butterflies.push_back(make_pair(c, 0));
}
/** calculate cpdist, 'have' flags, and do general fixings */
2019-08-09 19:00:52 +00:00
EX void bfs() {
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
calcTidalPhase();
yendor::onpath();
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) dcal[i]->cpdist = INFD;
2017-07-22 23:33:27 +00:00
worms.clear(); ivies.clear(); ghosts.clear(); golems.clear();
tempmonsters.clear(); targets.clear();
2016-08-26 09:58:03 +00:00
statuecount = 0;
hexsnakes.clear();
2017-03-23 10:53:57 +00:00
hadwhat = havewhat;
2018-01-25 22:22:33 +00:00
havewhat = 0; jiangshi_on_screen = 0;
2017-12-05 18:43:45 +00:00
snaketypes.clear();
2017-03-23 10:53:57 +00:00
if(!(hadwhat & HF_WARP)) { avengers = 0; }
2017-07-22 23:33:27 +00:00
if(!(hadwhat & HF_MIRROR)) { mirrorspirits = 0; }
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
elec::havecharge = false;
2017-03-23 10:53:57 +00:00
elec::afterOrb = false;
elec::haveelec = false;
2016-08-26 09:58:03 +00:00
airmap.clear();
2017-03-23 10:53:57 +00:00
if(!(hadwhat & HF_ROSE)) rosemap.clear();
2016-08-26 09:58:03 +00:00
dcal.clear(); reachedfrom.clear();
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
recalcTide = false;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=0; i<numplayers(); i++) {
cell *c = playerpos(i);
2017-03-23 10:53:57 +00:00
if(!c) continue;
2016-08-26 09:58:03 +00:00
if(c->cpdist == 0) continue;
c->cpdist = 0;
checkTide(c);
dcal.push_back(c);
reachedfrom.push_back(hrand(c->type));
if(!invismove) targets.push_back(c);
2016-01-02 10:09:13 +00:00
}
int distlimit = gamerange();
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) {
cell *c = playerpos(i);
if(!c) continue;
2018-02-27 22:43:21 +00:00
if(items[itOrbDomination])
if(c->monst == moTentacle || c->monst == moTentaclewait || c->monst == moTentacleEscaping)
2017-03-23 10:53:57 +00:00
worms.push_back(c);
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
int qb = 0;
2019-03-09 17:31:02 +00:00
first7 = 0;
2016-08-26 09:58:03 +00:00
while(true) {
2018-06-22 12:47:24 +00:00
if(qb == isize(dcal)) break;
2016-08-26 09:58:03 +00:00
int i, fd = reachedfrom[qb] + 3;
cell *c = dcal[qb++];
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
int d = c->cpdist;
2019-03-09 17:31:02 +00:00
2019-05-08 16:33:08 +00:00
if(WDIM == 2 && d == distlimit) { first7 = qb; break; }
2019-03-09 17:31:02 +00:00
for(int j=0; j<c->type; j++) if(i = (fd+j) % c->type, c->move(i)) {
// printf("i=%d cd=%d\n", i, c->move(i)->cpdist);
cell *c2 = c->move(i);
2017-03-23 10:53:57 +00:00
if(!c2) continue;
2016-08-26 09:58:03 +00:00
if(isWarpedType(c2->land)) havewhat |= HF_WARP;
2017-07-22 23:33:27 +00:00
if(c2->land == laMirror) havewhat |= HF_MIRROR;
2016-08-26 09:58:03 +00:00
if((c->wall == waBoat || c->wall == waSea) &&
(c2->wall == waSulphur || c2->wall == waSulphurC))
c2->wall = waSea;
if(c2 && signed(c2->cpdist) > d+1) {
2019-05-08 16:33:08 +00:00
if(WDIM == 3 && !gmatrix.count(c2)) {
2019-03-09 17:31:02 +00:00
if(!first7) first7 = qb;
continue;
}
2016-08-26 09:58:03 +00:00
c2->cpdist = d+1;
// remove treasures
2017-07-04 13:38:33 +00:00
if(!peace::on && c2->item && c2->cpdist == distlimit && itemclass(c2->item) == IC_TREASURE &&
2016-08-26 09:58:03 +00:00
c2->item != itBabyTortoise &&
2017-03-23 10:53:57 +00:00
(items[c2->item] >= (chaosmode?10:20) + currentLocalTreasure || getGhostcount() >= 2)) {
2016-08-26 09:58:03 +00:00
c2->item = itNone;
2017-03-23 10:53:57 +00:00
if(c2->land == laMinefield) { c2->landparam &= ~3; }
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(c2->item == itBombEgg && c2->cpdist == distlimit && items[itBombEgg] >= c2->landparam) {
c2->item = itNone;
2017-03-23 10:53:57 +00:00
c2->landparam |= 2;
c2->landparam &= ~1;
2016-08-26 09:58:03 +00:00
if(!c2->monst) c2->monst = moBomberbird;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(c2->item == itBarrow && c2->cpdist == distlimit && c2->wall != waBarrowDig) {
c2->item = itNone;
}
2016-08-26 09:58:03 +00:00
if(c2->item == itLotus && c2->cpdist == distlimit && items[itLotus] >= getHauntedDepth(c2)) {
c2->item = itNone;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(c2->item == itMutant2 && timerghost) {
2016-08-26 09:58:03 +00:00
bool rotten = true;
for(int i=0; i<c2->type; i++)
if(c2->move(i) && c2->move(i)->monst == moMutant)
2016-08-26 09:58:03 +00:00
rotten = false;
if(rotten) c2->item = itNone;
}
if(c2->item == itDragon && (shmup::on ? shmup::curtime-c2->landparam>300000 :
turncount-c2->landparam > 500))
c2->item = itNone;
2017-03-23 10:53:57 +00:00
if(c2->item == itTrollEgg && c2->cpdist == distlimit && !shmup::on && c2->landparam && turncount-c2->landparam > 650)
c2->item = itNone;
if(c2->item == itWest && c2->cpdist == distlimit && items[itWest] >= c2->landparam + 4)
c2->item = itNone;
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(c2->item == itMutant && c2->cpdist == distlimit && items[itMutant] >= c2->landparam) {
c2->item = itNone;
}
2017-03-23 10:53:57 +00:00
if(c2->item == itIvory && c2->cpdist == distlimit && items[itIvory] >= c2->landparam) {
c2->item = itNone;
}
if(c2->item == itAmethyst && c2->cpdist == distlimit && items[itAmethyst] >= -celldistAlt(c2)/5) {
2016-08-26 09:58:03 +00:00
c2->item = itNone;
}
if(!keepLightning) c2->ligon = 0;
dcal.push_back(c2);
reachedfrom.push_back(c->c.spin(i));
2016-08-26 09:58:03 +00:00
checkTide(c2);
if(c2->wall == waBigStatue && c2->land != laTemple)
statuecount++;
2017-03-23 10:53:57 +00:00
if(cellHalfvine(c2) && isWarped(c2)) {
addMessage(XLAT("%The1 is destroyed!", c2->wall));
destroyHalfvine(c2);
}
2016-08-26 09:58:03 +00:00
if(c2->wall == waCharged) elec::havecharge = true;
2017-03-23 10:53:57 +00:00
if(c2->land == laStorms) elec::haveelec = true;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(c2->land == laWhirlpool) havewhat |= HF_WHIRLPOOL;
if(c2->land == laWhirlwind) havewhat |= HF_WHIRLWIND;
2018-12-21 13:41:23 +00:00
if(c2->land == laWestWall) havewhat |= HF_WESTWALL;
2017-03-23 10:53:57 +00:00
if(c2->land == laPrairie) havewhat |= HF_RIVER;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(c2->wall == waRose) havewhat |= HF_ROSE;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if((hadwhat & HF_ROSE) && (rosemap[c2] & 3)) havewhat |= HF_ROSE;
2016-08-26 09:58:03 +00:00
if(c2->monst) {
if(isHaunted(c2->land) &&
c2->monst != moGhost && c2->monst != moZombie && c2->monst != moNecromancer)
survivalist = false;
if(c2->monst == moHexSnake || c2->monst == moHexSnakeTail) {
2017-03-23 10:53:57 +00:00
havewhat |= HF_HEX;
2017-12-05 18:43:45 +00:00
if(c2->mondir != NODIR)
snaketypes.insert(snake_pair(c2));
2016-08-26 09:58:03 +00:00
if(c2->monst == moHexSnake) hexsnakes.push_back(c2);
else findWormIvy(c2);
}
2017-03-23 10:53:57 +00:00
else if(c2->monst == moKrakenT || c2->monst == moKrakenH) {
havewhat |= HF_KRAKEN;
}
2016-08-26 09:58:03 +00:00
else if(c2->monst == moDragonHead || c2->monst == moDragonTail) {
2017-03-23 10:53:57 +00:00
havewhat |= HF_DRAGON;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
else if(c2->monst == moWitchSpeed)
havewhat |= HF_FAST;
2016-08-26 09:58:03 +00:00
else if(c2->monst == moMutant)
2017-03-23 10:53:57 +00:00
havewhat |= HF_MUTANT;
2018-01-25 22:22:33 +00:00
else if(c2->monst == moJiangshi)
jiangshi_on_screen++;
2016-08-26 09:58:03 +00:00
else if(c2->monst == moOutlaw)
2017-03-23 10:53:57 +00:00
havewhat |= HF_OUTLAW;
2016-08-26 09:58:03 +00:00
else if(isGhostMover(c2->monst))
ghosts.push_back(c2);
else if(isWorm(c2) || isIvy(c2)) findWormIvy(c2);
else if(isBug(c2)) {
2017-03-23 10:53:57 +00:00
havewhat |= HF_BUG;
2016-08-26 09:58:03 +00:00
targets.push_back(c2);
}
else if(isFriendly(c2)) {
if(c2->monst != moMouse && !markEmpathy(itOrbInvis) && !(isWatery(c2) && markEmpathy(itOrbFish)) &&
2017-03-23 10:53:57 +00:00
!c2->stuntime) targets.push_back(c2);
2016-08-26 09:58:03 +00:00
if(c2->monst == moGolem) golems.push_back(c2);
if(c2->monst == moFriendlyGhost) golems.push_back(c2);
if(c2->monst == moKnight) golems.push_back(c2);
if(c2->monst == moTameBomberbird) golems.push_back(c2);
2017-03-23 10:53:57 +00:00
if(c2->monst == moMouse) { golems.push_back(c2); havewhat |= HF_MOUSE; }
2016-08-26 09:58:03 +00:00
if(c2->monst == moPrincess || c2->monst == moPrincessArmed) golems.push_back(c2);
if(c2->monst == moIllusion) {
if(items[itOrbIllusion]) items[itOrbIllusion]--;
else c2->monst = moNone;
}
}
2017-03-23 10:53:57 +00:00
else if(c2->monst == moButterfly) {
addButterfly(c2);
}
else if(isAngryBird(c2->monst)) {
havewhat |= HF_BIRD;
if(c2->monst == moBat) havewhat |= HF_BATS | HF_EAGLES;
if(c2->monst == moEagle) havewhat |= HF_EAGLES;
}
else if(c2->monst == moReptile) havewhat |= HF_REPTILE;
else if(isLeader(c2->monst)) havewhat |= HF_LEADER;
else if(c2->monst == moEarthElemental) havewhat |= HF_EARTH;
else if(c2->monst == moWaterElemental) havewhat |= HF_WATER;
2017-09-30 09:46:41 +00:00
else if(c2->monst == moVoidBeast) havewhat |= HF_VOID;
else if(c2->monst == moHunterDog) havewhat |= HF_HUNTER;
2018-01-02 10:15:42 +00:00
else if(isMagneticPole(c2->monst)) havewhat |= HF_MAGNET;
else if(c2->monst == moAltDemon) havewhat |= HF_ALT;
else if(c2->monst == moHexDemon) havewhat |= HF_HEXD;
else if(c2->monst == moMonk) havewhat |= HF_MONK;
2017-03-23 10:53:57 +00:00
else if(c2->monst == moShark || c2->monst == moCShark) havewhat |= HF_SHARK;
2016-08-26 09:58:03 +00:00
else if(c2->monst == moAirElemental)
2017-03-23 10:53:57 +00:00
havewhat |= HF_AIR, airmap.push_back(make_pair(c2,0));
2016-08-26 09:58:03 +00:00
}
// pheromones!
if(c2->land == laHive && c2->landparam >= 50 && c2->wall != waWaxWall)
2017-03-23 10:53:57 +00:00
havewhat |= HF_BUG;
2016-08-26 09:58:03 +00:00
if(c2->wall == waThumperOn)
targets.push_back(c2);
2017-03-23 10:53:57 +00:00
2016-01-02 10:09:13 +00:00
}
}
}
2016-08-26 09:58:03 +00:00
while(recalcTide) {
recalcTide = false;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(dcal); i++) checkTide(dcal[i]);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
for(auto& t: tempmonsters) t.first->monst = t.second;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
buildAirmap();
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool makeEmpty(cell *c) {
2017-03-23 10:53:57 +00:00
if(c->monst != moPrincess) {
if(isAnyIvy(c->monst)) killMonster(c, moPlayer, 0);
else if(c->monst == moPair) {
if(c->move(c->mondir)->monst == moPair)
c->move(c->mondir)->monst = moNone;
}
2017-03-23 10:53:57 +00:00
else if(isWorm(c->monst)) {
if(!items[itOrbDomination]) return false;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else c->monst = moNone;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
if(c->land == laCocytus)
c->wall = waFrozenLake;
else if(c->land == laAlchemist || c->land == laCanvas)
;
2017-10-29 22:54:26 +00:00
else if(c->land == laDual)
;
2016-08-26 09:58:03 +00:00
else if(c->land == laCaves || c->land == laEmerald)
c->wall = waCavefloor;
else if(c->land == laDeadCaves)
c->wall = waDeadfloor2;
2019-10-05 17:59:59 +00:00
else if(c->land == laCaribbean || c->land == laOcean || c->land == laWhirlpool || c->land == laLivefjord || c->land == laWarpSea || c->land == laKraken || c->wall == waBoat)
2016-08-26 09:58:03 +00:00
c->wall = waBoat; // , c->item = itOrbYendor;
else if(c->land == laMinefield)
c->wall = waMineOpen;
else if(c->wall == waFan && bounded)
2017-03-23 10:53:57 +00:00
;
else if(c->wall == waOpenPlate && bounded)
2017-03-23 10:53:57 +00:00
;
else if(c->wall == waTrunk || c->wall == waSolidBranch || c->wall == waWeakBranch)
;
2017-03-23 10:53:57 +00:00
else if(c->wall == waGiantRug)
;
else if(c->wall == waInvisibleFloor)
;
2017-12-29 00:10:47 +00:00
else if(c->wall == waDock)
;
2019-10-05 14:59:52 +00:00
else if(c->wall == waLadder)
;
2017-12-29 00:10:47 +00:00
else if(c->land == laDocks)
c->wall = waBoat;
else if(c->wall == waFreshGrave && bounded)
2017-03-23 10:53:57 +00:00
;
2019-05-08 16:33:08 +00:00
else if(c->wall == waBarrier && sphere && WDIM == 3)
;
2017-03-23 10:53:57 +00:00
else if(isReptile(c->wall))
c->wparam = reptilemax();
else if(c->wall == waAncientGrave && bounded)
2017-03-23 10:53:57 +00:00
;
2016-08-26 09:58:03 +00:00
else
c->wall = waNone;
if(c->land == laBrownian && c->wall == waNone && c->landparam == 0)
c->landparam = 1;
2018-12-03 22:03:35 +00:00
if(c->item != itCompass)
c->item = itNone;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(c->land == laWildWest) {
2018-10-28 01:15:11 +00:00
forCellEx(c2, c)
forCellEx(c3, c2)
if(c3->wall != waBarrier)
c3->wall = waNone;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
return true;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
int numgates = 0;
2019-08-09 19:00:52 +00:00
EX void toggleGates(cell *c, eWall type, int rad) {
2018-04-12 09:00:12 +00:00
if(!c) return;
celllister cl(c, rad, 1000000, NULL);
for(cell *ct: cl.lst) {
if(ct->wall == waOpenGate && type == waClosePlate) {
bool onWorm = false;
if(isWorm(ct)) onWorm = true;
for(int i=0; i<ct->type; i++)
if(ct->move(i) && ct->move(i)->wall == waOpenGate && isWorm(ct->move(i))) onWorm = true;
2018-04-12 09:00:12 +00:00
if(!onWorm) {
ct->wall = waClosedGate, numgates++;
if(ct->item) {
playSound(ct, "hit-crush"+pick123());
addMessage(XLAT("%The1 is crushed!", ct->item));
ct->item = itNone;
}
2018-04-12 18:52:58 +00:00
toggleGates(ct, type, 1);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
2018-04-12 18:52:58 +00:00
if(ct->wall == waClosedGate && type == waOpenPlate) {
ct->wall = waOpenGate, numgates++;
toggleGates(ct, type, 1);
}
2015-08-08 13:57:52 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void toggleGates(cell *ct, eWall type) {
2017-03-23 10:53:57 +00:00
playSound(ct, "click");
numgates = 0;
if(type == waClosePlate && PURE)
2016-08-26 09:58:03 +00:00
toggleGates(ct, type, 2);
else
toggleGates(ct, type, (GOLDBERG && !sphere && !a4) ? gp::dist_3() : 3);
2017-03-23 10:53:57 +00:00
if(numgates && type == waClosePlate)
playSound(ct, "closegate");
if(numgates && type == waOpenPlate)
playSound(ct, "opengate");
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void destroyTrapsOn(cell *c) {
2017-10-08 12:02:03 +00:00
if(c->wall == waArrowTrap) c->wall = waNone, destroyTrapsAround(c);
}
2019-08-09 19:00:52 +00:00
EX void destroyTrapsAround(cell *c) {
2017-10-08 12:02:03 +00:00
forCellEx(c2, c) destroyTrapsOn(c2);
}
2019-08-09 19:00:52 +00:00
EX void destroyWeakBranch(cell *cf, cell *ct, eMonster who) {
2016-08-26 09:58:03 +00:00
if(cf && ct && cf->wall == waWeakBranch && cellEdgeUnstable(ct) &&
2018-12-21 13:41:23 +00:00
gravityLevelDiff(ct, cf) >= 0 && !ignoresPlates(who)) {
2016-08-26 09:58:03 +00:00
cf->wall = waCanopy;
2017-03-23 10:53:57 +00:00
if(!cellEdgeUnstable(cf)) { cf->wall = waWeakBranch; return; }
playSound(cf, "trapdoor");
drawParticles(cf, winf[waWeakBranch].color, 4);
}
if(cf && ct && cf->wall == waSmallBush && cellEdgeUnstable(ct) &&
2018-12-21 13:41:23 +00:00
gravityLevelDiff(ct, cf) >= 0 && !ignoresPlates(who)) {
2017-03-23 10:53:57 +00:00
cf->wall = waNone;
if(!cellEdgeUnstable(cf)) { cf->wall = waSmallBush; return; }
playSound(cf, "trapdoor");
drawParticles(cf, winf[waWeakBranch].color, 4);
}
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool isCentralTrap(cell *c) {
2017-10-04 19:26:26 +00:00
if(c->wall != waArrowTrap) return false;
int i = 0;
forCellEx(c2, c) if(c2->wall == waArrowTrap) i++;
return i == 2;
}
2019-08-09 19:00:52 +00:00
EX array<cell*, 5> traplimits(cell *c) {
2017-10-12 09:33:26 +00:00
array<cell*, 5> res;
2017-10-04 19:26:26 +00:00
int q = 0;
2017-10-12 09:33:26 +00:00
res[2] = c;
2017-10-04 19:26:26 +00:00
for(int d=0; d<c->type; d++) {
cellwalker cw(c, d);
2018-03-24 11:59:01 +00:00
cw += wstep;
if(cw.at->wall != waArrowTrap) continue;
res[1+q*2] = cw.at;
cw += (cw.at->type/2);
if((cw.at->type&1) && (cw+wstep).at->wall != waStone) cw += 1;
2018-03-24 11:59:01 +00:00
cw += wstep;
res[(q++)*4] = cw.at;
2017-10-04 19:26:26 +00:00
}
2017-10-12 09:33:26 +00:00
while(q<2) { res[q*4] = res[1+q*2] = NULL; q++; }
2017-10-04 19:26:26 +00:00
return res;
}
2019-08-09 19:00:52 +00:00
EX void activateArrowTrap(cell *c) {
2017-09-30 09:46:41 +00:00
if(c->wall == waArrowTrap && c->wparam == 0) {
2019-01-11 01:24:37 +00:00
playSound(c, "click");
2017-10-12 09:33:26 +00:00
c->wparam = shmup::on ? 2 : 1;
2017-09-30 09:46:41 +00:00
forCellEx(c2, c) activateArrowTrap(c2);
2017-10-12 09:33:26 +00:00
if(shmup::on) shmup::activateArrow(c);
2017-09-30 09:46:41 +00:00
}
}
/** effect of moving monster m from cf to ct
* this is called from moveMonster, or separately from moveIvy/moveWorm,
* or when a dead bird falls (then m == moDeadBird)
*/
2016-01-02 10:09:13 +00:00
EX void moveEffect(const movei& mi, eMonster m) {
2016-01-02 10:09:13 +00:00
auto& cf = mi.s;
auto& ct = mi.t;
2017-03-23 10:53:57 +00:00
if(cf) destroyWeakBranch(cf, ct, m);
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
mayExplodeMine(ct, m);
if(!isNonliving(m)) terracottaAround(ct);
2017-03-23 10:53:57 +00:00
if(ct->wall == waMineUnknown && !ct->item && !ignoresPlates(m) && normal_gravity_at(ct))
2017-03-23 10:53:57 +00:00
ct->landparam |= 2; // mark as safe
2016-08-26 09:58:03 +00:00
if((ct->wall == waClosePlate || ct->wall == waOpenPlate) && !ignoresPlates(m) && normal_gravity_at(ct))
2016-08-26 09:58:03 +00:00
toggleGates(ct, ct->wall);
if(m == moDeadBird && cf == ct && cellUnstable(cf) && normal_gravity_at(ct)) {
fallingFloorAnimation(cf);
cf->wall = waChasm;
}
2017-09-30 09:46:41 +00:00
if(ct->wall == waArrowTrap && !ignoresPlates(m) && normal_gravity_at(ct))
2017-09-30 09:46:41 +00:00
activateArrowTrap(ct);
2018-12-16 23:04:59 +00:00
2019-01-11 01:24:37 +00:00
if(ct->wall == waFireTrap && !ignoresPlates(m) && ct->wparam == 0 && normal_gravity_at(ct)) {
playSound(ct, "click");
2018-12-16 23:04:59 +00:00
ct->wparam = 1;
2019-01-11 01:24:37 +00:00
}
2016-01-02 10:09:13 +00:00
if(cf && isPrincess(m)) princess::move(mi);
2016-08-26 09:58:03 +00:00
if(cf && m == moTortoise) {
tortoise::emap[ct] = tortoise::getb(cf);
2016-08-26 09:58:03 +00:00
tortoise::emap.erase(cf);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
if(cf && ct->item == itBabyTortoise && !cf->item) {
cf->item = itBabyTortoise;
ct->item = itNone;
animateMovement(mi.rev(), LAYER_BOAT);
2016-08-26 09:58:03 +00:00
tortoise::babymap[cf] = tortoise::babymap[ct];
tortoise::babymap.erase(ct);
2016-01-02 10:09:13 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void updateHi(eItem it, int v) {
2016-08-26 09:58:03 +00:00
if(!yendor::on)
if(v > hiitems[modecode()][it]) hiitems[modecode()][it] = v;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void gainItem(eItem it) {
2016-08-26 09:58:03 +00:00
int g = gold();
2019-11-03 12:56:42 +00:00
bool lhu = landUnlocked(laHell);
2016-08-26 09:58:03 +00:00
items[it]++; if(it != itLotus) updateHi(it, items[it]);
if(it == itRevolver && items[it] > 6) items[it] = 6;
2019-11-03 12:56:42 +00:00
achievement_collection(it);
2017-03-23 10:53:57 +00:00
multi::treasures[multi::cpid]++;
2018-05-26 23:06:12 +00:00
#if CAP_DAILY
if(daily::on) achievement_final(false);
#endif
2019-11-03 12:56:42 +00:00
int g2 = gold();
if(items[itFireShard] && items[itAirShard] && items[itWaterShard] && items[itEarthShard]) {
items[itFireShard]--;
items[itAirShard]--;
items[itWaterShard]--;
items[itEarthShard]--;
gainItem(itElemental);
gainItem(itElemental);
gainItem(itElemental);
gainItem(itElemental);
addMessage(XLAT("You construct some Elemental Gems!", it) + itemcounter(items[itElemental]));
}
if(it == itBounty)
items[itRevolver] = 6;
if(it == itHyperstone && items[itHyperstone] == 10)
achievement_victory(true);
if(chaosmode && gold() >= 300 && !chaosAchieved) {
achievement_gain("CHAOS", rg::chaos);
chaosAchieved = true;
}
#if ISMOBILE==1
if(g < lastsafety + R30*3/2 && g2 >= lastsafety + R30*3/2)
addMessage(XLAT("The Orb of Safety from the Land of Eternal Motion might save you."));
#endif
#define IF(x) if(g < (x) && g2 >= x && !peace::on)
IF(R60/4)
addMessage(XLAT("Collect treasure to access more different lands..."));
IF(R30)
addMessage(XLAT("You feel that you have enough treasure to access new lands!"));
IF(R30*3/2)
addMessage(XLAT("Collect more treasures, there are still more lands waiting..."));
IF(R60)
addMessage(XLAT("You feel that the stars are right, and you can access R'Lyeh!"));
IF(R30*5/2)
addMessage(XLAT("Kill monsters and collect treasures, and you may get access to Hell..."));
IF(R10 * 9)
addMessage(XLAT("To access Hell, collect %1 treasures each of 9 kinds...", its(R10)));
if(landUnlocked(laHell) && !lhu) {
addMessage(XLAT("Abandon all hope, the gates of Hell are opened!"));
addMessage(XLAT("And the Orbs of Yendor await!"));
}
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX string itemcounter(int qty) {
2017-03-23 10:53:57 +00:00
string s = ""; s += " ("; s += its(qty); s += ")"; return s;
}
2019-08-09 19:00:52 +00:00
EX void gainShard(cell *c2, const char *msg) {
2017-03-23 10:53:57 +00:00
invismove = false;
string s = XLAT(msg);
2018-08-21 13:37:59 +00:00
if(is_mirrorland(c2) && !peace::on) {
2019-11-03 12:56:42 +00:00
collectMessage(c2, itShard);
2017-03-23 10:53:57 +00:00
gainItem(itShard);
s += itemcounter(items[itShard]);
}
addMessage(s);
c2->wall = waNone;
invismove = false;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void uncoverMinesFull(cell *c2) {
int mineradius =
bounded ? 3 :
(items[itBombEgg] < 1 && !tactic::on) ? 0 :
items[itBombEgg] < 20 ? 1 :
items[itBombEgg] < 30 ? 2 :
3;
2019-03-01 00:20:14 +00:00
bool nomine = !normal_gravity_at(c2);
if(!nomine && uncoverMines(c2, mineradius, 0, true) && markOrb(itOrbAether))
nomine = true;
if(!nomine) {
uncoverMines(c2, mineradius, 0, false);
mayExplodeMine(c2, moPlayer);
}
}
2019-08-09 19:00:52 +00:00
EX void playerMoveEffects(cell *c1, cell *c2) {
2017-07-04 13:38:33 +00:00
if(peace::on) items[itOrbSword] = c2->land == laBurial ? 100 : 0;
2017-03-23 10:53:57 +00:00
sword::dir[multi::cpid] = sword::shift(c1, c2, sword::dir[multi::cpid]);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
destroyWeakBranch(c1, c2, moPlayer);
uncoverMinesFull(c2);
2016-08-26 09:58:03 +00:00
if((c2->wall == waClosePlate || c2->wall == waOpenPlate) && normal_gravity_at(c2) && !markOrb(itOrbAether))
2016-08-26 09:58:03 +00:00
toggleGates(c2, c2->wall);
if(c2->wall == waArrowTrap && c2->wparam == 0 && normal_gravity_at(c2) && !markOrb(itOrbAether))
2017-09-30 09:46:41 +00:00
activateArrowTrap(c2);
2018-12-16 23:04:59 +00:00
2019-01-11 01:24:37 +00:00
if(c2->wall == waFireTrap && c2->wparam == 0 && normal_gravity_at(c2) &&!markOrb(itOrbAether)) {
playSound(c2, "click");
2018-12-16 23:04:59 +00:00
c2->wparam = 1;
2019-01-11 01:24:37 +00:00
}
2017-09-30 09:46:41 +00:00
2016-08-26 09:58:03 +00:00
princess::playernear(c2);
2017-03-23 10:53:57 +00:00
if(c2->wall == waGlass && items[itOrbAether] > ORBBASE+1) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("Your Aether powers are drained by %the1!", c2->wall));
2017-03-23 10:53:57 +00:00
drainOrb(itOrbAether, 2);
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
if(cellUnstable(c2) && !markOrb(itOrbAether)) doesFallSound(c2);
2016-08-26 09:58:03 +00:00
if(c2->wall == waStrandedBoat && markOrb(itOrbWater))
c2->wall = waBoat;
if(c2->land == laOcean && c2->wall == waBoat && c2->landparam < 30 && markOrb(itOrbWater))
c2->landparam = 40;
if((c2->land == laHauntedWall || c2->land == laHaunted) && !hauntedWarning) {
hauntedWarning = true;
addMessage(XLAT("You become a bit nervous..."));
addMessage(XLAT("Better not to let your greed make you stray from your path."));
2017-03-23 10:53:57 +00:00
playSound(c2, "nervous");
2017-12-30 23:08:55 +00:00
}
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX void beastcrash(cell *c, cell *beast) {
2017-03-23 10:53:57 +00:00
if(c->wall == waPetrified || c->wall == waDeadTroll || c->wall == waDeadTroll2 ||
c->wall == waGargoyle) {
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->wall));
c->wall = waNone;
}
else if(c->wall == waDeadwall || c->wall == waCavewall || c->wall == waSandstone ||
c->wall == waVinePlant || c->wall == waIcewall ||
c->wall == waMirror || c->wall == waCloud || c->wall == waBigTree || c->wall ==
2018-01-05 13:18:33 +00:00
waSmallTree || c->wall == waGlass || c->wall == waClosedGate || c->wall == waStone || c->wall == waRuinWall) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->wall));
c->wall = waNone;
}
else if(cellHalfvine(c)) {
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->wall));
destroyHalfvine(c);
}
else if(c->wall == waThumperOff) {
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->wall));
c->wall = waThumperOn;
c->wparam = 100;
}
2018-12-16 23:04:59 +00:00
else if(c->wall == waExplosiveBarrel) {
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->wall));
explodeBarrel(c);
}
2018-01-05 13:18:33 +00:00
else if(isBull(c->monst) || isSwitch(c->monst)) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 crashes into %the2!", beast->monst, c->monst));
if(c->monst == moSleepBull) c->monst = moRagingBull, c->stuntime = 3;
2016-08-26 09:58:03 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void stayEffect(cell *c) {
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
if(m == moAirElemental) airmap.push_back(make_pair(c, 0));
if(m == moRagingBull && c->mondir != NODIR) {
playSound(NULL, "hit-axe"+pick123());
forCellIdEx(c2, d, c) {
bool opposite = anglestraight(c, d, c->mondir);
2017-03-23 10:53:57 +00:00
if(opposite) beastcrash(c2, c);
}
c->mondir = NODIR; c->stuntime = 3;
}
}
2019-08-09 19:00:52 +00:00
EX void makeTrollFootprints(cell *c) {
2017-03-23 10:53:57 +00:00
if(c->land != laTrollheim) return;
if(c->item == itTrollEgg && c->landparam) return;
c->landparam = turncount + 100;
}
EX void moveMonster(const movei& mi) {
auto& cf = mi.s;
auto& ct = mi.t;
2017-12-30 14:12:15 +00:00
eMonster m = cf->monst;
2017-03-23 10:53:57 +00:00
bool fri = isFriendly(cf);
2016-08-26 09:58:03 +00:00
if(isDragon(m)) {
printf("called for Dragon\n");
return;
}
if(m != moMimic) animateMovement(mi, LAYER_SMALL);
2017-03-23 10:53:57 +00:00
// the following line is necessary because otherwise plates disappear only inside the sight range
if(cellUnstable(cf) && !ignoresPlates(m)) {
fallingFloorAnimation(cf);
cf->wall = waChasm;
}
moveEffect(mi, m);
2016-08-26 09:58:03 +00:00
if(ct->wall == waCamelotMoat &&
(m == moShark || m == moCShark || m == moGreaterShark))
achievement_gain("MOATSHARK");
if(m == moTentacleGhost) {
cf->monst = moTentacletail;
m = moGhost;
}
else cf->monst = moNone;
if(ct->monst == moTentacletail && m == moGhost) {
ct->monst = moTentacleGhost;
}
else {
ct->monst = m;
if(m == moWolf) ct->monst = moWolfMoved;
2017-10-15 22:15:54 +00:00
if(m == moHunterChanging) ct->stuntime = 1;
int d =neighborId(ct, cf);
2016-08-26 09:58:03 +00:00
if(ct->monst != moTentacleGhost)
ct->mondir = d;
if(d >= 0)
ct->monmirror = cf->monmirror ^ ct->c.mirror(d);
2016-08-26 09:58:03 +00:00
}
ct->hitpoints = cf->hitpoints;
ct->stuntime = cf->stuntime;
2017-03-23 10:53:57 +00:00
2018-01-02 10:15:42 +00:00
if(isMagneticPole(m) || m == moPair) {
if(cf->mondir == 15) {
ct->monst = moPirate;
return;
}
cell *other_pole = cf->move(cf->mondir);
2017-12-30 14:12:15 +00:00
if(other_pole) {
ct->mondir = neighborId(ct, other_pole),
other_pole->mondir = neighborId(other_pole, ct);
}
}
2017-03-23 10:53:57 +00:00
if(fri || isBug(m) || items[itOrbDiscord]) stabbingAttack(cf, ct, m);
2016-08-26 09:58:03 +00:00
if(isLeader(m)) {
if(ct->wall == waBigStatue) {
ct->wall = cf->wall;
cf->wall = waBigStatue;
animateMovement(mi.rev(), LAYER_BOAT);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
moveBoatIfUsingOne(mi);
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(isTroll(m)) { makeTrollFootprints(ct); makeTrollFootprints(cf); }
int inc = incline(cf, ct);
2016-08-26 09:58:03 +00:00
if(m == moEarthElemental) {
if(!passable(ct, cf, 0)) earthFloor(ct);
earthMove(mi);
2016-08-26 09:58:03 +00:00
}
if(m == moWaterElemental) {
placeWater(ct, cf);
for(int i=0; i<ct->type; i++) {
cell *c2 = ct->move(i);
2016-08-26 09:58:03 +00:00
if(!c2) continue;
2017-03-23 10:53:57 +00:00
if(c2->wall == waBoat && !(isPlayerOn(c2) && markOrb(itOrbWater))) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 is washed away!", c2->wall, moWaterElemental));
placeWater(c2, ct);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->wall == waStrandedBoat) {
addMessage(XLAT("%The1 is washed away!", c2->wall, moWaterElemental));
c2->wall = waNone;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->wall == waDeadTroll) {
addMessage(XLAT("%The1 is washed away!", c2->wall, moWaterElemental));
c2->wall = waCavefloor;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->wall == waDeadTroll2) {
addMessage(XLAT("%The1 is washed away!", c2->wall, moWaterElemental));
c2->wall = waNone;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(isFire(c2) && c2->wall != waEternalFire) {
addMessage(XLAT("%The1 is extinguished!", c2->wall, moWaterElemental));
2017-12-29 00:10:47 +00:00
if(c2->wall == waBurningDock)
c2->wall = waDock;
else
c2->wall = waNone;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
if(shmup::on && isWatery(c2)) shmup::destroyBoats(c2);
2016-08-26 09:58:03 +00:00
}
}
if(m == moGreaterShark) for(int i=0; i<ct->type; i++) {
cell *c3 = ct->move(i);
2016-08-26 09:58:03 +00:00
if(c3 && c3->wall == waBoat)
makeflame(c3, 5, false);
}
// lancers pierce our friends :(
if(m == moLancer) {
// printf("lancer stab?\n");
forCellEx(c3, ct) if(!logical_adjacent(cf, m, c3)) {
2016-08-26 09:58:03 +00:00
if(canAttack(ct, moLancer, c3, c3->monst, AF_LANCE | AF_GETPLAYER)) {
attackMonster(c3, AF_LANCE | AF_MSG | AF_GETPLAYER, m);
2015-08-08 13:57:52 +00:00
}
// this looks the same as effect graphically as exploding right away,
// except that it does not kill the lancer
if(c3->wall == waExplosiveBarrel)
c3->wall = waFireTrap, c3->wparam = 2;
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(m == moWitchFire) makeflame(cf, 10, false);
if(m == moFireElemental) { makeflame(cf, 20, false); if(cf->wparam < 20) cf->wparam = 20; }
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
bool adj = false;
2017-03-23 10:53:57 +00:00
if(ct->cpdist == 1 && (items[itOrb37] || !nonAdjacent(cf,ct)) && markOrb(itOrbBeauty))
2016-08-26 09:58:03 +00:00
adj = true;
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(!adj && items[itOrbEmpathy] && items[itOrbBeauty]) {
for(int i=0; i<ct->type; i++) if(ct->move(i) && isFriendly(ct->move(i)))
2017-03-23 10:53:57 +00:00
adj = true, markOrb(itOrbEmpathy), markOrb(itOrbBeauty);
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
if(adj && ct->stuntime == 0 && !isMimic(m)) {
ct->stuntime = 2;
checkStunKill(ct);
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(!cellEdgeUnstable(ct)) {
if(isMetalBeast(m)) ct->stuntime += 2;
if(m == moTortoise) ct->stuntime += 3;
if(m == moDraugr && ct->land != laBurial && ct->land != laHalloween) ct->stuntime += 2;
2018-10-25 00:43:14 +00:00
if(m == moBrownBug && snakelevel(ct) < snakelevel(cf)) ct->stuntime += 2;
if(m == moBrownBug && snakelevel(ct) < snakelevel(cf) - 1) ct->stuntime += 2;
if(m == moBrownBug && isWatery(ct) && !isWatery(cf)) ct->stuntime += 2;
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if(isWitch(m) && ct->item == itOrbLife && passable(cf, NULL, P_MIRROR)) {
// note that Fire Witches don't pick up Orbs of Life,
addMessage(XLAT("%The1 picks up %the2!", moWitch, ct->item));
cf->monst = moEvilGolem; ct->item = itNone;
}
else if(m == moWitch) {
bool pickup = false;
if(ct->item == itOrbFlash)
pickup = true, m = moWitchFlash;
if(ct->item == itOrbWinter)
pickup = true, m = moWitchWinter;
2017-03-23 10:53:57 +00:00
if(ct->item == itOrbAether)
2016-08-26 09:58:03 +00:00
pickup = true, m = moWitchGhost;
if(ct->item == itOrbFire)
pickup = true, m = moWitchFire;
2017-03-23 10:53:57 +00:00
if(ct->item == itOrbSpeed)
pickup = true, m = moWitchSpeed;
2016-08-26 09:58:03 +00:00
if(ct->item == itOrbLife)
pickup = true, cf->monst = moEvilGolem;
if(pickup) {
addMessage(XLAT("%The1 picks up %the2!", moWitch, ct->item));
ct->monst = m; ct->item = itNone;
2017-03-23 10:53:57 +00:00
// speedwitches are stunned to prevent them from making a move
// immediately
if(m == moWitchSpeed) ct->stuntime = 1;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
}
if(m == moAirElemental) airmap.push_back(make_pair(ct, 0));
2017-10-10 10:42:30 +00:00
if(m == moWolf && ct->land == laVolcano) ct->monst = moLavaWolf;
if(m == moLavaWolf && isIcyLand(ct)) ct->monst = moWolfMoved;
2018-01-02 10:15:42 +00:00
if(m == moPair) ct->stuntime++;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(inc == -3 && ct->monst == moReptile)
ct->stuntime =3;
else if(inc == 2 && ct->monst == moReptile)
ct->stuntime = 2;
else if(inc == 3 && ct->monst == moReptile)
ct->stuntime = 3;
else if(inc == -3 && !survivesFall(ct->monst) && !passable(cf, ct, P_MONSTER)) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 falls!", ct->monst));
2018-01-06 21:14:40 +00:00
fallMonster(ct, AF_FALL);
2016-08-26 09:58:03 +00:00
}
if(isThorny(ct->wall) && !survivesThorns(ct->monst)) {
addMessage(XLAT("%The1 is killed by thorns!", ct->monst));
2017-03-23 10:53:57 +00:00
playSound(ct, "hit-rose");
if(isBull(ct->monst)) ct->wall = waNone;
2018-01-06 21:14:40 +00:00
fallMonster(ct, AF_CRUSH);
2017-03-23 10:53:57 +00:00
}
if(sword::at(ct) && canAttack(NULL, moPlayer, ct, m, AF_SWORD_INTO)) {
attackMonster(ct, AF_SWORD_INTO | AF_MSG, moPlayer);
2017-03-23 10:53:57 +00:00
achievement_gain("GOSWORD");
2016-08-26 09:58:03 +00:00
}
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool cannotGo(eMonster m, cell *c) {
2017-03-23 10:53:57 +00:00
if(m == moCrystalSage && (c->land != laCocytus || HEAT(c) > SAGEMELT || allPlayersInBoats()))
2016-08-26 09:58:03 +00:00
return true;
return false;
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool wantsToStay(eMonster m) {
2017-03-23 10:53:57 +00:00
return m == moCrystalSage && allPlayersInBoats();
}
2019-08-09 19:00:52 +00:00
EX bool batsAfraid(cell *c) {
2017-03-23 10:53:57 +00:00
// bats
2018-06-22 12:47:24 +00:00
for(int i=-1; i<isize(targets); i++)
2017-03-23 10:53:57 +00:00
if(c == targets[i] || isNeighbor(c, targets[i])) {
if(!targets[i]->monst && invismove) continue;
bool enear = false;
forCellEx(c, targets[i])
forCellEx(c2, c)
forCellEx(c3, c2)
if(isActiveEnemy(c3, targets[i]->monst) && c3->monst != moBat &&
passable_for(c3->monst, c2, c3, 0) &&
passable_for(c3->monst, c, c2, 0)
)
enear = true;
if(!enear) return true;
}
return false;
}
2019-08-09 19:00:52 +00:00
EX int angledist(int t, int d1, int d2) {
2017-03-23 10:53:57 +00:00
int dd = d1 - d2;
while(dd<0) dd += t;
while(dd>t/2) dd -= t;
if(dd<0) dd = -dd;
return dd;
}
2019-08-09 19:00:52 +00:00
EX int angledistButterfly(int t, int d1, int d2) {
2017-03-23 10:53:57 +00:00
int dd = d1 - d2;
while(dd<0) dd += t;
return dd;
}
2019-08-09 19:00:52 +00:00
EX int angledist(cell *c, int d1, int d2) {
2017-03-23 10:53:57 +00:00
return angledist(c->type, d1, d2);
}
2019-08-09 19:00:52 +00:00
EX bool anglestraight(cell *c, int d1, int d2) {
return angledist(c->type, d1, d2) >= c->type / 2;
}
2019-08-09 19:00:52 +00:00
EX int bulldist(cell *c) {
2017-03-23 10:53:57 +00:00
int low = 0;
forCellEx(c2, c) if(c2->cpdist < c->cpdist) low++;
return 8 * c->cpdist - low;
}
2019-08-09 19:00:52 +00:00
EX int bulldistance(cell *c, cell *d) {
2017-03-23 10:53:57 +00:00
int low = 0;
int cd = celldistance(c, d);
forCellEx(c2, c) if(celldistance(c2, d) < cd) low++;
return 8 * cd - low;
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int landheattype(cell *c) {
2017-10-10 10:42:30 +00:00
if(isIcyLand(c)) return 0;
if(c->land == laVolcano) return 2;
return 1;
}
/** for the monster at c1, evaluation of the move to c2
* @param mf what moves are allowed
*/
2019-08-09 19:00:52 +00:00
EX int moveval(cell *c1, cell *c2, int d, flagtype mf) {
2016-08-26 09:58:03 +00:00
if(!c2) return -5000;
eMonster m = c1->monst;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
// Angry Beasts can only go forward
if(m == moRagingBull && c1->mondir != NODIR && !anglestraight(c1, c1->mondir, d)) return -1700;
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
// never move against a rose
if(againstRose(c1, c2) && !ignoresSmell(m)) return -1600;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
// worms cannot attack if they cannot move
if(isWorm(m) && !passable_for(c1->monst, c2, c1, P_MONSTER)) return -1700;
if(canAttack(c1, m, c2, c2->monst, AF_GETPLAYER | mf) && !(mf & MF_NOATTACKS)) {
2017-06-18 16:51:46 +00:00
if(m == moRagingBull && c1->mondir != NODIR) return -1700;
2016-08-26 09:58:03 +00:00
if(mf & MF_MOUNT) {
if(c2 == dragon::target) return 3000;
else if(isFriendlyOrBug(c2)) return 500;
else return 2000;
2016-01-02 10:09:13 +00:00
}
2017-07-04 13:38:33 +00:00
if(isPlayerOn(c2)) return peace::on ? -1700 : 2500;
2017-07-22 23:33:27 +00:00
else if(isFriendlyOrBug(c2)) return peace::on ? -1600 : 2000;
2016-08-26 09:58:03 +00:00
else return 500;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(!passable_for(c1->monst, c2, c1, 0))
return
// never move into a wall
(passable_for(c1->monst, c2, c1, P_DEADLY)) ? -1300 :
-1700; // move impossible
2017-03-23 10:53:57 +00:00
if(slowMover(m) && nogoSlow(c2, c1)) return -1300;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(isPlayerOn(c2)) return -1700; // probably shielded
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if((mf & MF_MOUNT) && c2 == dragon::target) return 3000;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// crystal sages would die out of Cocytus
if(cannotGo(m, c2)) return -600;
// Rose Beauties keep to the Rose Garden
if(m == moRoseBeauty && c2->land != laRose) return -600;
if(wantsToStay(m)) return 750;
if((m == moRatling || m == moRatlingAvenger) && lastmovetype == lmSkip) return 650;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(m == moLancer) {
bool lancerok = true;
forCellEx(c3, c2) if(c1 != c3 && !logical_adjacent(c1, m, c3))
if(canAttack(c2, moLancer, c3, c3->monst, AF_LANCE | AF_ONLY_ENEMY))
2016-08-26 09:58:03 +00:00
lancerok = false;
if(!lancerok) return 750;
}
2016-01-02 10:09:13 +00:00
2017-10-10 10:42:30 +00:00
bool hunt = true;
if(m == moLavaWolf) {
// prefers to keep to volcano
int clht = landheattype(c1);
int dlht = landheattype(c2);
if(dlht > clht) return 1510;
if(dlht < clht) return 700;
// will not hunt the player if these rules do not allow it
bool onlava = false;
for(cell *c: targets) {
if(landheattype(c) >= clht) onlava = true;
forCellEx(cc, c) if(landheattype(cc) >= clht) onlava = true;
}
if(!onlava) hunt = false;
}
2016-08-26 09:58:03 +00:00
if(m == moWolf) {
int val = 1500;
2017-10-10 10:42:30 +00:00
if(c2->land == laVolcano) return 1510;
2016-08-26 09:58:03 +00:00
if(heat::absheat(c2) <= heat::absheat(c1))
return 900;
for(int i=0; i<c1->type; i++) {
cell *c3 = c1->move(i);
2016-08-26 09:58:03 +00:00
if(heat::absheat(c3) > heat::absheat(c2))
val--;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
return val;
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if((mf & MF_MOUNT) && dragon::target)
return 1500 + celldistance(c1, dragon::target) - celldistance(c2, dragon::target);
2017-03-23 10:53:57 +00:00
// Goblins avoid getting near the Sword
if(m == moGoblin && sword::isnear(c2)) return 790;
2017-03-23 10:53:57 +00:00
if(m == moBat && batsAfraid(c2)) return 790;
if(m == moButterfly)
return 1500 + angledistButterfly(c1->type, c1->mondir, d);
if(m == moRagingBull && c1->mondir != NODIR)
return 1500 - bulldist(c2);
2016-01-02 10:09:13 +00:00
2017-10-15 22:15:54 +00:00
// actually they just run away
if(m == moHunterChanging && c2->pathdist > c1->pathdist) return 1600;
if((mf & MF_PATHDIST) && !pathlock) printf("using MF_PATHDIST without path\n");
2018-10-25 00:43:14 +00:00
int bonus = 0;
if(m == moBrownBug && snakelevel(c2) < snakelevel(c1)) bonus = -10;
2018-10-25 00:43:14 +00:00
if(hunt && (mf & MF_PATHDIST) && c2->pathdist < c1->pathdist && !peace::on) return 1500 + bonus; // good move
2016-08-26 09:58:03 +00:00
// prefer straight direction when wandering
2017-03-23 10:53:57 +00:00
int dd = angledist(c1, c1->mondir, d);
// goblins blocked by anglophobia prefer to move around than to stay
if(m == moGoblin) {
bool swn = false;
forCellEx(c3, c1) if(sword::isnear(c3)) swn = true;
2017-03-23 10:53:57 +00:00
if(swn) dd += 210;
}
2016-08-26 09:58:03 +00:00
return 800 + dd;
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// stay value
2019-08-09 19:00:52 +00:00
EX int stayval(cell *c, flagtype mf) {
2017-03-23 10:53:57 +00:00
if(isShark(c->monst) && !isWatery(c))
return 525;
if(againstRose(c, NULL) && !ignoresSmell(c->monst)) return -1500;
2016-08-26 09:58:03 +00:00
if(!passable_for(c->monst, c, NULL, P_MONSTER | P_MIRROR))
return 525;
if(cellEdgeUnstable(c))
2017-03-23 10:53:57 +00:00
return -1500;
2016-08-26 09:58:03 +00:00
if(isRatling(c->monst) && lastmovetype != lmSkip)
return 700;
2017-03-23 10:53:57 +00:00
// Goblins avoid staying near the Sword (if there is no choice, movement is preferred)
if(c->monst == moGoblin && sword::isnear(c)) return 780;
2017-03-23 10:53:57 +00:00
// Vikings move in a roughly straight line even if they cannot detect you
if(c->monst == moViking && c->wall == waBoat)
return 750;
2017-07-04 13:38:33 +00:00
// in peaceful, all monsters are wandering
if(peace::on && c->monst != moTortoise) return 750;
2016-08-26 09:58:03 +00:00
if(isWorm(c->monst)) return 550;
2017-03-23 10:53:57 +00:00
if(c->monst == moRagingBull) return -1690; // worse than to stay in place
if(c->monst == moBat && batsAfraid(c)) return 575;
2017-09-30 09:46:41 +00:00
if(c->monst == moHunterGuard) return 1600; // prefers to stay in place
2017-10-10 10:42:30 +00:00
// Lava Wolves will wander if not hunting
if(c->monst == moLavaWolf) return 750;
2016-08-26 09:58:03 +00:00
return 1000;
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX int totalbulldistance(cell *c, int k) {
2019-05-30 14:17:17 +00:00
shpos.resize(SHSIZE);
2017-06-18 16:51:46 +00:00
int tbd = 0;
for(int p=0; p<numplayers(); p++) {
cell *c2 = shpos[p][(cshpos+SHSIZE-k-1)%SHSIZE];
if(c2) tbd += bulldistance(c, c2);
}
return tbd;
}
2019-08-09 19:00:52 +00:00
EX void determinizeBull(cell *c, int *posdir, int& nc) {
2017-06-18 16:51:46 +00:00
// determinize the Angry Beast movement:
// use the previous PC's positions as the tiebreaker
for(int k=0; k<SHSIZE && nc>1; k++) {
int pts[MAX_EDGE];
for(int d=0; d<nc; d++) pts[d] = totalbulldistance(c->cmove(posdir[d]), k);
2017-06-18 16:51:46 +00:00
int bestpts = 1000;
for(int d=0; d<nc; d++) if(pts[d] < bestpts) bestpts = pts[d];
int nc0 = 0;
for(int d=0; d<nc; d++) if(pts[d] == bestpts) posdir[nc0++] = posdir[d];
nc = nc0;
}
}
2019-08-09 19:00:52 +00:00
EX int determinizeBullPush(cellwalker bull) {
2017-06-18 16:51:46 +00:00
int nc = 2;
int dirs[2], positive;
2018-03-24 11:59:01 +00:00
bull += wstep;
cell *c2 = bull.at;
if(!(c2->type & 1)) return 1; // irrelevant
int d = c2->type / 2;
2018-03-24 11:59:01 +00:00
bull += d; dirs[0] = positive = bull.spin;
bull -= 2*d; dirs[1] = bull.spin;
2017-06-18 16:51:46 +00:00
determinizeBull(c2, dirs, nc);
if(dirs[0] == positive) return -1;
return 1;
}
int posdir[MAX_EDGE], nc;
2017-09-30 09:46:41 +00:00
2019-08-09 19:00:52 +00:00
EX int pickMoveDirection(cell *c, flagtype mf) {
2017-09-30 09:46:41 +00:00
int bestval = stayval(c, mf);
nc = 1; posdir[0] = -1;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
// printf("stayval [%p, %s]: %d\n", c, dnameof(c->monst), bestval);
for(int d=0; d<c->type; d++) {
cell *c2 = c->move(d);
2016-08-26 09:58:03 +00:00
int val = moveval(c, c2, d, mf);
// printf("[%d] %p: val=%5d pass=%d\n", d, c2, val, passable(c2,c,0));
if(val > bestval) nc = 0, bestval = val;
if(val == bestval) posdir[nc++] = d;
}
2017-03-23 10:53:57 +00:00
2017-06-18 16:51:46 +00:00
if(c->monst == moRagingBull)
determinizeBull(c, posdir, nc);
2016-08-26 09:58:03 +00:00
if(!nc) return -1;
2017-09-30 09:46:41 +00:00
return posdir[hrand(nc)];
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX int pickDownDirection(cell *c, flagtype mf) {
int downs[MAX_EDGE], qdowns = 0;
2017-03-23 10:53:57 +00:00
int bestdif = -100;
forCellIdEx(c2, i, c) {
2018-12-21 13:41:23 +00:00
if(gravityLevelDiff(c2, c) < 0 && passable_for(c->monst, c2, c, P_MIRROR) &&
2017-03-23 10:53:57 +00:00
!isPlayerOn(c2)) {
int cdif = i-c->mondir;
if(cdif < 0) cdif += c->type;
if(cdif > c->type/2) cdif = cdif - c->type;
if(cdif < 0) cdif = -2*cdif+1; else cdif = 2*cdif;
// printf("i=%d md=%d dif=%d\n", i, c->mondir, cdif);
if(c2->wall == waClosePlate || c->wall == waClosePlate)
cdif += 20;
if(cdif > bestdif) bestdif = cdif, qdowns = 0;
if(cdif == bestdif) downs[qdowns++] = i;
}
}
if(!qdowns) return -1;
return downs[hrand(qdowns)];
}
2019-08-09 19:00:52 +00:00
EX vector<int> reverse_directions(cell *c, int dir) {
2019-09-26 11:13:44 +00:00
if(PURE) return reverse_directions(c->master, dir);
int d = c->degree();
if(d & 1)
return { gmod(dir + c->type/2, c->type), gmod(dir + (c->type+1)/2, c->type) };
else
return { gmod(dir + c->type/2, c->type) };
}
EX vector<int> reverse_directions(heptagon *c, int dir) {
int d = c->degree();
switch(geometry) {
case gBinary3:
if(dir < 4) return {8};
else if(dir >= 8) return {0, 1, 2, 3};
else return {dir ^ 1};
case gHoroTris:
if(dir < 4) return {7};
else if(dir == 4) return {5, 6};
else if(dir == 5) return {6, 4};
else if(dir == 6) return {4, 5};
else return {0, 1, 2, 3};
case gHoroRec:
if(dir < 2) return {6};
else if(dir == 6) return {0, 1};
else return {dir^1};
case gKiteDart3: {
if(dir < 4) return {dir ^ 2};
if(dir >= 6) return {4, 5};
vector<int> res;
for(int i=6; i<c->type; i++) res.push_back(i);
return res;
}
case gHoroHex: {
if(dir < 6) return {12, 13};
if(dir >= 12) return {0, 1, 2, 3, 4, 5};
const int dt[] = {0,0,0,0,0,0,10,11,9,8,6,7,0,0};
return {dt[dir]};
}
default:
if(d & 1)
return { gmod(dir + c->type/2, c->type), gmod(dir + (c->type+1)/2, c->type) };
else
return { gmod(dir + c->type/2, c->type) };
}
}
#if HDR
2017-06-18 16:51:46 +00:00
template<class T>
movei determinePush(cellwalker who, int subdir, const T& valid) {
2017-12-03 19:01:30 +00:00
if(subdir != 1 && subdir != -1) {
subdir = 1;
static bool first = true;
if(first)
first = false,
addMessage("bad push: " + its(subdir));
}
2017-06-18 16:51:46 +00:00
cellwalker push = who;
2018-03-24 11:59:01 +00:00
push += wstep;
cell *c2 = push.at;
if(binarytiling) {
auto rd = reverse_directions(push.at, push.spin);
for(int i: rd) {
push.spin = i;
if(valid(push.cpeek())) return movei(push.at, push.spin);
2019-02-27 15:14:28 +00:00
}
return movei(c2, NO_SPACE);
2019-02-27 15:14:28 +00:00
}
int pd = push.at->type/2;
2018-03-24 11:59:01 +00:00
push += pd * -subdir;
push += wstep;
if(valid(push.at)) return movei(c2, (push+wstep).spin);
if(c2->type&1) {
2018-03-24 11:59:01 +00:00
push = push + wstep - subdir + wstep;
if(valid(push.at)) return movei(c2, (push+wstep).spin);
2017-06-18 16:51:46 +00:00
}
2018-12-21 13:41:23 +00:00
if(gravityLevelDiff(push.at, c2) < 0) {
2018-03-24 11:59:01 +00:00
push = push + wstep + 1 + wstep;
2018-12-21 13:41:23 +00:00
if(gravityLevelDiff(push.at, c2) < 0) {
2018-03-24 11:59:01 +00:00
push = push + wstep - 2 + wstep;
2017-06-18 16:51:46 +00:00
}
2018-12-21 13:41:23 +00:00
if(gravityLevelDiff(push.at, c2) < 0) {
2018-03-24 11:59:01 +00:00
push = push + wstep + 1 + wstep;
2017-06-18 16:51:46 +00:00
}
if(valid(push.at)) return movei(c2, (push+wstep).spin);
2017-06-18 16:51:46 +00:00
}
return movei(c2, NO_SPACE);
2017-06-18 16:51:46 +00:00
}
#endif
2017-06-18 16:51:46 +00:00
2017-03-23 10:53:57 +00:00
// Angry Beast attack
// note: this is done both before and after movement
EX void beastAttack(cell *c, bool player, bool targetdir) {
2017-03-23 10:53:57 +00:00
if(c->mondir == NODIR) return;
forCellIdEx(c2, d, c) {
bool opposite = targetdir ? (d==c->mondir) : anglestraight(c, d, c->mondir);
int flags = AF_BULL;
2017-03-23 10:53:57 +00:00
if(player) flags |= AF_GETPLAYER;
if(!opposite) flags |= AF_ONLY_FBUG;
2017-06-18 16:51:46 +00:00
if(canAttack(c, moRagingBull, c2, c2->monst, flags)) {
2017-03-23 10:53:57 +00:00
attackMonster(c2, flags | AF_MSG, moRagingBull);
2017-06-18 16:51:46 +00:00
if(c2->monst && c2->stuntime) {
cellwalker bull (c, d);
int subdir = determinizeBullPush(bull);
auto mi = determinePush(bull, subdir, [c2] (cell *c) { return passable(c, c2, P_BLOW); });
if(mi.proper())
pushMonster(mi);
2017-06-18 16:51:46 +00:00
}
}
if(c2->wall == waThumperOff) {
playSound(c2, "click");
c2->wall = waThumperOn;
c2->wparam = 100;
2017-06-18 16:51:46 +00:00
}
2018-12-16 23:04:59 +00:00
if(c2->wall == waExplosiveBarrel) {
playSound(c2, "click");
explodeBarrel(c2);
}
2017-06-18 16:51:46 +00:00
if(c2->wall == waThumperOn) {
cellwalker bull (c, d);
int subdir = determinizeBullPush(bull);
auto mi = determinePush(bull, subdir, [c2] (cell *c) { return canPushThumperOn(c, c2, c); });
if(mi.proper())
pushThumper(mi);
2017-06-18 16:51:46 +00:00
}
2017-03-23 10:53:57 +00:00
}
}
EX bool quantum;
2017-09-30 09:46:41 +00:00
2019-08-09 19:00:52 +00:00
EX cell *moveNormal(cell *c, flagtype mf) {
2016-08-26 09:58:03 +00:00
eMonster m = c->monst;
if(isPowerMonster(m) && !playerInPower()) return NULL;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
int d;
if(c->stuntime) {
2017-09-30 09:46:41 +00:00
if(cellEdgeUnstable(c, MF_STUNNED)) d = pickDownDirection(c, mf), nc = 1, posdir[0] = d;
2017-03-23 10:53:57 +00:00
else return NULL;
}
else {
// Angry Beasts attack all neighbors first
if(m == moRagingBull) beastAttack(c, true, false);
2017-03-23 10:53:57 +00:00
d = pickMoveDirection(c, mf);
}
if(d == -1) {
stayEffect(c);
return c;
}
2017-09-30 09:46:41 +00:00
if(!quantum) {
2019-11-22 17:19:22 +00:00
movei mi(c, d);
auto& c2 = mi.t;
2017-09-30 09:46:41 +00:00
if(isPlayerOn(c2)) {
2018-01-02 10:15:42 +00:00
if(m == moCrusher) {
addMessage(XLAT("%The1 raises his weapon...", m));
crush_next.push_back(c2);
c->stuntime = 7;
return c2;
}
2017-09-30 09:46:41 +00:00
killThePlayerAt(m, c2, 0);
return c2;
}
eMonster m2 = c2->monst;
2018-01-02 10:15:42 +00:00
if(m2 && m == moCrusher) {
addMessage(XLAT("%The1 raises his weapon...", m));
crush_next.push_back(c2);
c->stuntime = 7;
return c2;
}
else if(m2) {
attackMonster(c2, AF_NORMAL | AF_MSG, m);
2019-11-22 17:19:22 +00:00
animateAttack(mi, LAYER_SMALL);
2017-09-30 09:46:41 +00:00
if(m == moFlailer && m2 == moIllusion)
attackMonster(c, 0, m2);
return c2;
}
2019-11-22 17:19:22 +00:00
moveMonster(mi);
if(m == moRagingBull) beastAttack(c2, false, false);
2016-08-26 09:58:03 +00:00
return c2;
}
2017-09-30 09:46:41 +00:00
else {
bool attacking = false;
for(int i=0; i<nc; i++) {
cell *c2 = c->move(posdir[i]);
2016-01-02 10:09:13 +00:00
2017-09-30 09:46:41 +00:00
if(isPlayerOn(c2)) {
2018-01-25 16:19:50 +00:00
killThePlayerAt(m, c2, 0);
2017-09-30 09:46:41 +00:00
attacking = true;
}
else {
eMonster m2 = c2->monst;
if(m2) {
attackMonster(c2, AF_NORMAL | AF_MSG, m);
2017-09-30 09:46:41 +00:00
if(m == moFlailer && m2 == moIllusion)
attackMonster(c, 0, m2);
attacking = true;
}
}
}
if(!attacking) for(int i=0; i<nc; i++) {
2019-11-22 17:19:22 +00:00
movei mi(c, posdir[i]);
2017-09-30 09:46:41 +00:00
if(!c->monst) c->monst = m;
2019-11-22 17:19:22 +00:00
moveMonster(mi);
if(m == moRagingBull) beastAttack(mi.t, false, false);
2017-09-30 09:46:41 +00:00
}
return c->move(d);
2016-08-26 09:58:03 +00:00
}
}
2016-01-02 10:09:13 +00:00
2017-10-08 12:02:03 +00:00
// for sandworms
2019-08-09 19:00:52 +00:00
EX void explodeAround(cell *c) {
2016-08-26 09:58:03 +00:00
for(int j=0; j<c->type; j++) {
cell* c2 = c->move(j);
2016-08-26 09:58:03 +00:00
if(c2) {
if(isIcyLand(c2)) HEAT(c2) += 0.5;
2017-03-23 10:53:57 +00:00
eWall ow = c2->wall;
2016-08-26 09:58:03 +00:00
if((c2->wall == waDune || c2->wall == waIcewall ||
c2->wall == waAncientGrave || c2->wall == waFreshGrave ||
c2->wall == waColumn || c2->wall == waThumperOff || c2->wall == waThumperOn ||
(isFire(c2) && !eternalFire(c2)) ||
c2->wall == waBigTree || c2->wall == waSmallTree ||
c2->wall == waVinePlant || c2->wall == waVineHalfA || c2->wall == waVineHalfB)) {
destroyHalfvine(c2);
c2->wall = waNone;
2016-01-02 10:09:13 +00:00
}
2018-12-16 23:04:59 +00:00
if(c2->wall == waExplosiveBarrel) explodeBarrel(c2);
2016-08-26 09:58:03 +00:00
if(c2->wall == waCavewall || c2->wall == waDeadTroll) c2->wall = waCavefloor;
if(c2->wall == waDeadTroll2) c2->wall = waNone;
2017-03-23 10:53:57 +00:00
if(c2->wall == waPetrified) c2->wall = waNone;
2016-08-26 09:58:03 +00:00
if(c2->wall == waDeadfloor2) c2->wall = waDeadfloor;
if(c2->wall == waGargoyleFloor) c2->wall = waChasm;
if(c2->wall == waGargoyleBridge || c2->wall == waPetrifiedBridge) placeWater(c2, c2);
2016-08-26 09:58:03 +00:00
if(c2->wall == waRubble) c2->wall = waNone;
if(c2->wall == waPlatform) c2->wall = waNone;
2017-10-08 12:02:03 +00:00
if(c2->wall == waStone) c2->wall = waNone, destroyTrapsAround(c2);
2016-08-26 09:58:03 +00:00
if(c2->wall == waRose) c2->wall = waNone;
if(c2->wall == waRuinWall) c2->wall = waNone;
2016-08-26 09:58:03 +00:00
if(c2->wall == waLadder) c2->wall = waNone;
if(c2->wall == waGargoyle) c2->wall = waNone;
if(c2->wall == waSandstone) c2->wall = waNone;
if(c2->wall == waSaloon) c2->wall = waNone;
if(c2->wall == waDeadwall) c2->wall = waDeadfloor2;
if(c2->wall == waBigStatue) c2->wall = waNone;
if(c2->wall == waPalace || c2->wall == waOpenGate || c2->wall == waClosedGate)
c2->wall = waNone;
if(isAlch(c2) && isAlch(c))
c2->wall = c->wall;
2017-03-23 10:53:57 +00:00
if(c2->wall != ow && ow) drawParticles(c2, winf[ow].color, 16);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
}
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void killHardcorePlayer(int id, flagtype flags) {
2017-08-06 12:50:16 +00:00
charstyle& cs = getcs(id);
cell *c = playerpos(id);
if(flags & AF_FALL)
fallingMonsterAnimation(c, moPlayer);
else for(int i=0; i<6; i++) {
drawParticle(c, cs.skincolor >> 8, 100);
drawParticle(c, cs.haircolor >> 8, 125);
if(cs.charid)
drawParticle(c, cs.dresscolor >> 8, 150);
else
drawParticle(c, cs.skincolor >> 8, 150);
if(cs.charid == 3)
drawParticle(c, cs.dresscolor2 >> 8, 175);
else
drawParticle(c, cs.skincolor >> 8, 150);
drawParticle(c, cs.swordcolor >> 8, 200);
}
if(multi::players > 1 && multi::activePlayers() > 1) {
multi::leaveGame(id);
}
else {
canmove = false;
achievement_final(true);
}
}
2019-08-09 19:00:52 +00:00
EX void killThePlayer(eMonster m, int id, flagtype flags) {
2016-08-26 09:58:03 +00:00
if(markOrb(itOrbShield)) return;
if(shmup::on) {
2017-03-23 10:53:57 +00:00
multi::cpid = id;
2016-08-26 09:58:03 +00:00
shmup::killThePlayer(m);
}
2017-03-23 10:53:57 +00:00
else if(items[itOrbDomination] && playerpos(id)->monst) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 tries to dismount you!", m));
attackMonster(playerpos(id), AF_NORMAL, m);
2016-08-26 09:58:03 +00:00
useupOrb(itOrbDomination, items[itOrbDomination]/2);
}
else if(items[itOrbShell] && !(flags & AF_EAT)) {
addMessage(XLAT("%The1 attacks your shell!", m));
useupOrb(itOrbShell, 10);
2017-03-23 10:53:57 +00:00
if(items[itOrbShell] < 1) items[itOrbShell] = 1, orbused[itOrbShell] = true;
2016-08-26 09:58:03 +00:00
}
else if(hardcore) {
addMessage(XLAT("You are killed by %the1!", m));
2017-08-06 12:50:16 +00:00
killHardcorePlayer(id, flags);
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
else if(m == moLightningBolt && lastmovetype == lmAttack && isAlchAny(playerpos(id))) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You are killed by %the1!", m));
addMessage(XLAT("Don't play with slime and electricity next time, okay?"));
kills[moPlayer]++;
items[itOrbSafety] = 0;
}
2017-03-23 10:53:57 +00:00
else {
// printf("confused!\n");
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 is confused!", m));
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void killThePlayerAt(eMonster m, cell *c, flagtype flags) {
2016-08-26 09:58:03 +00:00
for(int i=0; i<numplayers(); i++)
if(playerpos(i) == c)
killThePlayer(m, i, flags);
}
2019-08-09 19:00:52 +00:00
EX void afterplayermoved() {
2019-05-27 05:17:39 +00:00
pregen();
setdist(cwt.at, 7 - getDistLimit() - genrange_bonus, NULL);
2017-03-23 10:53:57 +00:00
prairie::treasures();
if(generatingEquidistant) {
printf("Warning: generatingEquidistant set to true\n");
generatingEquidistant = false;
}
}
2019-11-22 17:48:51 +00:00
EX void mountmove(const movei& mi, bool fp) {
2018-02-27 22:43:21 +00:00
for(int i=0; i<numplayers(); i++) {
2019-11-22 17:48:51 +00:00
if(playerpos(i) == mi.s) {
animateMovement(mi, LAYER_SMALL);
if(multi::players > 1) {
multi::player[i].at = mi.t;
multi::player[i].spin = mi.rev_dir();
multi::flipped[i] = fp;
}
else {
cwt.at = mi.t;
cwt.spin = mi.rev_dir();
flipplayer = fp;
}
afterplayermoved();
2018-02-27 22:43:21 +00:00
}
2019-11-22 17:48:51 +00:00
if(lastmountpos[i] == mi.s && mi.s) {
lastmountpos[i] = mi.t;
2018-02-27 22:43:21 +00:00
}
2019-11-22 17:48:51 +00:00
else if(lastmountpos[i] == mi.t) {
2018-02-27 22:43:21 +00:00
lastmountpos[i] = NULL;
}
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
}
2019-08-09 19:00:52 +00:00
EX void moveWorm(cell *c) {
2016-08-26 09:58:03 +00:00
2018-02-27 22:43:21 +00:00
bool mounted = isMounted(c);
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(c->monst == moWormwait) { c->monst = moWorm; return; }
else if(c->monst == moTentaclewait) { c->monst = moTentacle; return; }
else if(c->monst == moTentacleEscaping) {
// explodeAround(c);
forCellEx(c2, c)
2017-03-23 10:53:57 +00:00
if(canAttack(c, c->monst, c2, c2->monst, mounted ? AF_ONLY_ENEMY : (AF_GETPLAYER | AF_ONLY_FBUG))) {
attackMonster(c2, AF_NORMAL | AF_MSG | AF_GETPLAYER, c->monst);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
cell *c2 = c;
2017-03-23 10:53:57 +00:00
vector<cell*> allcells;
2016-08-26 09:58:03 +00:00
while(c2->mondir != NODIR) {
2017-03-23 10:53:57 +00:00
allcells.push_back(c2);
c2 = c2->move(c2->mondir);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
allcells.push_back(c2);
2018-06-22 12:47:24 +00:00
for(int i=isize(allcells)-2; i>=0; i--) {
2017-03-23 10:53:57 +00:00
cell *cmt = allcells[i+1];
cell *cft = allcells[i];
2019-11-22 17:48:51 +00:00
auto mi = moveimon(cft);
2017-03-23 10:53:57 +00:00
if(cft->monst != moTentacleGhost && cmt->monst != moTentacleGhost)
2019-11-22 17:48:51 +00:00
mountmove(mi, false);
animateMovement(mi, LAYER_BIG);
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
c->monst = moNone;
if(c->mondir != NODIR) c->move(c->mondir)->monst = moTentacleEscaping;
2016-08-26 09:58:03 +00:00
return;
}
else if(c->monst != moWorm && c->monst != moTentacle) return;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
int id = m - moWorm;
2016-08-26 09:58:03 +00:00
int mf = MF_PATHDIST | AF_EAT;
2017-03-23 10:53:57 +00:00
if(mounted) mf ^= (MF_MOUNT | MF_PATHDIST);
2016-08-26 09:58:03 +00:00
2019-07-31 08:55:09 +00:00
// without this, in 3D geometries, Sandworms explode because no land around them is generated yet
forCellCM(c2, c) setdist(c2, 8, c);
2016-08-26 09:58:03 +00:00
int dir = pickMoveDirection(c, mf);
if(c->wall == waRose) {
addMessage(XLAT("%The1 eats %the2!", c->monst, c->wall));
c->wall = waNone;
dir = -1;
}
if(dir == -1) {
int spices = 0;
if(id) {
addMessage(XLAT("Cthulhu withdraws his tentacle!"));
kills[moTentacle]++;
c->monst = moTentacleEscaping;
moveWorm(c);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else {
kills[moWorm]++;
spices = 3;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
eItem loc = treasureType(c->land);
bool spiceSeen = false;
while(c->monst == moWorm || c->monst == moWormtail || c->monst == moTentacle || c->monst == moTentacletail) {
// if(!id)
explodeAround(c);
2017-03-23 10:53:57 +00:00
drawParticles(c, minf[c->monst].color, 16);
2016-08-26 09:58:03 +00:00
if(spices > 0 && c->land == laDesert) {
if(notDippingForExtra(itSpice, loc)) {
c->item = itSpice;
if(c->cpdist <= 6) spiceSeen = true;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
spices--;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
c->monst = moNone;
if(c->mondir != NODIR) c = c->move(c->mondir);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(!id) {
if(spiceSeen)
addMessage(XLAT("The sandworm explodes in a cloud of Spice!"));
else
addMessage(XLAT("The sandworm explodes!"));
2017-03-23 10:53:57 +00:00
playSound(NULL, "explosion");
2018-06-21 23:48:46 +00:00
if(geometry == gZebraQuotient)
achievement_gain("ZEBRAWORM", rg::special_geometry);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
return;
}
movei mi(c, dir);
auto& goal = mi.t;
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(isPlayerOn(goal) || goal->monst)
attackMonster(goal, AF_EAT | AF_MSG | AF_GETPLAYER, c->monst);
2016-08-26 09:58:03 +00:00
if(1) {
2016-08-26 09:58:03 +00:00
goal->monst = eMonster(moWormwait + id);
moveEffect(mi, eMonster(moWormwait + id));
2016-08-26 09:58:03 +00:00
animateMovement(mi, LAYER_BIG);
2016-08-26 09:58:03 +00:00
c->monst = eMonster(moWormtail + id);
goal->mondir = mi.rev_dir_or(NODIR);
goal->monmirror = c->monmirror ^ c->c.mirror(dir);
2016-08-26 09:58:03 +00:00
2019-11-22 17:48:51 +00:00
mountmove(mi, true);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(id) {
cell *c2 = c, *c3 = c2;
while(c2->monst == moTentacletail || c2->monst == moTentacleGhost) {
2019-11-22 17:48:51 +00:00
auto mi = moveimon(c2);
if(!mi.proper()) return;
c3 = c2, c2 = mi.t;
2017-03-23 10:53:57 +00:00
if(c3->monst != moTentacleGhost && c2->monst != moTentacleGhost)
2019-11-22 17:48:51 +00:00
mountmove(mi, true);
animateMovement(mi.rev(), LAYER_BIG);
2016-01-02 10:09:13 +00:00
}
}
2016-08-26 09:58:03 +00:00
cell *c2 = c, *c3 = c2;
2017-03-23 10:53:57 +00:00
for(int a=0; a<WORMLENGTH; a++) {
2016-08-26 09:58:03 +00:00
if(c2->monst == moWormtail) {
2019-11-22 17:48:51 +00:00
movei mim = moveimon(c2).rev();
if(!mim.proper()) {
2017-03-23 10:53:57 +00:00
drawParticles(c2, (linf[c2->land].color & 0xF0F0F0), 16);
return;
}
2019-11-22 17:48:51 +00:00
c3 = c2, c2 = mim.s;
mountmove(mim, true);
animateMovement(mim, LAYER_BIG);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(c2->monst == moWormtail) c2->monst = moNone, c3->mondir = NODIR;
}
}
2019-08-09 19:00:52 +00:00
EX void ivynext(cell *c) {
cellwalker cw(c, c->mondir, c->monmirror);
2017-03-23 10:53:57 +00:00
// check the mirroring status
cell *c2 = c;
while(true) {
if(c2->monst == moIvyRoot) break;
if(!isIvy(c2->monst)) break;
if(c2->c.mirror(c2->mondir)) cw.mirrored = !cw.mirrored;
c2 = c2->move(c2->mondir);
2017-03-23 10:53:57 +00:00
}
cw.at->monst = moIvyWait;
2016-08-26 09:58:03 +00:00
bool findleaf = false;
while(true) {
2018-03-24 11:59:01 +00:00
cw += 1;
if(cw.spin == signed(cw.at->mondir)) {
2016-08-26 09:58:03 +00:00
if(findleaf) {
cw.at->monst = moIvyHead; break;
2015-08-08 13:57:52 +00:00
}
cw.at->monst = moIvyWait;
2018-03-24 11:59:01 +00:00
cw += wstep;
2016-08-26 09:58:03 +00:00
continue;
}
2018-03-24 11:59:01 +00:00
cw += wstep;
if(cw.at->monst == moIvyWait && signed(cw.at->mondir) == cw.spin) {
cw.at->monst = moIvyBranch;
2016-08-26 09:58:03 +00:00
findleaf = true; continue;
2015-08-08 13:57:52 +00:00
}
2018-03-24 11:59:01 +00:00
cw += wstep;
2015-08-08 13:57:52 +00:00
}
}
2016-08-26 09:58:03 +00:00
// this removes Ivy, but also potentially causes Vines to grow
2019-08-09 19:00:52 +00:00
EX void removeIvy(cell *c) {
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
2016-08-26 09:58:03 +00:00
c->monst = moNone; // NEWYEARFIX
for(int i=0; i<c->type; i++)
// note that semi-vines don't count
if(c->move(i)->wall == waVinePlant) {
2016-08-26 09:58:03 +00:00
destroyHalfvine(c);
c->wall = waVinePlant;
}
2017-03-23 10:53:57 +00:00
if(c->wall != waVinePlant) {
if(m == moIvyDead)
m = moIvyWait;
drawParticles(c, minf[m].color, 2);
}
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void moveivy() {
2018-06-22 12:47:24 +00:00
if(isize(ivies) == 0) return;
2018-11-24 00:30:05 +00:00
if(racing::on) return;
pathdata pd(moIvyRoot);
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(ivies); i++) {
2016-08-26 09:58:03 +00:00
cell *c = ivies[i];
cell *co = c;
if(c->monst != moIvyHead) continue;
ivynext(c);
int pd = c->pathdist;
movei mi(nullptr, nullptr, NODIR);
2016-08-26 09:58:03 +00:00
while(c->monst != moIvyRoot) {
if(!isIvy(c->monst)) {
raiseBuggyGeneration(c, "that's not an Ivy!");
}
if(c->mondir == NODIR)
raiseBuggyGeneration(c, "wrong mondir!");
forCellIdEx(c2, j, c) {
if(canAttack(c, c->monst, c2, c2->monst, AF_ONLY_FRIEND | AF_GETPLAYER)) {
if(isPlayerOn(c2))
killThePlayerAt(c->monst, c2, 0);
2016-08-26 09:58:03 +00:00
else {
if(attackJustStuns(c2, 0, c->monst))
addMessage(XLAT("The ivy attacks %the1!", c2->monst));
else if(isNonliving(c2->monst))
addMessage(XLAT("The ivy destroys %the1!", c2->monst));
2016-08-26 09:58:03 +00:00
else
addMessage(XLAT("The ivy kills %the1!", c2->monst));
attackMonster(c2, AF_NORMAL, c->monst);
2016-08-26 09:58:03 +00:00
}
continue;
2015-08-08 13:57:52 +00:00
}
if(c2 && c2->pathdist < pd && passable(c2, c, 0) && !strictlyAgainstGravity(c2, c, false, MF_IVY))
mi = movei(c, j), pd = c2->pathdist;
2015-08-08 13:57:52 +00:00
}
c = c->move(c->mondir);
2015-08-08 13:57:52 +00:00
}
auto& mto = mi.t;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(mto && mto->cpdist) {
animateMovement(mi, LAYER_BIG);
mto->monst = moIvyWait, mto->mondir = mi.rev_dir_or(NODIR);
mto->monmirror = mi.s->monmirror ^ mi.mirror();
moveEffect(mi, moIvyWait);
2016-08-26 09:58:03 +00:00
// if this is the only branch, we want to move the head immediately to mto instead
if(mi.s->monst == moIvyHead) {
2016-08-26 09:58:03 +00:00
mto->monst = moIvyHead; co->monst = moIvyBranch;
2015-08-08 13:57:52 +00:00
}
}
else if(co->move(co->mondir)->monst != moIvyRoot) {
2016-08-26 09:58:03 +00:00
// shrink useless branches, but do not remove them completely (at the root)
if(co->monst == moIvyHead) co->move(co->mondir)->monst = moIvyHead;
2016-08-26 09:58:03 +00:00
removeIvy(co);
}
2015-08-08 13:57:52 +00:00
}
}
EX bool earthMove(const movei& mi) {
auto& from = mi.s;
2016-08-26 09:58:03 +00:00
bool b = false;
cell *c2 = mi.t;
2016-08-26 09:58:03 +00:00
b |= earthWall(from);
if(!mi.proper()) return b;
int d = mi.rev_dir_or(0);
2016-08-26 09:58:03 +00:00
if(c2) for(int u=2; u<=c2->type-2; u++) {
cell *c3 = c2->modmove(d + u);
2016-08-26 09:58:03 +00:00
if(c3) b |= earthFloor(c3);
}
return b;
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
vector<cell*> gendfs;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
int targetcount;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool isTargetOrAdjacent(cell *c) {
2017-03-23 10:53:57 +00:00
for(int i=0; i<targetcount; i++)
if(gendfs[i] == c || isNeighbor(gendfs[i], c))
return true;
return false;
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
EX void groupmove2(const movei& mi, eMonster movtype, flagtype mf) {
auto& c = mi.s;
auto& from = mi.t; // note: we are moving from 'c' to 'from'!'
2016-08-26 09:58:03 +00:00
if(!c) return;
2017-03-23 10:53:57 +00:00
if(c->pathdist == 0) return;
2017-03-23 10:53:57 +00:00
if(movtype == moKrakenH && isTargetOrAdjacent(from)) ;
/* else if(passable_for(movtype, from, c, P_ONPLAYER | P_CHAIN | P_MONSTER)) ;
else if(canAttack(c, movtype, from, from->monst, AF_GETPLAYER)) ; */
else if(from->wall == waThumperOn) ;
2017-03-23 10:53:57 +00:00
else if(passable_for(movtype, from, c, P_CHAIN | P_MONSTER)) ;
else if(canAttack(c, movtype, from, from->monst, AF_GETPLAYER | AF_NOSHIELD)) ;
2018-01-02 10:15:42 +00:00
else if(isMagneticPole(movtype)) {
// a special case here -- we have to ignore the illegality of
// the 'second' move due to an adjacent opposite pole
forCellIdEx(c2, d, c)
if(c2->monst == movtype) {
cell *c3 = c2->move(c2->mondir);
2018-01-02 10:15:42 +00:00
eMonster m2 = c3->monst;
c3->monst = moNone;
bool ok =
passable_for(movtype, from, c, P_CHAIN | P_MONSTER)
&& passable_for(movtype, c, c2, P_CHAIN | P_MONSTER);
c3->monst = m2;
if(ok) groupmove2(movei(c, d).rev(), movtype, mf);
2018-01-02 10:15:42 +00:00
}
}
2017-03-23 10:53:57 +00:00
else return;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(from->monst) {
if(mf & MF_MOUNT) {
// don't go through friends
if(isFriendlyOrBug(from)) return;
}
else {
// go through the player (even mounted)
2017-03-23 10:53:57 +00:00
if(isPlayerOn(from)) ;
2016-08-26 09:58:03 +00:00
// go through the mounted dragon
else if(isDragon(from->monst) && isFriendlyOrBug(from)) ;
// but not through other worms
else if(isWorm(from)) return;
// go through other friends
else if(isFriendlyOrBug(from)) ;
else return;
}
}
2017-03-23 10:53:57 +00:00
// Kraken movement
if(movtype == moKrakenH && c->monst == moKrakenT && c->stuntime == 0)
kraken::trymove(c);
2018-01-02 10:15:42 +00:00
if(movegroup(c->monst) == movtype) {
2016-08-26 09:58:03 +00:00
int af = AF_ONLY_FBUG | AF_GETPLAYER;
if(mf & MF_MOUNT) af = 0;
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(!passable_for(movtype, from, c, P_ONPLAYER | P_MONSTER)) return;
if(!ignoresSmell(c->monst) && againstRose(c, from)) return;
2017-07-22 23:33:27 +00:00
if((mf & MF_ONLYEAGLE) && c->monst != moEagle && c->monst != moBat)
return;
if((mf & MF_ONLYEAGLE) && bird_disruption(c) && markOrb(itOrbGravity)) return;
2017-03-23 10:53:57 +00:00
// in the gravity lands, eagles cannot ascend in their second move
2018-12-21 13:41:23 +00:00
if((mf & MF_ONLYEAGLE) && gravityLevelDiff(c, from) < 0) {
onpath(c, 0);
return;
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if((mf & MF_NOFRIEND) && isFriendly(c)) return;
2017-03-23 10:53:57 +00:00
if((mf & MF_MOUNT) && !isMounted(c)) return;
2016-08-26 09:58:03 +00:00
if(isRatling(c->monst) && lastmovetype == lmSkip) return;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(c->stuntime) return;
2017-03-23 10:53:57 +00:00
if(c->monst == moBat && batsAfraid(from)) return;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// note: move from 'c' to 'from'!
if(!(mf & MF_NOATTACKS)) for(int j=0; j<c->type; j++)
if(c->move(j) && canAttack(c, c->monst, c->move(j), c->move(j)->monst, af)) {
attackMonster(c->move(j), AF_NORMAL | AF_GETPLAYER | AF_MSG, c->monst);
2019-11-22 15:46:25 +00:00
animateAttack(movei(c, j), LAYER_SMALL);
onpath(c, 0);
2016-08-26 09:58:03 +00:00
// XLATC eagle
return;
}
2016-01-02 10:09:13 +00:00
if(from->cpdist == 0 || from->monst) { onpath(c, 0); return; }
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(movtype == moDragonHead) {
dragon::move(mi);
2016-08-26 09:58:03 +00:00
return;
}
2017-03-23 10:53:57 +00:00
moveMonster(mi);
onpath(from, 0);
2016-01-02 10:09:13 +00:00
}
onpath(c, 0);
2016-08-26 09:58:03 +00:00
// MAXGCELL
2018-06-22 12:47:24 +00:00
if(isize(gendfs) < 1000 || c->cpdist <= 6) gendfs.push_back(c);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void groupmove(eMonster movtype, flagtype mf) {
pathdata pd(0);
2016-08-26 09:58:03 +00:00
gendfs.clear();
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(mf & MF_MOUNT) {
if(dragon::target) gendfs.push_back(dragon::target);
if(movtype == moDragonHead) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(dcal); i++) {
2016-08-26 09:58:03 +00:00
cell *c = (i == 0 && dragon::target) ? dragon::target : dcal[i];
if(!c->monst) continue;
if(isFriendlyOrBug(c)) continue;
2017-03-23 10:53:57 +00:00
forCellIdEx(c2, d, c) if(c2->monst && isMounted(c2)) {
groupmove2(movei(c,d).rev(),movtype,mf);
2016-08-26 09:58:03 +00:00
}
}
}
}
else {
2018-06-22 12:47:24 +00:00
if(!peace::on) for(int i=0; i<isize(targets); i++) gendfs.push_back(targets[i]);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(invisfish && (movtype == moSlime || movtype == moShark || movtype == moKrakenH)) for(int i=0; i<numplayers(); i++) {
2016-08-26 09:58:03 +00:00
cell *c = playerpos(i);
2017-03-23 10:53:57 +00:00
if(!c) continue;
2016-08-26 09:58:03 +00:00
gendfs.push_back(c);
}
}
2018-06-22 12:47:24 +00:00
targetcount = isize(gendfs);
2017-03-23 10:53:57 +00:00
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(gendfs); i++) {
2016-08-26 09:58:03 +00:00
cell *c = gendfs[i];
int dirtable[MAX_EDGE], qdirtable=0;
2017-03-23 10:53:57 +00:00
forCellIdAll(c2,t,c) dirtable[qdirtable++] = t;
hrandom_shuffle(dirtable, qdirtable);
2017-03-23 10:53:57 +00:00
while(qdirtable--) {
int t = dirtable[qdirtable];
groupmove2(movei(c, t).rev(),movtype,mf);
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if(movtype == moEagle && c->monst == moNone && !isPlayerOn(c) && !bird_disruption(c)) {
2016-08-26 09:58:03 +00:00
cell *c2 = whirlwind::jumpFromWhereTo(c, false);
groupmove2(movei(c2, c, STRONGWIND), movtype, mf);
2016-08-26 09:58:03 +00:00
}
}
2018-06-22 12:47:24 +00:00
if(movtype != moDragonHead) for(int i=0; i<isize(dcal); i++) {
2016-08-26 09:58:03 +00:00
cell *c = dcal[i];
2017-03-23 10:53:57 +00:00
if((mf & MF_ONLYEAGLE) && c->monst != moEagle && c->monst != moBat) return;
if(movegroup(c->monst) == movtype && c->pathdist != 0) {
2016-08-26 09:58:03 +00:00
cell *c2 = moveNormal(c, mf);
2018-06-29 10:29:23 +00:00
if(c2) onpath(c2, 0);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
}
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
// Hex monsters
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
vector<cell*> hexdfs;
EX void moveHexSnake(const movei& mi, bool mounted) {
// note: move from 'c' to 'from'!
auto& from = mi.t;
auto& c = mi.s;
2016-08-26 09:58:03 +00:00
if(from->wall == waBoat) from->wall = waSea;
moveEffect(mi, c->monst);
from->monst = c->monst; from->mondir = mi.rev_dir_or(NODIR); from->hitpoints = c->hitpoints;
2016-08-26 09:58:03 +00:00
c->monst = moHexSnakeTail;
2017-03-23 10:53:57 +00:00
preventbarriers(from);
animateMovement(mi, LAYER_BIG);
2019-11-22 17:48:51 +00:00
mountmove(mi, true);
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
cell *c2 = c, *c3=c2;
for(int a=0;; a++) if(c2->monst == moHexSnakeTail) {
if(a == ROCKSNAKELENGTH) { c2->monst = moNone, c3->mondir = NODIR; break; }
2019-11-22 17:48:51 +00:00
auto mim = moveimon(c2).rev();
if(!mim.proper()) break;
mountmove(mim, true);
animateMovement(mim, LAYER_BIG);
c3 = c2, c2 = mim.s;
2016-08-26 09:58:03 +00:00
}
else break;
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void snakeAttack(cell *c, bool mounted) {
2016-08-26 09:58:03 +00:00
for(int j=0; j<c->type; j++)
if(c->move(j) && canAttack(c, moHexSnake, c->move(j), c->move(j)->monst,
2016-08-26 09:58:03 +00:00
mounted ? AF_ONLY_ENEMY : (AF_ONLY_FBUG | AF_GETPLAYER))) {
eMonster m2 = c->move(j)->monst;
attackMonster(c->move(j), AF_NORMAL | AF_GETPLAYER | AF_MSG, moHexSnake);
produceGhost(c->move(j), moHexSnake, m2);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool goodmount(cell *c, bool mounted) {
2017-03-23 10:53:57 +00:00
if(mounted) return isMounted(c);
else return !isMounted(c);
2016-08-26 09:58:03 +00:00
}
2019-08-09 19:00:52 +00:00
EX int inpair(cell *c, int colorpair) {
2017-12-05 18:43:45 +00:00
return (colorpair >> pattern_threecolor(c)) & 1;
}
2019-08-09 19:00:52 +00:00
EX int snake_pair(cell *c) {
2018-01-11 22:16:50 +00:00
if(c->mondir == NODIR)
return (1 << pattern_threecolor(c));
else
return (1 << pattern_threecolor(c)) | (1 << pattern_threecolor(c->move(c->mondir)));
2017-12-05 18:43:45 +00:00
}
2016-08-26 09:58:03 +00:00
// note: move from 'c' to 'from'!
2019-08-09 19:00:52 +00:00
EX void hexvisit(cell *c, cell *from, int d, bool mounted, int colorpair) {
2016-08-26 09:58:03 +00:00
if(!c) return;
if(cellUnstable(c) || cellEdgeUnstable(c)) return;
if(c->pathdist == 0) return;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(cellUnstableOrChasm(c) || cellUnstableOrChasm(from)) return;
/* if(c->monst == moHexSnake)
printf("%p:%p %s %d\n", from, c, dnameof(from->monst), passable(from, c, true, false, false)); */
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(from->cpdist && (!passable(from, c, P_MONSTER|P_WIND|P_FISH))) return;
2015-08-08 13:57:52 +00:00
2017-12-05 18:43:45 +00:00
if(c->monst == moHexSnake && snake_pair(c) == colorpair) {
2016-08-26 09:58:03 +00:00
// printf("got snake\n");
2017-12-05 18:43:45 +00:00
if(!inpair(from, colorpair)) return;
2016-08-26 09:58:03 +00:00
if(!goodmount(c, mounted)) return;
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(canAttack(c, moHexSnake, from, from->monst, AF_EAT | (mounted ? AF_ONLY_ENEMY : AF_ONLY_FBUG | AF_GETPLAYER))) {
2017-03-23 10:53:57 +00:00
attackMonster(from, AF_MSG | AF_EAT | AF_GETPLAYER, c->monst);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(from->cpdist == 0 || from->monst) return;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
snakeAttack(c, mounted);
moveHexSnake(movei(from, d).rev(), mounted);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
onpath(c, 0);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// MAXGCELL
2018-06-22 12:47:24 +00:00
if(isize(hexdfs) < 2000 || c->cpdist <= 6)
2016-08-26 09:58:03 +00:00
hexdfs.push_back(c);
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void movehex(bool mounted, int colorpair) {
2018-06-28 12:56:12 +00:00
pathdata pd(3);
2016-08-26 09:58:03 +00:00
hexdfs.clear();
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(mounted) {
if(dragon::target && dragon::target->monst != moHexSnake) {
hexdfs.push_back(dragon::target);
onpath(dragon::target, 0);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
else for(cell *c: targets) {
hexdfs.push_back(c);
onpath(c, 0);
2015-08-08 13:57:52 +00:00
}
//hexdfs.push_back(cwt.at);
2015-08-08 13:57:52 +00:00
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(hexdfs); i++) {
2016-08-26 09:58:03 +00:00
cell *c = hexdfs[i];
int dirtable[MAX_EDGE], qdirtable=0;
for(int t=0; t<c->type; t++) if(c->move(t) && inpair(c->move(t), colorpair))
2017-03-23 10:53:57 +00:00
dirtable[qdirtable++] = t;
hrandom_shuffle(dirtable, qdirtable);
2017-03-23 10:53:57 +00:00
while(qdirtable--) {
int t = dirtable[qdirtable];
hexvisit(c->move(t), c, t, mounted, colorpair);
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void movehex_rest(bool mounted) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(hexsnakes); i++) {
2016-08-26 09:58:03 +00:00
cell *c = hexsnakes[i];
int colorpair;
if(c->monst == moHexSnake) {
colorpair = snake_pair(c);
2016-08-26 09:58:03 +00:00
if(!goodmount(c, mounted)) continue;
2017-10-27 18:07:58 +00:00
int t[MAX_EDGE];
2016-08-26 09:58:03 +00:00
for(int i=0; i<c->type; i++) t[i] = i;
for(int j=1; j<c->type; j++) swap(t[j], t[hrand(j+1)]);
for(int u=0; u<c->type; u++) {
createMov(c, t[u]);
if(inpair(c->move(t[u]), colorpair))
hexvisit(c, c->move(t[u]), c->c.spin(t[u]), mounted, colorpair);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
if(c->monst == moHexSnake) {
2016-08-26 09:58:03 +00:00
snakeAttack(c, mounted);
kills[moHexSnake]++;
2017-03-23 10:53:57 +00:00
playSound(c, "die-troll");
2016-08-26 09:58:03 +00:00
cell *c2 = c;
while(c2->monst == moHexSnakeTail || c2->monst == moHexSnake) {
if(c2->monst != moHexSnake && c2->mondir != NODIR)
snakepile(c2, moHexSnake);
snakepile(c2, moHexSnake);
c2->monst = moNone;
if(c2->mondir == NODIR) break;
c2 = c2->move(c2->mondir);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
}
2016-08-26 09:58:03 +00:00
}
2019-08-09 19:00:52 +00:00
EX void movemutant() {
2016-08-26 09:58:03 +00:00
vector<cell*> young;
2018-04-14 08:24:02 +00:00
for(cell *c: currentmap->allcells())
if(c->monst == moMutant && c->stuntime == mutantphase)
young.push_back(c);
2015-08-08 13:57:52 +00:00
2018-06-22 12:47:24 +00:00
for(int j=1; j<isize(young); j++)
2016-08-26 09:58:03 +00:00
swap(young[j], young[hrand(j+1)]);
mutantphase++;
mutantphase &= 15;
2015-08-08 13:57:52 +00:00
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(young); i++) {
2016-08-26 09:58:03 +00:00
cell *c = young[i];
if(clearing::buggyplant) { if(c->monst == moMutant) c->monst=moNone; continue; }
for(int j=0; j<c->type; j++) {
2019-11-22 17:48:51 +00:00
movei mi(c, j);
auto& c2 = mi.t;
2016-08-26 09:58:03 +00:00
if(!c2) continue;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(c2->monst != moMutant && canAttack(c, moMutant, c2, c2->monst, AF_ONLY_FBUG | AF_GETPLAYER)) {
attackMonster(c2, AF_NORMAL | AF_MSG | AF_GETPLAYER, moMutant);
2016-08-26 09:58:03 +00:00
continue;
}
if(isPlayerOn(c2)) continue;
if((c2->land == laOvergrown || !pseudohept(c2)) && passable(c2, c, 0)) {
2018-04-14 08:24:02 +00:00
if(c2->land == laClearing && !bounded && c2->mpdist > 7) continue;
2016-08-26 09:58:03 +00:00
c2->monst = moMutant;
c2->mondir = c->c.spin(j);
2016-08-26 09:58:03 +00:00
c2->stuntime = mutantphase;
2019-11-22 17:48:51 +00:00
animateMovement(mi, LAYER_BIG);
2016-01-02 10:09:13 +00:00
}
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
2019-08-10 08:57:14 +00:00
#if HDR
#define SHSIZE 16
#endif
2019-08-09 20:07:03 +00:00
EX vector<array<cell*, MAXPLAYER>> shpos;
EX int cshpos = 0;
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX cell *lastmountpos[MAXPLAYER];
2018-02-27 22:43:21 +00:00
2019-08-09 19:00:52 +00:00
EX void clearshadow() {
2019-05-30 14:17:17 +00:00
shpos.resize(SHSIZE);
2017-03-23 10:53:57 +00:00
for(int i=0; i<SHSIZE; i++) for(int p=0; p<MAXPLAYER; p++)
shpos[p][i] = NULL;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void moveshadow() {
2017-03-23 10:53:57 +00:00
cell *shfrom = NULL;
2019-05-30 14:17:17 +00:00
shpos.resize(SHSIZE);
2017-03-23 10:53:57 +00:00
for(int p=0; p<numplayers(); p++) {
cell *c = shpos[p][cshpos];
if(c && c->monst == moShadow) {
for(int j=0; j<c->type; j++)
if(c->move(j) && canAttack(c, moShadow, c->move(j), c->move(j)->monst, AF_ONLY_FBUG | AF_GETPLAYER))
attackMonster(c->move(j), AF_NORMAL | AF_MSG | AF_GETPLAYER, c->monst);
2017-03-23 10:53:57 +00:00
c->monst = moNone;
shfrom = c;
}
shpos[p][cshpos] = playerpos(p);
}
2016-08-26 09:58:03 +00:00
cshpos = (cshpos+1) % SHSIZE;
2017-03-23 10:53:57 +00:00
for(int p=0; p<numplayers(); p++) {
cell* where = shpos[p][cshpos];
if(where && where->monst == moNone && where->cpdist && where->land == laGraveyard &&
!sword::at(where)) {
2019-11-22 17:48:51 +00:00
if(shfrom) animateMovement(match(shfrom, where), LAYER_SMALL);
2017-03-23 10:53:57 +00:00
where->monst = moShadow;
where->hitpoints = p;
where->stuntime = 0;
// the Shadow sets off the mines
mayExplodeMine(where, moShadow);
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void moveghosts() {
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(invismove) return;
2019-03-02 23:43:31 +00:00
for(int d=0; d<=MAX_EDGE; d++) movesofgood[d].clear();
2016-01-02 10:09:13 +00:00
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(ghosts); i++) {
2016-08-26 09:58:03 +00:00
cell *c = ghosts[i];
2016-01-02 10:09:13 +00:00
if(c->stuntime) continue;
if(isPowerMonster(c) && !playerInPower()) continue;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(isGhostMover(c->monst)) {
int goodmoves = 0;
for(int k=0; k<c->type; k++) if(c->move(k) && c->move(k)->cpdist < c->cpdist)
if(ghostmove(c->monst, c->move(k), c) && !isPlayerOn(c->move(k)))
2016-08-26 09:58:03 +00:00
goodmoves++;
movesofgood[goodmoves].push_back(c);
}
2016-01-02 10:09:13 +00:00
}
2019-03-02 23:43:31 +00:00
for(int d=0; d<=MAX_EDGE; d++) for(int i=0; i<isize(movesofgood[d]); i++) {
2016-08-26 09:58:03 +00:00
cell *c = movesofgood[d][i];
if(c->stuntime) continue;
if(isPowerMonster(c) && !playerInPower()) continue;
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(isGhostMover(c->monst) && c->cpdist >= 1) {
2016-08-26 09:58:03 +00:00
2017-10-27 18:07:58 +00:00
int mdir[MAX_EDGE];
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int j=0; j<c->type; j++)
if(c->move(j) && canAttack(c, c->monst, c->move(j), c->move(j)->monst, AF_GETPLAYER | AF_ONLY_FBUG)) {
2016-08-26 09:58:03 +00:00
// XLATC ghost/greater shark
attackMonster(c->move(j), AF_NORMAL | AF_MSG | AF_GETPLAYER, c->monst);
2017-03-23 10:53:57 +00:00
goto nextghost;
2016-08-26 09:58:03 +00:00
}
int qmpos = 0;
for(int k=0; k<c->type; k++) if(c->move(k) && c->move(k)->cpdist < c->cpdist)
if(ghostmove(c->monst, c->move(k), c))
2016-08-26 09:58:03 +00:00
mdir[qmpos++] = k;
if(!qmpos) continue;
int d = mdir[hrand(qmpos)];
cell *c2 = c->move(d);
2016-08-26 09:58:03 +00:00
if(c2->monst == moTortoise && c2->stuntime > 1) {
addMessage(XLAT("%The1 scares %the2 a bit!", c->monst, c2->monst));
c2->stuntime = 1;
}
2019-11-22 17:19:22 +00:00
else moveMonster(movei(c, d));
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
nextghost: ;
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
int lastdouble = -3;
2019-08-09 19:00:52 +00:00
EX void produceGhost(cell *c, eMonster victim, eMonster who) {
2016-08-26 09:58:03 +00:00
if(who != moPlayer && !items[itOrbEmpathy]) return;
if(markOrb(itOrbUndeath) && !c->monst && isGhostable(victim)) {
c->monst = moFriendlyGhost, c->stuntime = 0;
if(who != moPlayer) markOrb(itOrbEmpathy);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX bool swordAttack(cell *mt, eMonster who, cell *c, int bb) {
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
if(c->wall == waCavewall) markOrb(bb ? itOrbSword2: itOrbSword);
if(c->wall == waSmallTree || c->wall == waBigTree || c->wall == waRose || c->wall == waCTree || c->wall == waVinePlant ||
2017-06-09 01:41:33 +00:00
thruVine(mt, c) || c->wall == waBigBush || c->wall == waSmallBush || c->wall == waSolidBranch || c->wall == waWeakBranch) {
2017-03-23 10:53:57 +00:00
playSound(NULL, "hit-axe"+pick123());
markOrb(bb ? itOrbSword2: itOrbSword);
drawParticles(c, winf[c->wall].color, 16);
addMessage(XLAT("You chop down %the1.", c->wall));
destroyHalfvine(c);
c->wall = waNone;
}
if(c->wall == waBarrowDig) {
playSound(NULL, "hit-axe"+pick123());
markOrb(bb ? itOrbSword2: itOrbSword);
drawParticles(c, winf[c->wall].color, 16);
c->wall = waNone;
}
if(c->wall == waBarrowWall && items[itBarrow] >= 25) {
playSound(NULL, "hit-axe"+pick123());
markOrb(bb ? itOrbSword2: itOrbSword);
drawParticles(c, winf[c->wall].color, 16);
c->wall = waNone;
}
if(c->wall == waExplosiveBarrel)
explodeBarrel(c);
2017-07-24 22:21:36 +00:00
if(!peace::on && canAttack(mt, who, c, m, AF_SWORD)) {
2017-03-23 10:53:57 +00:00
markOrb(bb ? itOrbSword2: itOrbSword);
int k = tkills();
attackMonster(c, AF_NORMAL | AF_MSG | AF_SWORD, who);
2017-03-23 10:53:57 +00:00
if(c->monst == moShadow) c->monst = moNone;
produceGhost(c, m, who);
if(tkills() > k) return true;
}
return false;
}
2019-08-09 19:00:52 +00:00
EX void swordAttackStatic(int bb) {
swordAttack(cwt.at, moPlayer, sword::pos(multi::cpid, bb), bb);
}
2019-08-09 19:00:52 +00:00
EX void swordAttackStatic() {
2017-03-23 10:53:57 +00:00
for(int bb = 0; bb < 2; bb++)
if(sword::orbcount(bb))
swordAttackStatic(bb);
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX void sideAttack(cell *mf, int dir, eMonster who, int bonus, eItem orb) {
2017-09-30 09:46:41 +00:00
if(!items[orb]) return;
if(who != moPlayer && !items[itOrbEmpathy]) return;
for(int k: {-1, 1}) {
2019-08-09 12:29:08 +00:00
cell *mt = mf->modmove(dir + k*bonus);
2017-09-30 09:46:41 +00:00
eMonster m = mt->monst;
2018-01-03 21:33:03 +00:00
flagtype f = AF_SIDE;
if(items[itOrbSlaying]) f|= AF_CRUSH;
if(canAttack(mf, who, mt, m, f)) {
if((f & AF_CRUSH) && !canAttack(mf, who, mt, m, AF_SIDE | AF_MUSTKILL))
markOrb(itOrbSlaying);
2017-09-30 09:46:41 +00:00
markOrb(orb);
if(who != moPlayer) markOrb(itOrbEmpathy);
if(attackMonster(mt, AF_NORMAL | AF_SIDE | AF_MSG, who))
2017-09-30 09:46:41 +00:00
produceGhost(mt, m, who);
}
else if(mt->wall == waBigTree)
mt->wall = waSmallTree;
else if(mt->wall == waSmallTree)
mt->wall = waNone;
else if(mt->wall == waExplosiveBarrel)
explodeBarrel(mt);
2017-09-30 09:46:41 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void sideAttack(cell *mf, int dir, eMonster who, int bonuskill) {
2017-09-30 09:46:41 +00:00
int k = tkills();
sideAttack(mf, dir, who, 1, itOrbSide1);
sideAttack(mf, dir, who, 2, itOrbSide2);
sideAttack(mf, dir, who, 3, itOrbSide3);
if(who == moPlayer) {
int kills = tkills() - k + bonuskill;
if(kills >= 5) achievement_gain("MELEE5");
}
2017-09-30 09:46:41 +00:00
}
template<class T> void do_swords(cell *mf, cell *mt, eMonster who, const T& f) {
2017-03-23 10:53:57 +00:00
for(int bb=0; bb<2; bb++) if(who == moPlayer && sword::orbcount(bb)) {
cell *sf = sword::pos(mf, sword::dir[multi::cpid], bb);
cell *st = sword::pos(mt, sword::shift(mf, mt, sword::dir[multi::cpid]), bb);
f(st, bb);
2017-03-23 10:53:57 +00:00
if(sf != st && !isNeighbor(sf,st)) {
// also attack the in-transit cell
2017-10-30 11:20:45 +00:00
if(S3 == 3) {
forCellEx(sb, sf) if(isNeighbor(sb, st) && sb != mf && sb != mt) f(sb, bb);
2017-10-30 11:20:45 +00:00
}
else {
forCellEx(sb, mf) if(isNeighbor(sb, st) && sb != mt) f(sb, bb);
forCellEx(sb, mt) if(isNeighbor(sb, sf) && sb != mf) f(sb, bb);
2017-10-30 11:20:45 +00:00
}
2017-03-23 10:53:57 +00:00
}
}
}
2019-08-09 19:00:52 +00:00
EX eMonster do_we_stab_a_friend(cell *mf, cell *mt, eMonster who) {
eMonster m = moNone;
do_swords(mf, mt, who, [&] (cell *c, int bb) {
if(!peace::on && canAttack(mt, who, c, c->monst, AF_SWORD) && c->monst && isFriendly(c)) m = c->monst;
});
for(int t=0; t<mf->type; t++) {
cell *c = mf->move(t);
if(!c) continue;
bool stabthere = false;
if(logical_adjacent(mt, who, c)) stabthere = true;
if(stabthere && canAttack(mt,who,c,c->monst,AF_STAB) && isFriendly(c))
return c->monst;
}
return m;
}
2019-08-09 19:00:52 +00:00
EX void stabbingAttack(cell *mf, cell *mt, eMonster who, int bonuskill IS(0)) {
int numsh = 0, numflail = 0, numlance = 0, numslash = 0, numbb[2];
numbb[0] = numbb[1] = 0;
int backdir = neighborId(mt, mf);
do_swords(mf, mt, who, [&] (cell *c, int bb) { if(swordAttack(mt, who, c, bb)) numbb[bb]++, numslash++; });
for(int bb=0; bb<2; bb++) achievement_count("SLASH", numbb[bb], 0);
2017-07-24 22:21:36 +00:00
if(peace::on) return;
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
for(int t=0; t<mf->type; t++) {
cell *c = mf->move(t);
2016-08-26 09:58:03 +00:00
if(!c) continue;
2017-03-23 10:53:57 +00:00
bool stabthere = false, away = true;
if(logical_adjacent(mt, who, c)) stabthere = true, away = false;
if(stabthere && c->wall == waExplosiveBarrel && markOrb(itOrbThorns))
explodeBarrel(c);
2017-03-23 10:53:57 +00:00
if(stabthere && canAttack(mt,who,c,c->monst,AF_STAB)) {
if(c->monst != moHedge) {
markOrb(itOrbThorns); if(who != moPlayer) markOrb(itOrbEmpathy);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
int k = tkills();
if(attackMonster(c, AF_STAB | AF_MSG, who))
2017-03-23 10:53:57 +00:00
produceGhost(c, m, who);
if(tkills() > k) numsh++;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
if(away && c != mt && canAttack(mf,who,c,c->monst,AF_BACK)) {
2017-03-23 10:53:57 +00:00
if(c->monst == moVizier && c->hitpoints > 1) {
fightmessage(c->monst, who, true, AF_BACK);
c->hitpoints--;
// c->stuntime = 1;
}
else {
eMonster m = c->monst;
if(c->monst != moFlailer) {
playSound(NULL, "hit-sword"+pick123());
fightmessage(c->monst, who, false, AF_BACK);
}
else {
playSound(NULL, "hit-sword"+pick123());
2016-08-26 09:58:03 +00:00
if(who != moPlayer)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 tricks %the2.", who, c->monst));
2016-08-26 09:58:03 +00:00
else
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You trick %the1.", c->monst));
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
if(c->monst == moFlailer && isPrincess(who) && isUnarmed(who))
achievement_gain("PRINCESS_PACIFIST");
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(attackMonster(c, 0, who)) numflail++;
if(m == moVizier) produceGhost(c, m, who);
2016-01-02 10:09:13 +00:00
}
}
}
2015-08-08 13:57:52 +00:00
if(!isUnarmed(who)) forCellIdEx(c, t, mt) {
if(!logical_adjacent(mt, who, c)) continue;
2017-03-23 10:53:57 +00:00
eMonster mm = c->monst;
int flag = AF_APPROACH;
if(anglestraight(mt, backdir, t)) flag |= AF_HORNS;
2017-03-23 10:53:57 +00:00
if(canAttack(mt,who,c,c->monst, flag)) {
if(attackMonster(c, flag | AF_MSG, who)) numlance++;
produceGhost(c, mm, who);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
if(who == moPlayer) {
if(numsh) achievement_count("STAB", numsh, 0);
if(numlance && numflail && numsh) achievement_gain("MELEE3");
2015-08-08 13:57:52 +00:00
if(numlance + numflail + numsh + numslash + bonuskill >= 5) achievement_gain("MELEE5");
if(numsh == 2) {
if(lastdouble == turncount-1) achievement_count("STAB", 4, 0);
lastdouble = turncount;
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool cellDangerous(cell *c) {
2016-08-26 09:58:03 +00:00
return cellUnstableOrChasm(c) || isFire(c) || c->wall == waClosedGate;
}
2019-08-09 19:00:52 +00:00
EX bool hasPrincessWeapon(eMonster m) {
2016-08-26 09:58:03 +00:00
return m == moPalace || m == moFatGuard;
}
/** for an ally m at c, evaluate staying in place */
2019-08-09 19:00:52 +00:00
EX int stayvalue(eMonster m, cell *c) {
2017-03-23 10:53:57 +00:00
if(!passable_for(c->monst, c, NULL, P_MONSTER | P_MIRROR))
return -1501;
if(cellEdgeUnstable(c))
return -1501;
if(againstRose(c, NULL) && !ignoresSmell(c->monst)) return -1500;
return 100;
}
/** for an ally m at c, evaluate moving to c2 */
2019-08-09 19:00:52 +00:00
EX int movevalue(eMonster m, cell *c, cell *c2, flagtype flags) {
2016-08-26 09:58:03 +00:00
int val = 0;
2017-03-23 10:53:57 +00:00
if(isPlayerOn(c2)) val = -3000;
2016-08-26 09:58:03 +00:00
else if(againstRose(c, c2) && !ignoresSmell(m)) return -1200;
else if(m == moPrincess && c2->stuntime && hasPrincessWeapon(c2->monst) &&
!cellDangerous(c) && !cellDangerous(c2) && canAttack(c, m, c2, c2->monst, AF_IGNORE_UNARMED | flags)) {
val = 15000;
}
else if(canAttack(c,m,c2,c2->monst,flags))
2017-03-23 10:53:57 +00:00
val =
(!passable_for(c->monst, c, NULL, P_MONSTER | P_MIRROR)) ? 100 :
2016-08-26 09:58:03 +00:00
(m == moPrincessArmed && isPrincess(c2->monst)) ? 14000 : // jealousy!
2017-03-23 10:53:57 +00:00
isActiveEnemy(c2,m) ? 12000 :
2018-10-25 00:43:14 +00:00
among(c2->monst, moSkeleton, moMetalBeast, moReptile, moTortoise, moSalamander, moTerraWarrior, moBrownBug) ? -400 :
2016-08-26 09:58:03 +00:00
isIvy(c2) ? 8000 :
isInactiveEnemy(c2,m) ? 1000 :
-500;
else if(monstersnear(c2, NULL, m, NULL, c)) val = 50; // linked with mouse suicide!
2017-03-23 10:53:57 +00:00
else if(passable_for(m, c2, c, 0)) {
if(mineMarked(c2) && !ignoresPlates(m))
val = 50;
else
val = 4000;
}
2016-08-26 09:58:03 +00:00
else if(passable_for(m, c2, c, P_DEADLY)) val = -1100;
2017-03-23 10:53:57 +00:00
else val = -1750;
2016-08-26 09:58:03 +00:00
if(c->monst == moGolem )
val -= c2->cpdist;
else if(c->monst == moFriendlyGhost )
val += c2->cpdist - 40;
else if(c->monst == moMouse) {
int d;
if(!euclid && (c2->land != laPalace || !c2->master->alt)) d = 200;
else d = celldistAlt(c2);
// first rule: suicide if the Princess is killed,
// by monstersnear or jumping into a chasm
princess::info *i = princess::getPrisonInfo(c);
if(i && !i->princess) {
if(val == 50 || c2->wall == waChasm) val = 20000;
}
// second rule: move randomly if the Princess is saved
if(i && i->bestdist > 6)
;
// third rule: do not get too far from the Princess
else if(d > 150)
val -= (700+d);
// fourth rule: do not get too far from the Rogue
// NOTE: since Mouse is not a target, we can use
// the full pathfinding here instead of cpdist!
else if(c2->pathdist > 3 && c2->pathdist <= 19)
val -= (500+c2->pathdist * 10);
else if(c2->pathdist > 19)
val -= (700);
// fifth rule: get close to the Princess, to point the way
else
val -= (250+d);
/*
// avoid stepping on trapdoors and plates
// (REMOVED BECAUSE MICE NO LONGER ACTIVATE TRAPDOORS AND PLATES)
// note that the Mouse will still step on the trapdoor
// if it wants to get close to you and there is no other way
if(c2->wall == waTrapdoor)
val -= 5;
*/
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(isPrincess(c->monst)) {
int d = c2->cpdist;
if(d <= 3) val -= d;
else val -= 10 * d;
// the Princess also avoids stepping on pressure plates
if(c2->wall == waClosePlate || c2->wall == waOpenPlate || c2->wall == waTrapdoor)
val -= 5;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(c->monst == moTameBomberbird) {
int d = c2->cpdist;
if(d == 1 && c->cpdist > 1) d = 5;
if(d == 2 && c->cpdist > 2) d = 4;
val -= d;
2015-08-08 13:57:52 +00:00
}
if(c->monst == moKnight && (eubinary || c2->master->alt)) {
2016-08-26 09:58:03 +00:00
val -= celldistAlt(c2);
2017-03-23 10:53:57 +00:00
// don't go to external towers
if(c2->wall == waTower && c2->wparam == 1 && !c2->monst)
return 60;
}
2016-08-26 09:58:03 +00:00
return val;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void movegolems(flagtype flags) {
if(items[itOrbEmpathy] && items[itOrbSlaying])
flags |= AF_CRUSH;
pathdata pd(moMouse);
2016-08-26 09:58:03 +00:00
int qg = 0;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(golems); i++) {
2016-08-26 09:58:03 +00:00
cell *c = golems[i];
eMonster m = c->monst;
if(c->stuntime) continue;
if(m == moGolem || m == moKnight || m == moTameBomberbird || m == moPrincess ||
m == moPrincessArmed || m == moMouse || m == moFriendlyGhost) {
if(m == moGolem) qg++;
if(m == moFriendlyGhost) markOrb(itOrbUndeath);
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
bool recorduse[ittypes];
for(int i=0; i<ittypes; i++) recorduse[i] = orbused[i];
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("stayval"));
2017-10-27 18:07:58 +00:00
int bestv = stayvalue(m, c), bq = 0, bdirs[MAX_EDGE];
2015-08-08 13:57:52 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("moveval"));
for(int k=0; k<c->type; k++) if(c->move(k)) {
cell *c2 = c->move(k);
2016-08-26 09:58:03 +00:00
int val = movevalue(m, c, c2, flags);
2017-03-23 10:53:57 +00:00
2016-08-26 09:58:03 +00:00
if(val > bestv) bestv = val, bq = 0;
if(val == bestv) bdirs[bq++] = k;
}
if(m == moTameBomberbird) {
cell *c2 = whirlwind::jumpDestination(c);
if(c2 && !c2->monst) {
int val = movevalue(m, c, c2, flags);
// printf("val = %d bestv = %d\n",
if(val > bestv) bestv = val, bq = 0;
if(val == bestv) bdirs[bq++] = STRONGWIND;
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
for(int i=0; i<ittypes; i++) orbused[i] = recorduse[i];
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
// printf("stayvalue = %d, result = %d, bq = %d\n", stayvalue(m,c), bestv, bq);
if(bq == 0) continue;
2016-08-26 09:58:03 +00:00
int dir = bdirs[hrand(bq)];
auto mi = movei(c, dir);
auto& c2 = mi.t;
2016-08-26 09:58:03 +00:00
if(c2->monst) {
2017-03-23 10:53:57 +00:00
bool revenge = (m == moPrincess);
bool jealous = (isPrincess(c->monst) && isPrincess(c2->monst));
eMonster m2 = c2->monst;
if(revenge) {
playSound(c2, princessgender() ? "dzia-princess" : "dzia-prince");
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 takes %his1 revenge on %the2!", m, c2->monst));
}
if(revenge || jealous) flags |= AF_CRUSH;
else if((flags & AF_CRUSH) && !canAttack(c, m, c2, c2->monst, flags ^ AF_CRUSH ^ AF_MUSTKILL))
markOrb(itOrbEmpathy), markOrb(itOrbSlaying);
attackMonster(c2, flags | AF_MSG, m);
2019-11-22 15:46:25 +00:00
animateAttack(movei(c, dir), LAYER_SMALL);
2017-03-23 10:53:57 +00:00
produceGhost(c2, m2, m);
2017-09-30 09:46:41 +00:00
sideAttack(c, dir, m, 0);
2017-03-23 10:53:57 +00:00
if(revenge) c->monst = m = moPrincessArmed;
if(jealous) {
playSound(c2, princessgender() ? "dzia-princess" : "dzia-prince");
addMessage("\"That should teach you to take me seriously!\"");
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else {
2017-03-23 10:53:57 +00:00
passable_for(m, c2, c, P_DEADLY);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("move"));
moveMonster(mi);
2017-03-23 10:53:57 +00:00
if(m != moTameBomberbird && m != moFriendlyGhost)
moveBoatIfUsingOne(mi);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
if(c2->monst == m) {
if(m == moGolem) c2->monst = moGolemMoved;
if(m == moMouse) c2->monst = moMouseMoved;
if(m == moPrincess) c2->monst = moPrincessMoved;
if(m == moPrincessArmed) c2->monst = moPrincessArmedMoved;
if(m == moTameBomberbird) c2->monst = moTameBomberbirdMoved;
if(m == moKnight) c2->monst = moKnightMoved;
if(m == moFriendlyGhost) c2->stuntime = 1;
}
2015-08-08 13:57:52 +00:00
empathyMove(mi);
2015-08-08 13:57:52 +00:00
}
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("other"));
2015-08-08 13:57:52 +00:00
}
}
2016-08-26 09:58:03 +00:00
achievement_count("GOLEM", qg, 0);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void sageheat(cell *c, double v) {
2016-08-26 09:58:03 +00:00
HEAT(c) += v;
if(c->wall == waFrozenLake && HEAT(c) > .6) c->wall = waLake;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void activateFlashFrom(cell *cf, eMonster who, flagtype flags);
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
bool sagefresh = true;
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX int nearestPathPlayer(cell *c) {
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) if(playerpos(i) == c) return i;
forCellEx(c2, c) if(c2->pathdist < c->pathdist) return nearestPathPlayer(c2);
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i)) return i;
return 0;
}
/** note: butterflies don't use moveNormal for two reasons:
* 1) to make sure that they move AFTER bulls
* 2) to make sure that they move offscreen
*/
2019-08-09 19:00:52 +00:00
EX void moveButterflies() {
2017-03-23 10:53:57 +00:00
int j = 0;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(butterflies); i++) {
2017-03-23 10:53:57 +00:00
cell* c = butterflies[i].first;
if(c->monst == moButterfly) {
/* // don't move if under attack of a bull
bool underattack = false;
forCellEx(c3, c)
if(c3->monst == moRagingBull && c3->mondir != NODIR &&
angledist(c3->type, c3->mondir, neighborId(c3, c)) == 3 &&
canAttack(c3, moRagingBull, c, c->monst, AF_BULL)
)
underattack = true;
if(underattack) continue; */
cell *c2 = moveNormal(c, 0);
if(butterflies[i].second < 50 && c2)
butterflies[j++] = make_pair(c2, butterflies[i].second+1);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
}
butterflies.resize(j);
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
// assume pathdist
2019-08-09 19:00:52 +00:00
EX void specialMoves() {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(dcal); i++) {
2017-03-23 10:53:57 +00:00
cell *c = dcal[i];
if(c->stuntime) continue;
eMonster m = c->monst;
2017-10-15 22:15:54 +00:00
if(m == moHunterGuard && items[itHunting] >= 10)
c->monst = moHunterChanging;
if(m == moHunterDog && (havewhat & HF_FAILED_AMBUSH) && hyperbolic && !quotient)
c->monst = moHunterChanging;
2017-07-04 13:38:33 +00:00
if(m == moSleepBull && !peace::on) {
2017-03-23 10:53:57 +00:00
bool wakeup = false;
forCellEx(c2, c) if(c2->monst == moGadfly) {
addMessage(XLAT("%The1 wakes up %the2.", c2->monst, m));
wakeup = true;
}
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(targets); i++) {
2017-03-23 10:53:57 +00:00
cell *t = targets[i];
if(celldistance(c, t) <= 2) wakeup = true;
}
if(wakeup) {
playSound(NULL, "bull");
c->monst = m = moRagingBull;
c->mondir = NODIR;
}
}
if(m == moNecromancer) {
pathdata pd(moNecromancer);
2016-08-26 09:58:03 +00:00
int gravenum = 0, zombienum = 0;
cell *gtab[8], *ztab[8];
for(int j=0; j<c->type; j++) if(c->move(j)) {
if(c->move(j)->wall == waFreshGrave) gtab[gravenum++] = c->move(j);
if(passable(c->move(j), c, 0) && c->move(j)->pathdist < c->pathdist)
ztab[zombienum++] = c->move(j);
2016-08-26 09:58:03 +00:00
}
if(gravenum && zombienum) {
cell *gr = gtab[hrand(gravenum)];
gr->wall = waAncientGrave;
gr->monst = moGhost;
2018-03-24 14:21:41 +00:00
gr->stuntime = 1;
2016-08-26 09:58:03 +00:00
ztab[hrand(zombienum)]->monst = moZombie;
2018-03-24 14:21:41 +00:00
ztab[hrand(zombienum)]->stuntime = 1;
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 raises some undead!", m));
playSound(c, "necromancy");
2016-08-26 09:58:03 +00:00
}
}
else if(m == moOutlaw) {
for(cell *c1: gun_targets(c))
if(canAttack(c, moOutlaw, c1, c1->monst, AF_GETPLAYER | AF_ONLY_FBUG | AF_GUN)) {
attackMonster(c1, AF_GETPLAYER | AF_ONLY_FBUG | AF_GUN, moOutlaw);
c->stuntime = 1;
break;
}
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
else if(m == moWitchFlash && flashWouldKill(c, AF_GETPLAYER | AF_ONLY_FBUG) && !flashWouldKill(c, false)) {
addMessage(XLAT("%The1 activates her Flash spell!", m));
m = moWitch;
activateFlashFrom(c, moWitchFlash, AF_MAGIC | AF_GETPLAYER | AF_MSG);
c->stuntime = 1;
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
else if(m == moCrystalSage && c->cpdist <= 4 && isIcyLand(cwt.at) && cwt.at->wall != waBoat) {
2016-08-26 09:58:03 +00:00
// only one sage attacks
if(sagefresh) {
sagefresh = false;
if(sagephase == 0) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 shows you two fingers.", m));
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You wonder what does it mean?"));
}
else if(sagephase == 1) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 shows you a finger.", m));
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You think about possible meanings."));
}
else {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("%The1 moves his finger downwards.", m));
2016-08-26 09:58:03 +00:00
addMessage(XLAT("Your brain is steaming."));
}
sagephase++;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(targets); i++) {
2017-03-23 10:53:57 +00:00
cell *t = targets[i];
if(celldistance(c, t) > 4) continue;
sageheat(t, .0);
for(int i=0; i<t->type; i++)
sageheat(t->move(i), .3);
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
c->stuntime = 1;
2016-08-26 09:58:03 +00:00
}
2017-07-24 22:21:36 +00:00
else if(m == moPyroCultist && !peace::on) {
2017-03-23 10:53:57 +00:00
bool shot = false;
bool dont_approach = false;
// smaller range on the sphere
int firerange = (sphere || getDistLimit() < 5) ? 2 : 4;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(targets); i++) {
2017-03-23 10:53:57 +00:00
cell *t = targets[i];
if(celldistance(c,t) <= firerange && makeflame(t, 20, true)) {
if(isPlayerOn(t))
addMessage(XLAT("%The1 throws fire at you!", m));
else
addMessage(XLAT("%The1 throws fire at %the2!", m, t->monst));
makeflame(t, 20, false);
playSound(t, "fire");
c->monst = moCultist;
shot = true;
}
if(celldistance(c,t) <= 3 && !sphere) dont_approach = true;
}
if(shot || dont_approach) c->stuntime = 1;
}
else if(m == moVampire) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(targets); i++) {
2017-03-23 10:53:57 +00:00
cell *t = targets[i];
if(celldistance(c,t) <= 2) {
bool msg = false;
for(int i=0; i<ittypes; i++)
if(itemclass(eItem(i)) == IC_ORB && items[i] && items[itOrbTime] && !orbused[i]) {
orbused[i] = true;
msg = true;
}
if(msg) addMessage(XLAT("%The1 drains your powers!", m));
c->stuntime = 1;
}
2016-08-26 09:58:03 +00:00
}
}
2015-08-08 13:57:52 +00:00
}
}
2019-08-09 19:00:52 +00:00
EX void moveworms() {
2018-06-22 12:47:24 +00:00
if(!isize(worms)) return;
pathdata pd(moWorm);
2018-06-22 12:47:24 +00:00
int wrm = isize(worms);
2016-08-26 09:58:03 +00:00
for(int i=0; i<wrm; i++) {
moveWorm(worms[i]);
}
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void refreshFriend(cell *c) {
2016-08-26 09:58:03 +00:00
if(c->monst == moGolemMoved) c->monst = moGolem;
if(c->monst == moMouseMoved) c->monst = moMouse;
if(c->monst == moPrincessMoved) c->monst = moPrincess;
if(c->monst == moPrincessArmedMoved) c->monst = moPrincessArmed;
if(c->monst == moKnightMoved) c->monst = moKnight;
if(c->monst == moTameBomberbirdMoved) c->monst = moTameBomberbird;
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool saved_tortoise_on(cell *c) {
return
(c->monst == moTortoise && c->item == itBabyTortoise &&
!((tortoise::getb(c) ^ tortoise::babymap[c]) & tortoise::mask));
}
2019-08-09 19:00:52 +00:00
EX bool normal_gravity_at(cell *c) {
return !in_gravity_zone(c);
}
2019-08-09 19:00:52 +00:00
EX void moverefresh(bool turn IS(true)) {
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) {
cell *c = dcal[i];
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(c->monst == moWolfMoved) c->monst = moWolf;
if(c->monst == moIvyNext) {
c->monst = moIvyHead; ivynext(c);
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
if(c->monst == moIvyDead)
removeIvy(c);
refreshFriend(c);
if(c->monst == moSlimeNextTurn) c->monst = moSlime;
2017-03-23 10:53:57 +00:00
if(c->monst == moLesser && !cellEdgeUnstable(c)) c->monst = moLesserM;
2016-08-26 09:58:03 +00:00
else if(c->monst == moLesserM) c->monst = moLesser;
2017-03-23 10:53:57 +00:00
if(c->monst == moGreater && !cellEdgeUnstable(c)) c->monst = moGreaterM;
2016-08-26 09:58:03 +00:00
else if(c->monst == moGreaterM) c->monst = moGreater;
2015-08-08 13:57:52 +00:00
2018-01-02 10:15:42 +00:00
if(c->monst == moPair && !c->stuntime) {
cell *c2 = c->move(c->mondir);
2018-01-02 10:15:42 +00:00
if(c2->monst != moPair) continue;
if(true) for(int i: {-1, 1}) {
cell *c3 = c->modmove(c->mondir + i);
if(among(c3->wall, waRuinWall, waColumn, waStone, waVinePlant, waPalace)) {
drawParticles(c3, winf[c3->wall].color, 30);
2018-01-02 10:15:42 +00:00
c3->wall = waNone;
}
}
}
2016-08-26 09:58:03 +00:00
if(c->stuntime && !isMutantIvy(c)) {
c->stuntime--;
2017-03-23 10:53:57 +00:00
int breathrange = sphere ? 2 : 3;
2016-08-26 09:58:03 +00:00
if(c->stuntime == 0 && c->monst == moDragonHead) {
// if moDragonHead is renamed to "Dragon Head", we might need to change this
eMonster subject = c->monst;
2016-08-26 09:58:03 +00:00
if(!c->hitpoints) c->hitpoints = 1;
else if(shmup::on && dragon::totalhp(c) > 2 && shmup::dragonbreath(c)) {
c->hitpoints = 0;
}
else if(dragon::totalhp(c) <= 2) ;
2018-02-27 22:53:48 +00:00
else if(isMounted(c)) {
2017-03-23 10:53:57 +00:00
if(dragon::target && celldistance(c, dragon::target) <= breathrange && makeflame(dragon::target, 5, true)) {
addMessage(XLAT("%The1 breathes fire!", subject));
2016-08-26 09:58:03 +00:00
makeflame(dragon::target, 5, false);
2017-03-23 10:53:57 +00:00
playSound(dragon::target, "fire");
2016-08-26 09:58:03 +00:00
c->hitpoints = 0;
}
}
else {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(targets); i++) {
2017-03-23 10:53:57 +00:00
cell *t = targets[i];
if(celldistance(c, t) <= breathrange && makeflame(t, 5, true)) {
if(isPlayerOn(t)) addMessage(XLAT("%The1 breathes fire at you!", subject));
2017-03-23 10:53:57 +00:00
else if(t->monst)
addMessage(XLAT("%The1 breathes fire at %the2!", subject, t->monst));
2017-03-23 10:53:57 +00:00
else
addMessage(XLAT("%The1 breathes fire!", subject));
2017-03-23 10:53:57 +00:00
makeflame(t, 5, false);
playSound(t, "fire");
c->hitpoints = 0;
}
2016-08-26 09:58:03 +00:00
}
}
}
}
// tortoises who have found their children no longer move
if(saved_tortoise_on(c))
c->stuntime = 2;
2017-09-30 09:46:41 +00:00
2017-03-23 10:53:57 +00:00
if(c->monst == moReptile) {
if(c->wall == waChasm || cellUnstable(c)) {
c->monst = moNone;
c->wall = waReptile;
c->wparam = reptilemax();
playSound(c, "click");
}
else if(isChasmy(c) || isWatery(c)) {
if(c->wall == waMercury) {
fallMonster(c, AF_FALL);
c->wall = waNone;
}
else {
c->wall = waReptileBridge;
c->wparam = reptilemax();
c->monst = moNone;
}
2017-03-23 10:53:57 +00:00
c->item = itNone;
playSound(c, "click");
}
}
2016-08-26 09:58:03 +00:00
if(c->wall == waChasm) {
if(c->land != laWhirlwind) c->item = itNone;
2017-03-23 10:53:57 +00:00
if(c->monst && !survivesChasm(c->monst) && c->monst != moReptile && normal_gravity_at(c)) {
2016-08-26 09:58:03 +00:00
if(c->monst != moRunDog && c->land == laMotion)
achievement_gain("FALLDEATH1");
addMessage(XLAT("%The1 falls!", c->monst));
2017-03-23 10:53:57 +00:00
fallMonster(c, AF_FALL);
}
}
else if(isReptile(c->wall) && turn) {
if(c->monst || isPlayerOn(c)) c->wparam = -1;
else if(c->cpdist <= 7) {
c->wparam--;
if(c->wparam == 0) {
if(c->wall == waReptile) c->wall = waChasm;
else placeWater(c, NULL);
c->monst = moReptile;
c->hitpoints = 3;
c->stuntime = 0;
2017-10-27 18:07:58 +00:00
int gooddirs[MAX_EDGE], qdirs = 0;
2017-07-04 13:38:33 +00:00
// in the peace mode, a reptile will
// prefer to walk on the ground, rather than the chasm
for(int i=0; i<c->type; i++) {
int i0 = (i+3) % c->type;
int i1 = (i+c->type-3) % c->type;
if(c->move(i0) && passable(c->move(i0), c, 0))
if(c->move(i1) && passable(c->move(i1), c, 0))
2017-07-04 13:38:33 +00:00
gooddirs[qdirs++] = i;
}
if(qdirs) c->mondir = gooddirs[hrand(qdirs)];
2017-03-23 10:53:57 +00:00
playSound(c, "click");
}
2016-08-26 09:58:03 +00:00
}
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
else if(isFire(c)) {
if(c->monst == moSalamander) c->stuntime = max<int>(c->stuntime, 1);
else if(c->monst && !survivesFire(c->monst) && !isWorm(c->monst)) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 burns!", c->monst));
2017-03-23 10:53:57 +00:00
if(isBull(c->monst)) {
addMessage(XLAT("Fire is extinguished!"));
c->wall = waNone;
}
2018-01-06 21:14:40 +00:00
fallMonster(c, AF_CRUSH);
2016-08-26 09:58:03 +00:00
}
if(c->item && itemBurns(c->item)) {
addMessage(XLAT("%The1 burns!", c->item));
c->item = itNone;
2015-08-08 13:57:52 +00:00
}
}
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
else if(isWatery(c)) {
2016-08-26 09:58:03 +00:00
if(c->monst == moLesser || c->monst == moLesserM || c->monst == moGreater || c->monst == moGreaterM)
c->monst = moGreaterShark;
if(c->monst && !survivesWater(c->monst) && normal_gravity_at(c)) {
2017-03-23 10:53:57 +00:00
playSound(c, "splash"+pick12());
if(isNonliving(c->monst))
addMessage(XLAT("%The1 sinks!", c->monst));
else
addMessage(XLAT("%The1 drowns!", c->monst));
if(isBull(c->monst)) {
addMessage(XLAT("%The1 is filled!", c->wall));
c->wall = waNone;
}
fallMonster(c, AF_FALL);
}
}
else if(c->wall == waSulphur || c->wall == waSulphurC || c->wall == waMercury) {
if(c->monst && !survivesPoison(c->monst, c->wall) && normal_gravity_at(c)) {
playSound(c, "splash"+pick12());
2016-08-26 09:58:03 +00:00
if(isNonliving(c->monst))
addMessage(XLAT("%The1 sinks!", c->monst));
else
addMessage(XLAT("%The1 drowns!", c->monst));
2017-03-23 10:53:57 +00:00
if(isBull(c->monst)) {
addMessage(XLAT("%The1 is filled!", c->wall));
c->wall = waNone;
}
fallMonster(c, AF_FALL);
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
}
2017-10-08 09:12:03 +00:00
else if(c->wall == waMagma) {
if(c->monst == moSalamander) c->stuntime = max<int>(c->stuntime, 1);
else if(c->monst && !survivesPoison(c->monst, c->wall) && normal_gravity_at(c)) {
2017-10-08 09:12:03 +00:00
if(isNonliving(c->monst))
addMessage(XLAT("%The1 is destroyed by lava!", c->monst));
else
addMessage(XLAT("%The1 is killed by lava!", c->monst));
2017-10-10 12:59:19 +00:00
playSound(c, "steamhiss", 70);
2017-10-08 09:12:03 +00:00
fallMonster(c, AF_FALL);
}
}
2017-03-23 10:53:57 +00:00
else if(!isWateryOrBoat(c)) {
if(c->monst == moGreaterShark)
c->monst = moGreaterM;
else if(c->monst == moShark || c->monst == moCShark) {
addMessage(XLAT("%The1 suffocates!", c->monst));
2018-01-06 21:14:40 +00:00
fallMonster(c, AF_CRUSH);
2017-03-23 10:53:57 +00:00
}
else if(c->monst == moKrakenH) {
addMessage(XLAT("%The1 suffocates!", c->monst));
kraken::kill(c, moNone);
}
}
if(c->monst == moVineSpirit && !cellHalfvine(c) && c->wall != waVinePlant) {
addMessage(XLAT("%The1 is destroyed!", c->monst));
2018-01-06 21:14:40 +00:00
fallMonster(c, AF_CRUSH);
2017-03-23 10:53:57 +00:00
}
if(c->monst) mayExplodeMine(c, c->monst);
2016-08-26 09:58:03 +00:00
if(c->monst && c->wall == waClosedGate && !survivesWall(c->monst)) {
2017-03-23 10:53:57 +00:00
playSound(c, "hit-crush"+pick123());
2016-08-26 09:58:03 +00:00
addMessage(XLAT("%The1 is crushed!", c->monst));
2018-01-06 21:14:40 +00:00
fallMonster(c, AF_CRUSH);
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(c->monst && cellUnstable(c) && !ignoresPlates(c->monst) && !shmup::on)
doesFallSound(c);
2016-01-02 10:09:13 +00:00
}
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void consMove(cell *c, eMonster param) {
2017-03-23 10:53:57 +00:00
eMonster m = c->monst;
2016-08-26 09:58:03 +00:00
if(movegroup(m) != moYeti) return;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(m == moWitchSpeed) havewhat |= HF_FAST;
bool slow = slowMover(m);
if(slow) havewhat |= HF_SLOW;
if(param == moYeti && slow) return;
if(param == moTortoise && !slow) return;
if(param == moWitchSpeed && m != moWitchSpeed) return;
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(isActiveEnemy(c, moPlayer)) {
int goodmoves = 0;
for(int t=0; t<c->type; t++) {
cell *c2 = c->move(t);
2017-03-23 10:53:57 +00:00
if(c2 && c2->pathdist < c->pathdist)
goodmoves++;
}
movesofgood[goodmoves].push_back(c);
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else
movesofgood[0].push_back(c);
}
2019-08-09 19:00:52 +00:00
EX void moveNormals(eMonster param) {
pathdata pd(param);
2015-08-08 13:57:52 +00:00
2019-03-02 23:43:31 +00:00
for(int d=0; d<=MAX_EDGE; d++) movesofgood[d].clear();
2017-03-23 10:53:57 +00:00
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(pathqm); i++)
2017-03-23 10:53:57 +00:00
consMove(pathqm[i], param);
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) {
2016-01-02 10:09:13 +00:00
cell *c = dcal[i];
2017-03-23 10:53:57 +00:00
if(c->pathdist == PINFD) consMove(c, param);
}
2019-03-02 23:43:31 +00:00
for(int d=0; d<=MAX_EDGE; d++) for(int i=0; i<isize(movesofgood[d]); i++) {
2017-03-23 10:53:57 +00:00
cell *c = movesofgood[d][i];
if(minf[c->monst].mgroup == moYeti) {
2017-03-23 10:53:57 +00:00
moveNormal(c, MF_PATHDIST);
}
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX void markAmbush(cell *c, manual_celllister& cl) {
if(!cl.add(c)) return;
forCellEx(c2, c)
if(c2->cpdist < c->cpdist)
markAmbush(c2, cl);
}
EX int ambush_distance;
EX bool ambushed;
2019-08-09 19:00:52 +00:00
EX void checkAmbushState() {
if(havewhat & HF_HUNTER) {
2018-06-28 11:35:03 +00:00
manual_celllister cl;
for(cell *c: dcal) {
if(c->monst == moHunterDog) {
if(c->cpdist > ambush_distance)
ambush_distance = c->cpdist;
markAmbush(c, cl);
}
if(c->monst == moHunterGuard && c->cpdist <= 4)
markAmbush(c, cl);
}
if(items[itHunting] > 5 && items[itHunting] <= 22) {
int q = 0;
for(int i=0; i<numplayers(); i++)
forCellEx(c2, playerpos(i))
if(cl.listed(c2))
q++;
if(q == 1) havewhat |= HF_FAILED_AMBUSH;
if(q == 2) {
for(int i=0; i<numplayers(); i++)
forCellEx(c2, playerpos(i))
if(cl.listed(c2))
forCellEx(c3, playerpos(i))
if(c3 != c2 && isNeighbor(c2,c3))
if(cl.listed(c3))
havewhat |= HF_FAILED_AMBUSH;
}
if(havewhat & HF_FAILED_AMBUSH && ambushed) {
addMessage(XLAT("The Hunting Dogs give up."));
ambushed = false;
}
}
}
}
2017-12-05 18:43:45 +00:00
2019-08-09 19:00:52 +00:00
EX void movehex_all() {
2017-12-05 18:43:45 +00:00
for(int i: snaketypes) {
movehex(false, i);
if(!shmup::on && haveMount()) movehex(true, i);
}
movehex_rest(false);
movehex_rest(true);
2017-12-05 18:43:45 +00:00
}
2019-08-09 19:00:52 +00:00
EX void movemonsters() {
ambush_distance = 0;
2017-03-23 10:53:57 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("lava1"));
2017-10-08 09:12:03 +00:00
orboflava(1);
checkAmbushState();
2017-10-08 09:12:03 +00:00
2017-03-23 10:53:57 +00:00
sagefresh = true;
turncount++;
specialMoves();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("ghosts"));
2017-03-23 10:53:57 +00:00
moveghosts();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("butterflies"));
2017-03-23 10:53:57 +00:00
moveButterflies();
2016-01-02 10:09:13 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("normal"));
2017-03-23 10:53:57 +00:00
moveNormals(moYeti);
2015-08-08 13:57:52 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("slow"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_SLOW) moveNormals(moTortoise);
2016-08-26 09:58:03 +00:00
if(sagefresh) sagephase = 0;
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("ivy"));
2016-08-26 09:58:03 +00:00
moveivy();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("slimes"));
2016-08-26 09:58:03 +00:00
groupmove(moSlime, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("sharks"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_SHARK) groupmove(moShark, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("eagles"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_BIRD) groupmove(moEagle, 0);
if(havewhat & HF_EAGLES) groupmove(moEagle, MF_NOATTACKS | MF_ONLYEAGLE);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("eagles"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_REPTILE) groupmove(moReptile, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("air"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_AIR) {
2016-08-26 09:58:03 +00:00
airmap.clear();
groupmove(moAirElemental, 0);
buildAirmap();
}
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("earth"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_EARTH) groupmove(moEarthElemental, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("water"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_WATER) groupmove(moWaterElemental, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("void"));
2017-09-30 09:46:41 +00:00
if(havewhat & HF_VOID) groupmove(moVoidBeast, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("leader"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_LEADER) groupmove(moPirate, 0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("mutant"));
2018-04-14 08:24:02 +00:00
if((havewhat & HF_MUTANT) || (bounded && among(specialland, laOvergrown, laClearing))) movemutant();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("bugs"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_BUG) hive::movebugs();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("whirlpool"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_WHIRLPOOL) whirlpool::move();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("whirlwind"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_WHIRLWIND) whirlwind::move();
2019-02-17 17:37:23 +00:00
#if CAP_COMPLEX2
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("westwall"));
2018-12-21 13:41:23 +00:00
if(havewhat & HF_WESTWALL) westwall::move();
2019-02-17 17:37:23 +00:00
#endif
2019-01-18 20:03:55 +00:00
for(int i=0; i<numplayers(); i++) if(playerpos(i)->item == itOrbSafety) return;
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("river"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_RIVER) prairie::move();
2019-05-12 23:57:40 +00:00
/* DEBB(DF_TURN, ("magnet"));
2018-01-02 10:15:42 +00:00
if(havewhat & HF_MAGNET)
groupmove(moSouthPole, 0),
groupmove(moNorthPole, 0); */
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("bugs"));
2018-01-02 10:15:42 +00:00
if(havewhat & HF_HEXD) groupmove(moHexDemon, 0);
if(havewhat & HF_ALT) groupmove(moAltDemon, 0);
if(havewhat & HF_MONK) groupmove(moMonk, 0);
2016-01-02 10:09:13 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("worm"));
2017-03-23 10:53:57 +00:00
cell *savepos[MAXPLAYER];
for(int i=0; i<numplayers(); i++)
savepos[i] = playerpos(i);
2016-08-26 09:58:03 +00:00
moveworms();
2017-12-05 18:43:45 +00:00
if(havewhat & HF_HEX)
movehex_all();
2017-03-23 10:53:57 +00:00
if(havewhat & HF_KRAKEN) kraken::attacks(), groupmove(moKrakenH, 0);
if(havewhat & HF_DRAGON) groupmove(moDragonHead, MF_NOFRIEND);
if(haveMount()) groupmove(moDragonHead, MF_MOUNT);
2016-01-02 10:09:13 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("golems"));
2016-08-26 09:58:03 +00:00
movegolems(0);
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("fresh"));
2016-08-26 09:58:03 +00:00
moverefresh();
2017-10-08 09:12:03 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("lava2"));
2017-10-08 09:12:03 +00:00
orboflava(2);
2015-08-08 13:57:52 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("shadow"));
2016-08-26 09:58:03 +00:00
moveshadow();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("wandering"));
2016-08-26 09:58:03 +00:00
wandering();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("rosemap"));
2017-03-23 10:53:57 +00:00
if(havewhat & HF_ROSE) buildRosemap();
for(int i=0; i<numplayers(); i++)
if(savepos[i] != playerpos(i)) {
bfs(); break;
}
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
// move heat
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
// move the PC in direction d (or stay in place for d == -1)
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool checkNeedMove(bool checkonly, bool attacking) {
if(items[itOrbDomination] > ORBBASE && cwt.at->monst)
2016-08-26 09:58:03 +00:00
return false;
2017-08-06 12:50:16 +00:00
int flags = 0;
if(cwt.at->monst) {
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
if(isMountable(cwt.at->monst))
addMessage(XLAT("You need to dismount %the1!", cwt.at->monst));
2016-08-26 09:58:03 +00:00
else
addMessage(XLAT("You need to move to give space to %the1!", cwt.at->monst));
2015-08-08 13:57:52 +00:00
}
else if(cwt.at->wall == waRoundTable) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
addMessage(XLAT("It would be impolite to land on the table!"));
}
else if(cwt.at->wall == waLake) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
if(markOrb2(itOrbFish)) return false;
if(in_gravity_zone(cwt.at) && passable(cwt.at, NULL, P_ISPLAYER)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
2017-08-06 12:50:16 +00:00
flags |= AF_FALL;
2016-08-26 09:58:03 +00:00
addMessage(XLAT("Ice below you is melting! RUN!"));
}
else if(!attacking && cellEdgeUnstable(cwt.at)) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
if(in_gravity_zone(cwt.at) && passable(cwt.at, NULL, P_ISPLAYER)) return false;
2016-08-26 09:58:03 +00:00
addMessage(XLAT("Nothing to stand on here!"));
}
else if(cwt.at->wall == waSea || cwt.at->wall == waCamelotMoat) {
2016-08-26 09:58:03 +00:00
if(markOrb(itOrbFish)) return false;
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
if(in_gravity_zone(cwt.at) && passable(cwt.at, NULL, P_ISPLAYER)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
addMessage(XLAT("You have to run away from the water!"));
}
else if(cwt.at->wall == waClosedGate) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
addMessage(XLAT("The gate is closing right on you! RUN!"));
}
else if(isFire(cwt.at) && !markOrb(itOrbWinter) && !markOrb2(itOrbShield)) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
addMessage(XLAT("This spot will be burning soon! RUN!"));
2015-08-08 13:57:52 +00:00
}
else if(cwt.at->wall == waMagma && !markOrb(itOrbWinter) && !markOrb2(itOrbShield)) {
if(markOrb2(itOrbAether)) return false;
if(in_gravity_zone(cwt.at) && passable(cwt.at, cwt.at, P_ISPLAYER)) return false;
if(checkonly) return true;
addMessage(XLAT("Run away from the magma!"));
}
else if(cwt.at->wall == waChasm) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
if(in_gravity_zone(cwt.at) && passable(cwt.at, cwt.at, P_ISPLAYER)) return false;
2016-08-26 09:58:03 +00:00
if(checkonly) return true;
2017-08-06 12:50:16 +00:00
flags |= AF_FALL;
2016-08-26 09:58:03 +00:00
addMessage(XLAT("The floor has collapsed! RUN!"));
}
else if(items[itOrbAether] > ORBBASE && !passable(cwt.at, NULL, P_ISPLAYER | P_NOAETHER)) {
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
2016-08-26 09:58:03 +00:00
return true;
}
else if(!passable(cwt.at, NULL, P_ISPLAYER)) {
if(isFire(cwt.at)) return false; // already checked: have Shield
2017-03-23 10:53:57 +00:00
if(markOrb2(itOrbAether)) return false;
if(checkonly) return true;
addMessage(XLAT("Your Aether power has expired! RUN!"));
}
2016-08-26 09:58:03 +00:00
else return false;
2017-08-06 12:50:16 +00:00
if(hardcore)
killHardcorePlayer(multi::cpid, flags);
2016-08-26 09:58:03 +00:00
return true;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX int countMyGolems(eMonster m) {
2018-06-22 12:47:24 +00:00
int g=0, dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) {
cell *c = dcal[i];
if(c->monst == m) g++;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
return g;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX int savePrincesses() {
2018-06-22 12:47:24 +00:00
int g=0, dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) {
cell *c = dcal[i];
if(isPrincess(c->monst)) princess::save(c);
}
return g;
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int countMyGolemsHP(eMonster m) {
2018-06-22 12:47:24 +00:00
int g=0, dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=0; i<dcs; i++) {
cell *c = dcal[i];
if(c->monst == m) g += c->hitpoints;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
return g;
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void restoreGolems(int qty, eMonster m, int hp IS(0)) {
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2016-08-26 09:58:03 +00:00
for(int i=1; qty && i<dcs; i++) {
cell *c = dcal[i];
if(m == moTameBomberbird ?
(c->mpdist >= 3 && passable(c, NULL, P_FLYING)) :
passable(c, NULL, 0)) {
c->hitpoints = hp / qty;
c->monst = m, qty--, hp -= c->hitpoints;
if(m == moPrincess || m == moPrincessArmed)
princess::newFakeInfo(c);
2015-08-08 13:57:52 +00:00
}
}
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void placeItems(int qty, eItem it) {
2018-06-22 12:47:24 +00:00
int dcs = isize(dcal);
2017-09-30 09:39:00 +00:00
for(int i=1; qty && i<dcs; i++) {
cell *c = dcal[i];
if(!c->monst && !c->item && passable(c, NULL, 0))
c->item = it, qty--;
}
}
2019-08-09 21:39:36 +00:00
EX cellwalker recallCell;
EX display_data recallDisplay;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX bool activateRecall() {
if(!recallCell.at) {
2017-03-23 10:53:57 +00:00
addMessage("Error: no recall");
return false;
}
items[itOrbRecall] = 0; items[itOrbSafety] = 0;
if(!makeEmpty(recallCell.at)) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Your Orb of Recall is blocked by something big!"));
recallCell.at = NULL;
2017-03-23 10:53:57 +00:00
return false;
}
killFriendlyIvy();
movecost(cwt.at, recallCell.at, 3);
playerMoveEffects(cwt.at, recallCell.at);
2017-07-22 23:33:27 +00:00
mirror::destroyAll();
2017-08-14 21:48:46 +00:00
sword::reset();
2017-03-23 10:53:57 +00:00
cwt = recallCell;
recallCell.at = NULL;
flipplayer = true;
centerover = recallDisplay.precise_center;
View = recallDisplay.view_matrix;
// local_perspective = recallDisplay.local_perspective;
gmatrix = recallDisplay.cellmatrices;
gmatrix0 = recallDisplay.old_cellmatrices;
current_display->which_copy = recallDisplay.which_copy;
makeEmpty(cwt.at);
forCellEx(c2, cwt.at)
2017-03-23 10:53:57 +00:00
if(c2->monst != moMutant)
c2->stuntime = 4;
if(shmup::on) shmup::recall();
if(multi::players > 1) multi::recall();
bfs();
checkmove();
drawSafety();
addMessage(XLAT("You are recalled!"));
return true;
}
2019-08-09 19:00:52 +00:00
EX void saveRecall(cellwalker cw2) {
if(!recallCell.at) {
recallCell = cw2;
recallDisplay = *current_display;
}
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX void activateSafety(eLand l) {
if(recallCell.at && activateRecall())
2017-03-23 10:53:57 +00:00
return;
2016-08-26 09:58:03 +00:00
savePrincesses();
int gg = countMyGolems(moGolem);
int gb = countMyGolems(moTameBomberbird);
int gp1 = countMyGolems(moPrincess);
int gp2 = countMyGolems(moPrincessArmed);
int gph1 = countMyGolemsHP(moPrincess);
int gph2 = countMyGolemsHP(moPrincessArmed);
drawSafety();
addMessage(XLAT("You fall into a wormhole!"));
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
eLand f = firstland;
if(l == laTemple) l = laRlyeh;
if(l == laClearing) l = laOvergrown;
if(l == laWhirlpool) l = laOcean;
2017-03-23 10:53:57 +00:00
if(l == laCrossroads5) l = laCrossroads2; // could not fit!
if(l == laCamelot && !(tactic::on && specialland == laCamelot))
2016-08-26 09:58:03 +00:00
l = laCrossroads;
firstland = l;
safetyland = l;
safetyseed = hrandpos();
clear_euland(firstland);
2016-08-26 09:58:03 +00:00
safety = true; avengers = 0;
clearMemory();
initcells();
initgame();
firstland = f;
safety = false;
restoreGolems(gg, moGolem);
restoreGolems(gb, moTameBomberbird);
restoreGolems(gp1, moPrincess, gph1);
restoreGolems(gp2, moPrincessArmed, gph2);
restartGraph();
}
2015-08-08 13:57:52 +00:00
EX bool legalmoves[MAX_EDGE+1];
2017-03-31 19:41:09 +00:00
2019-08-09 19:00:52 +00:00
EX bool hasSafeOrb(cell *c) {
2016-08-26 09:58:03 +00:00
return
c->item == itOrbSafety ||
c->item == itOrbShield ||
2017-03-23 10:53:57 +00:00
c->item == itOrbShell ||
2017-08-06 12:50:16 +00:00
(c->item == itOrbYendor && yendor::state(c) == yendor::ysUnlocked);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void checkmove() {
2017-07-16 21:00:55 +00:00
2019-05-29 21:08:57 +00:00
if(dual::state == 2) return;
if(shmup::on) return;
2019-05-29 21:08:57 +00:00
dynamicval<eGravity> gs(gravity_state, gravity_state);
2017-07-22 23:33:27 +00:00
#if CAP_INV
2017-07-16 21:00:55 +00:00
if(inv::on) inv::compute();
#endif
2017-03-23 10:53:57 +00:00
if(multi::players > 1 && !multi::checkonly) return;
2016-08-26 09:58:03 +00:00
if(hardcore) return;
bool orbusedbak[ittypes];
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
// do not activate orbs!
for(int i=0; i<ittypes; i++) orbusedbak[i] = orbused[i];
2015-08-08 13:57:52 +00:00
for(int i=0; i<=MAX_EDGE; i++) legalmoves[i] = false;
2017-03-31 19:41:09 +00:00
canmove = haveRangedTarget();
2017-03-23 10:53:57 +00:00
items[itWarning]+=2;
2017-10-27 18:07:58 +00:00
if(movepcto(-1, 0, true)) canmove = legalmoves[MAX_EDGE] = true;
2017-03-31 19:41:09 +00:00
if(vid.mobilecompasssize || !canmove)
for(int i=0; i<cwt.at->type; i++)
2017-03-31 19:41:09 +00:00
if(movepcto(1, -1, true))
canmove = legalmoves[cwt.spin] = true;
if(vid.mobilecompasssize || !canmove)
for(int i=0; i<cwt.at->type; i++)
2017-03-31 19:41:09 +00:00
if(movepcto(1, 1, true))
canmove = legalmoves[cwt.spin] = true;
2016-08-26 09:58:03 +00:00
if(kills[moPlayer]) canmove = false;
2017-07-10 18:47:38 +00:00
2017-07-22 23:33:27 +00:00
#if CAP_INV
if(inv::on && !canmove && !inv::incheck) {
2018-01-25 16:21:33 +00:00
if(inv::remaining[itOrbSafety] || inv::remaining[itOrbFreedom])
2017-07-16 21:00:55 +00:00
canmove = true;
else {
inv::check(1);
checkmove();
inv::check(-1);
}
if(canmove)
pushScreen(inv::show);
}
#endif
2017-07-10 18:47:38 +00:00
if(!canmove) {
2016-08-26 09:58:03 +00:00
achievement_final(true);
2017-07-12 17:50:39 +00:00
if(cmode & sm::NORMAL) showMissionScreen();
2017-07-10 18:47:38 +00:00
}
2016-08-26 09:58:03 +00:00
if(canmove && timerstopped) {
timerstart = time(NULL);
timerstopped = false;
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
items[itWarning]-=2;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
for(int i=0; i<ittypes; i++) orbused[i] = orbusedbak[i];
if(recallCell.at && !markOrb(itOrbRecall)) activateRecall();
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
// move the PC. Warning: a very long function! todo: refactor
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void placeGolem(cell *on, cell *moveto, eMonster m) {
2017-03-23 10:53:57 +00:00
if(on->monst == moFriendlyIvy)
killMonster(on, moPlayer);
if(on->monst) {
addMessage(XLAT("There is no room for %the1!", m));
return;
}
if(passable(on, moveto, P_ISFRIEND | (m == moTameBomberbird ? P_FLYING : 0)))
2017-03-23 10:53:57 +00:00
on->monst = m;
2016-08-26 09:58:03 +00:00
else {
2017-03-23 10:53:57 +00:00
on->monst = m;
2018-01-06 21:14:40 +00:00
flagtype f = AF_CRUSH;
2016-08-26 09:58:03 +00:00
if(isFire(on))
addMessage(XLAT("%The1 burns!", m));
else if(on->wall == waChasm)
2018-01-06 21:14:40 +00:00
addMessage(XLAT("%The1 falls!", m)), f = AF_FALL;
2016-08-26 09:58:03 +00:00
else if(isWatery(on) && isNonliving(m))
2018-01-06 21:14:40 +00:00
addMessage(XLAT("%The1 sinks!", m)), f = AF_FALL;
2016-08-26 09:58:03 +00:00
else if(isWatery(on))
2018-01-06 21:14:40 +00:00
addMessage(XLAT("%The1 drowns!", m)), f = AF_FALL;
2016-08-26 09:58:03 +00:00
else if(isWall(on))
addMessage(XLAT("%The1 is crushed!", m));
else if(m == moTameBomberbird && cwt.at->wall == waBoat)
2017-03-23 10:53:57 +00:00
return;
else
addMessage(XLAT("%The1 is destroyed!", m));
printf("mondir = %d\n", on->mondir);
fallMonster(cwt.at, f);
2018-01-06 21:14:40 +00:00
}
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool multiRevival(cell *on, cell *moveto) {
2017-03-23 10:53:57 +00:00
int fl = 0;
if(items[itOrbAether]) fl |= P_AETHER;
if(items[itOrbFish]) fl |= P_FISH;
if(items[itOrbWinter]) fl |= P_WINTER;
if(passable(on, moveto, fl)) {
int id = multi::revive_queue[0];
2018-06-22 12:47:24 +00:00
for(int i=1; i<isize(multi::revive_queue); i++)
2017-03-23 10:53:57 +00:00
multi::revive_queue[i-1] = multi::revive_queue[i];
multi::revive_queue.pop_back();
multi::player[id].at = on;
2017-03-23 10:53:57 +00:00
multi::player[id].spin = neighborId(moveto, on);
if(multi::player[id].spin < 0) multi::player[id].spin = 0;
multi::flipped[id] = true;
multi::whereto[id].d = MD_UNDECIDED;
2017-08-14 21:48:46 +00:00
sword::reset();
2017-03-23 10:53:57 +00:00
return true;
2015-08-08 13:57:52 +00:00
}
2017-03-23 10:53:57 +00:00
return false;
2015-08-08 13:57:52 +00:00
}
2019-06-17 23:46:24 +00:00
bool got_crossroads;
2019-08-09 19:00:52 +00:00
EX void movecost(cell* from, cell *to, int phase) {
if(from->land == laPower && to->land != laPower && (phase & 1)) {
2016-08-26 09:58:03 +00:00
int n=0;
for(int i=0; i<ittypes; i++)
if(itemclass(eItem(i)) == IC_ORB && items[i] >= 2 && i != itOrbFire)
items[i] = 2, n++;
if(n)
addMessage(XLAT("As you leave, your powers are drained!"));
}
2015-08-08 13:57:52 +00:00
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
if(from->land != to->land && tour::on && (phase & 2))
tour::checkGoodLand(to->land);
#endif
2019-06-17 23:46:24 +00:00
if(to->land ==laCrossroads4 && !got_crossroads && !geometry && (phase & 2) && !cheater) {
2016-08-26 09:58:03 +00:00
achievement_gain("CR4");
2019-06-17 23:46:24 +00:00
got_crossroads = true;
2016-08-26 09:58:03 +00:00
chaosUnlocked = true;
2015-08-08 13:57:52 +00:00
}
if(isHaunted(from->land) && !isHaunted(to->land) && (phase & 2)) {
2016-08-26 09:58:03 +00:00
updateHi(itLotus, truelotus = items[itLotus]);
if(items[itLotus] >= 1) achievement_gain("LOTUS1");
2019-06-17 08:13:08 +00:00
if(items[itLotus] >= (big_unlock ? 25 : 10)) achievement_gain("LOTUS2");
if(items[itLotus] >= (big_unlock ? 50 : 25)) achievement_gain("LOTUS3");
if(items[itLotus] >= 50 && !big_unlock) achievement_gain("LOTUS4");
2016-08-26 09:58:03 +00:00
achievement_final(false);
2015-08-08 13:57:52 +00:00
}
if(geometry == gNormal && celldist(to) == 0 && !usedSafety && gold() >= 100 && (phase & 2))
2016-08-26 09:58:03 +00:00
achievement_gain("COMEBACK");
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
bool tortoiseOK =
to->land == from->land || to->land == laTortoise ||
2017-03-23 10:53:57 +00:00
(to->land == laDragon && from->land != laTortoise) ||
chaosmode;
2015-08-08 13:57:52 +00:00
if(tortoise::seek() && !from->item && !tortoiseOK && passable(from, NULL, 0) && (phase & 2)) {
2016-08-26 09:58:03 +00:00
from->item = itBabyTortoise;
tortoise::babymap[from] = tortoise::seekbits;
addMessage(XLAT("You leave %the1.", itBabyTortoise));
items[itBabyTortoise]--;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX bool cantGetGrimoire(cell *c2, bool verbose IS(true)) {
2016-08-26 09:58:03 +00:00
if(chaosmode) return false;
if(!eubinary && !c2->master->alt) return false;
2016-08-26 09:58:03 +00:00
if(c2->item == itGrimoire && items[itGrimoire] > celldistAlt(c2)/-TEMPLE_EACH) {
if(verbose)
addMessage(XLAT("You already have this Grimoire! Seek new tomes in the inner circles."));
return true;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
return false;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void gainLife() {
2016-08-26 09:58:03 +00:00
items[itOrbLife] ++;
if(items[itOrbLife] > 5 && !inv::on) items[itOrbLife] = 5;
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void collectMessage(cell *c2, eItem which) {
bool specialmode = yendor::on || princess::challenge || cheater || !in_full_game();
2017-07-04 13:38:33 +00:00
if(which == itDodeca && peace::on) return;
2017-03-23 10:53:57 +00:00
if(which == itTreat) ;
else if(isElementalShard(which)) {
int tsh =
items[itFireShard] + items[itAirShard] + items[itWaterShard] + items[itEarthShard] +
items[itElemental];
if(tsh == 0) {
addMessage(XLAT("Collect four different Elemental Shards!"));
addMessage(XLAT("Unbalanced shards in your inventory are dangerous."));
}
else {
string t = XLAT("You collect %the1. (%2)", which, its(items[which]+1));
addMessage(t);
}
}
2017-07-04 13:38:33 +00:00
else if(which == itKey) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You have found the Key! Now unlock this Orb of Yendor!"));
2017-07-04 13:38:33 +00:00
}
2017-03-23 10:53:57 +00:00
else if(which == itGreenStone && !items[itGreenStone])
addMessage(XLAT("This orb is dead..."));
else if(which == itGreenStone)
addMessage(XLAT("Another Dead Orb."));
2017-08-06 12:50:16 +00:00
else if(itemclass(which) != IC_TREASURE) {
if(!inv::activating)
2017-08-06 12:50:16 +00:00
addMessage(XLAT("You have found %the1!", which));
}
2017-03-23 10:53:57 +00:00
else if(which == itBabyTortoise) {
playSound(c2, playergender() ? "speak-princess" : "speak-prince");
addMessage(XLAT("Aww, poor %1... where is your family?", which));
}
else if(gold() == 0 && !specialmode)
addMessage(XLAT("Wow! %1! This trip should be worth it!", which));
else if(gold() == 1 && !specialmode)
addMessage(XLAT("For now, collect as much treasure as possible..."));
else if(gold() == 2 && !specialmode)
addMessage(XLAT("Prove yourself here, then find new lands, with new quests..."));
else if(!items[which] && itemclass(which) == IC_TREASURE)
addMessage(XLAT("You collect your first %1!", which));
2017-07-12 16:03:53 +00:00
else if(items[which] == 4 && maxgold() == U5-1 && !specialmode) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel that %the2 become%s2 more dangerous.", which, c2->land));
addMessage(XLAT("With each %1 you collect...", which, c2->land));
}
2017-07-12 16:03:53 +00:00
else if(items[which] == 9 && maxgold() == 9 && !specialmode) {
if(inv::on) {
addMessage(XLAT("The treasure gives your magical powers!", c2->land));
if(!ISMOBILE)
addMessage(XLAT("Press 'i' to access your magical powers.", c2->land));
}
else
addMessage(XLAT("Are there any magical orbs in %the1?...", c2->land));
}
else if(items[which] == R10 && maxgold() == R10 && !specialmode && !inv::on) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel that %the1 slowly become%s1 dangerous...", c2->land));
addMessage(XLAT("Better find some other place."));
}
2017-10-30 09:38:01 +00:00
else if(which == itHunting && items[itHunting] == 4 && !specialmode && !ISMOBWEB)
addMessage(XLAT("Hint: hold Alt to highlights enemies and other important features."));
else if(which == itSpice && items[itSpice] == U10*7/10 && !specialmode && isLandIngame(laHell))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You have a vision of the future, fighting demons in Hell..."));
else if(which == itSpice && items[itSpice] == U10-1 && !specialmode && isLandIngame(laRedRock))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You will be fighting red rock snakes, too..."));
2017-07-12 16:03:53 +00:00
else if(which == itKraken && items[itKraken] == U10-1 && !specialmode)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel that a magical weapon is waiting for you..."));
// else if(which == itFeather && items[itFeather] == 10)
// addMessage(XLAT("There should be a Palace somewhere nearby..."));
2017-07-12 16:03:53 +00:00
else if(which == itElixir && items[itElixir] == U5-1 && !specialmode)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("With this Elixir, your life should be long and prosperous..."));
else if(which == itRuby && items[itRuby] == U5-1 && !specialmode && isLandIngame(laMountain)) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel something strange about gravity here..."));
}
else if(which == itPalace && items[itPalace] == U5-1 && !specialmode && isLandIngame(laDungeon)) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("The rug depicts a man in a deep dungeon, unable to leave."));
}
2019-06-17 08:13:08 +00:00
else if(which == itFeather && items[itFeather] == 25-1 && !specialmode && inv::on && !chaosmode)
2017-08-06 12:50:16 +00:00
addMessage(XLAT("You feel the presence of free saves on the Crossroads."));
2019-06-17 08:13:08 +00:00
else if(which == itHell && items[itHell] == 25-1 && !specialmode && inv::on && !chaosmode)
2017-08-06 12:50:16 +00:00
addMessage(XLAT("You feel the Orbs of Yendor nearby..."));
2019-06-17 08:13:08 +00:00
else if(which == itHell && items[itHell] == 50-1 && !specialmode && inv::on && !chaosmode)
2017-08-06 12:50:16 +00:00
addMessage(XLAT("You feel the Orbs of Yendor in the Crossroads..."));
2019-06-17 08:13:08 +00:00
else if(which == itHell && items[itHell] == 100-1 && !specialmode && inv::on && !chaosmode)
2017-08-06 12:50:16 +00:00
addMessage(XLAT("You feel the Orbs of Yendor everywhere..."));
else if(which == itBone && items[itBone] % 25 == 24 && !specialmode && inv::on)
addMessage(XLAT("You have gained an offensive power!"));
else if(which == itHell && items[itHell] >= 100 && items[itHell] % 25 == 24 && !specialmode && inv::on)
addMessage(XLAT("A small reward for braving the Hell."));
else if(which == itIvory && items[itIvory] == U5-1 && !specialmode && (isLandIngame(laMountain) || isLandIngame(laDungeon))) {
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You feel attuned to gravity, ready to face mountains and dungeons."));
}
else if(which == itBone && items[itBone] == U5+1 && !specialmode && isLandIngame(laHell))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("The Necromancer's Totem contains hellish incantations..."));
2017-07-12 16:03:53 +00:00
else if(which == itStatue && items[itStatue] == U5+1 && !specialmode)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("The inscriptions on the Statue of Cthulhu point you toward your destiny..."));
else if(which == itStatue && items[itStatue] == U5-1 && isLandIngame(laTemple))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("There must be some temples of Cthulhu in R'Lyeh..."));
2017-07-12 16:03:53 +00:00
else if(which == itDiamond && items[itDiamond] == U10-2 && !specialmode)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Still, even greater treasures lie ahead..."));
else if(which == itFernFlower && items[itFernFlower] == U5-1 && isLandIngame(laEmerald))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You overheard Hedgehog Warriors talking about emeralds..."));
else if(which == itEmerald && items[itEmerald] == U5-1 && !specialmode && isLandIngame(laCamelot))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You overhear miners talking about a castle..."));
else if(which == itEmerald && items[itEmerald] == U5 && !specialmode && isLandIngame(laCamelot))
2017-03-23 10:53:57 +00:00
addMessage(XLAT("A castle in the Crossroads..."));
else if(which == itShard) ;
else {
int qty = (which == itBarrow) ? c2->landparam : 1;
string t;
if(which == itBarrow && items[which] < 25 && items[which] + qty >= 25)
t = XLAT("Your energy swords get stronger!");
else if(maxgold() < 25 && items[which] + qty >= 25)
t = XLAT("You feel even more attuned to the magic of this land!");
else t = XLAT("You collect %the1. (%2)", which, its(items[which]+qty));
addMessage(t);
}
}
EX int ambushval;
2017-09-30 09:46:41 +00:00
2019-08-09 19:00:52 +00:00
EX int ambushSize(cell *c, eItem what) {
2017-09-30 09:46:41 +00:00
bool restricted = false;
2017-10-15 21:09:08 +00:00
for(cell *c2: dcal) {
if(c2->cpdist > 3) break;
if(c2->monst && !isFriendly(c2) && !slowMover(c2) && !isMultitile(c2)) restricted = true;
2017-09-30 09:46:41 +00:00
}
2017-10-15 21:09:08 +00:00
2017-10-10 12:24:39 +00:00
int qty = items[itHunting];
2017-10-15 21:09:08 +00:00
if(ambushval)
return ambushval;
2017-09-30 09:46:41 +00:00
switch(what) {
case itCompass:
return 0;
2017-10-10 12:24:39 +00:00
case itHunting:
2017-10-15 22:15:54 +00:00
return min(min(qty, max(33-qty, 6)), 15);
2017-09-30 09:46:41 +00:00
case itOrbSide3:
2017-10-15 21:09:08 +00:00
return restricted ? 10 : 20;
2017-09-30 09:46:41 +00:00
case itOrbFreedom:
2017-10-15 21:09:08 +00:00
return restricted ? 10 : 60;
2017-09-30 09:46:41 +00:00
case itOrbThorns:
case itOrb37:
2017-10-15 21:09:08 +00:00
return 20;
2017-09-30 09:46:41 +00:00
case itOrbLava:
2017-10-15 21:09:08 +00:00
return 20;
2017-09-30 09:46:41 +00:00
case itOrbBeauty:
2017-10-15 21:09:08 +00:00
return 35;
2017-09-30 09:46:41 +00:00
case itOrbShell:
2017-10-15 21:09:08 +00:00
return 35;
2017-09-30 09:46:41 +00:00
case itOrbPsi:
2017-10-15 21:09:08 +00:00
// return 40; -> no benefits
return 20;
2017-09-30 09:46:41 +00:00
case itOrbDash:
case itOrbFrog:
2017-10-15 21:09:08 +00:00
return 40;
2017-09-30 09:46:41 +00:00
case itOrbAir:
case itOrbDragon:
2017-10-15 21:09:08 +00:00
return 50;
2017-09-30 09:46:41 +00:00
case itOrbStunning:
2017-10-15 21:09:08 +00:00
// return restricted ? 50 : 60; -> no benefits
return 30;
2017-09-30 09:46:41 +00:00
case itOrbBull:
case itOrbSpeed:
case itOrbShield:
2017-10-15 21:09:08 +00:00
return 60;
2017-09-30 09:46:41 +00:00
case itOrbInvis:
2017-10-15 21:09:08 +00:00
return 80;
2017-09-30 09:46:41 +00:00
case itOrbTeleport:
2017-10-15 21:09:08 +00:00
return 300;
2017-09-30 09:46:41 +00:00
case itGreenStone:
case itOrbSafety:
case itOrbYendor:
2017-10-15 21:09:08 +00:00
return 0;
2017-09-30 09:46:41 +00:00
case itKey:
2017-10-15 21:09:08 +00:00
return 16;
2017-09-30 09:46:41 +00:00
case itWarning:
2017-10-15 21:09:08 +00:00
return qty;
2017-09-30 09:46:41 +00:00
default:
2017-10-15 21:09:08 +00:00
return restricted ? 6 : 10;
2017-09-30 09:46:41 +00:00
break;
// Flash can survive about 70, but this gives no benefits
}
2017-10-15 21:09:08 +00:00
}
2019-08-09 19:00:52 +00:00
EX int ambush(cell *c, eItem what) {
int maxdist = gamerange();
2017-10-15 21:09:08 +00:00
celllister cl(c, maxdist, 1000000, NULL);
cell *c0 = c;
int d = 0;
int dogs0 = 0;
2017-10-15 21:09:08 +00:00
for(cell *cx: cl.lst) {
int dh = cl.getdist(cx);
if(dh <= 2 && cx->monst == moHunterGuard)
cx->monst = moHunterDog, dogs0++;
2017-10-15 21:09:08 +00:00
if(dh > d) c0 = cx, d = dh;
}
2017-11-03 20:50:31 +00:00
if(sphere) {
int dogs = ambushSize(c, what);
for(int i = cl.lst.size()-1; i>0 && dogs; i--)
if(!isPlayerOn(cl.lst[i]) && !cl.lst[i]->monst)
cl.lst[i]->monst = moHunterDog, dogs--;
}
2017-10-15 21:09:08 +00:00
vector<cell*> around;
cell *clast = NULL;
cell *ccur = c0;
int v = VALENCE;
2019-06-03 13:36:24 +00:00
if(v > 4) {
for(cell *c: cl.lst) if(cl.getdist(c) == d) around.push_back(c);
hrandom_shuffle(&around[0], isize(around));
}
else {
for(int tries=0; tries<10000; tries++) {
cell *c2 = NULL;
if(v == 3) {
forCellEx(c1, ccur)
if(c1 != clast && cl.listed(c1) && cl.getdist(c1) == d)
c2 = c1;
}
if(v == 4) {
for(int i=0; i<ccur->type; i++) {
cell *c1 = (cellwalker(ccur, i) + wstep + 1).peek();
if(!c1) continue;
if(c1 != clast && cl.listed(c1) && cl.getdist(c1) == d)
c2 = c1;
}
}
2019-06-03 13:36:24 +00:00
if(!c2) break;
if(c2->land == laHunting && c2->wall == waNone && c2->monst == moNone)
around.push_back(c2);
clast = ccur; ccur = c2;
if(c2 == c0) break;
}
2017-10-15 21:09:08 +00:00
}
2018-06-22 12:47:24 +00:00
int N = isize(around);
2017-10-15 21:09:08 +00:00
int dogs = ambushSize(c, what);
2017-09-30 09:46:41 +00:00
int gaps = dogs;
if(!N) return dogs0;
ambushed = true;
2017-09-30 09:46:41 +00:00
int shift = hrand(N);
dogs = min(dogs, N);
gaps = min(gaps, N);
for(int i=0; i<dogs; i++) {
int pos = (shift + (N * i) / gaps) % N;
cell *nextdog = around[pos];
nextdog->monst = moHunterDog;
nextdog->stuntime = 1;
drawFlash(nextdog);
}
return dogs + dogs0;
2017-09-30 09:46:41 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool cannotPickupItem(cell *c, bool telekinesis) {
return itemHidden(c) && !telekinesis && !(isWatery(c) && markOrb(itOrbFish));
}
2019-08-09 19:00:52 +00:00
EX bool canPickupItemWithMagnetism(cell *c, cell *from) {
if(!c->item || c->item == itOrbYendor || isWall(c) || cannotPickupItem(c, false))
return false;
if(c->item == itCompass && from->item)
return false;
return true;
}
2019-08-09 19:00:52 +00:00
EX bool doPickupItemsWithMagnetism(cell *c) {
2017-12-30 23:08:55 +00:00
cell *csaf = NULL;
if(items[itOrbMagnetism])
forCellEx(c3, c) if(canPickupItemWithMagnetism(c3, c)) {
if(c3->item == itCompass) {
if(!c->item)
moveItem(c3, c, false);
}
else if(c3->item == itOrbSafety || c3->item == itBuggy || c3->item == itBuggy2)
csaf = c3;
else if(markOrb(itOrbMagnetism))
collectItem(c3, false);
}
if(csaf)
return collectItem(csaf, false);
return false;
}
2019-08-09 19:00:52 +00:00
EX void pickupMovedItems(cell *c) {
if(!c->item) return;
2019-01-18 20:03:55 +00:00
if(c->item == itOrbSafety) return;
if(isPlayerOn(c)) collectItem(c, true);
if(items[itOrbMagnetism])
forCellEx(c2, c)
if(isPlayerOn(c2) && canPickupItemWithMagnetism(c, c2))
collectItem(c, true);
}
2019-08-09 19:00:52 +00:00
EX bool collectItem(cell *c2, bool telekinesis IS(false)) {
2016-08-26 09:58:03 +00:00
bool dopickup = true;
2018-12-23 16:54:38 +00:00
bool had_choice = false;
2015-08-08 13:57:52 +00:00
if(cannotPickupItem(c2, telekinesis))
2016-08-26 09:58:03 +00:00
return false;
/* if(c2->item == itHolyGrail && telekinesis)
return false; */
if(c2->item) {
invismove = false;
if(shmup::on) shmup::visibleFor(2000);
string s0 = "";
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(c2->item == itPalace && items[c2->item] == 12)
princess::forceVizier = true;
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(!cantGetGrimoire(c2, false)) collectMessage(c2, c2->item);
if(c2->item == itDodeca && peace::on) peace::simon::extend();
2016-01-02 10:09:13 +00:00
}
2017-09-30 09:46:41 +00:00
if(c2->land == laHunting && c2->item && !inv::activating) {
int dogs = ambush(c2, c2->item);
if(dogs)
addMessage(XLAT("You are ambushed!"));
2017-09-30 09:46:41 +00:00
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(isRevivalOrb(c2->item) && multi::revive_queue.size()) {
multiRevival(cwt.at, c2);
2017-03-23 10:53:57 +00:00
}
2017-07-16 21:00:55 +00:00
else if(isShmupLifeOrb(c2->item) && shmup::on) {
playSound(c2, "pickup-orb"); // TODO summon
gainLife();
}
else if(orbcharges(c2->item)) {
eItem it = c2->item;
if(it == itOrbRecall && !dual::state) {
cellwalker cw2 = cwt;
cw2++;
cw2.at = c2;
saveRecall(cw2);
}
2017-07-16 21:00:55 +00:00
if(it == itOrbFire) playSound(c2, "fire");
else if(it == itOrbFire) playSound(c2, "fire");
else if(it == itOrbWinter) playSound(c2, "pickup-winter");
else if(it == itOrbSpeed) playSound(c2, "pickup-speed");
else if(it == itRevolver) playSound(c2, "pickup-key");
else playSound(c2, "pickup-orb");
2018-12-23 16:54:38 +00:00
if(items[itOrbChoice]) items[itOrbChoice] = 0, had_choice = true;
int oc = orbcharges(it);
if(dual::state && among(it, itOrbTeleport, itOrbFrog, itOrbPhasing, itOrbDash, itOrbRecall)) {
oc = 10;
it = itOrbSpeed;
}
2019-03-30 16:51:37 +00:00
if(c2->land == laAsteroids) oc = 10;
2018-12-25 18:27:19 +00:00
if(markOrb(itOrbIntensity)) oc = oc * 6 / 5;
2017-07-16 21:00:55 +00:00
if(!items[it]) items[it]++;
items[it] += oc;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->item == itOrbLife) {
2017-03-23 10:53:57 +00:00
playSound(c2, "pickup-orb"); // TODO summon
placeGolem(cwt.at, c2, moGolem);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->item == itOrbFriend) {
2017-03-23 10:53:57 +00:00
playSound(c2, "pickup-orb"); // TODO summon
placeGolem(cwt.at, c2, moTameBomberbird);
2015-08-08 13:57:52 +00:00
}
2017-07-22 23:33:27 +00:00
#if CAP_TOUR
else if(tour::on && (c2->item == itOrbSafety || c2->item == itOrbRecall)) {
addMessage(XLAT("This Orb is not compatible with the Tutorial."));
return true;
}
#endif
2016-08-26 09:58:03 +00:00
else if(c2->item == itOrbSafety) {
2017-03-23 10:53:57 +00:00
playSound(c2, "pickup-orb"); // TODO safety
if(!dual::state) items[c2->item] = 7;
2016-08-26 09:58:03 +00:00
if(shmup::on)
shmup::delayed_safety = true;
2016-08-26 09:58:03 +00:00
else
activateSafety(c2->land);
return true;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(c2->item == itBabyTortoise) {
using namespace tortoise;
int bnew = babymap[c2];
babymap.erase(c2);
int bold = seekbits;
seekbits = bnew;
tortoise::last = seekbits;
2016-08-26 09:58:03 +00:00
if(seek()) {
cell *c = passable(cwt.at, NULL, 0) ? cwt.at : c2;
2016-08-26 09:58:03 +00:00
c->item = itBabyTortoise;
2017-03-23 10:53:57 +00:00
if(c == c2) dopickup = false;
2016-08-26 09:58:03 +00:00
babymap[c] = bold;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else items[itBabyTortoise]++;
2015-08-08 13:57:52 +00:00
}
2017-07-04 13:38:33 +00:00
else if(c2->item == itOrbYendor && peace::on) {
if(!items[itDodeca]) {
addMessage(XLAT("Collect as many Dodecahedra as you can, then return here!"));
}
else {
addMessage(XLAT("Your score: %1", its(items[itDodeca])));
peace::simon::restore();
}
2017-03-23 10:53:57 +00:00
dopickup = false;
}
2017-07-04 13:38:33 +00:00
else if(c2->item == itOrbYendor && yendor::state(c2) != yendor::ysUnlocked) {
dopickup = false;
2016-01-02 10:09:13 +00:00
}
2017-07-04 13:38:33 +00:00
else if(c2->item == itOrbYendor)
yendor::collected(c2);
2016-01-02 10:09:13 +00:00
else if(c2->item == itHolyGrail) {
2017-03-23 10:53:57 +00:00
playSound(c2, "tada");
2016-01-02 10:09:13 +00:00
int v = newRoundTableRadius() + 12;
items[itOrbTeleport] += v;
items[itOrbSpeed] += v;
2016-08-26 09:58:03 +00:00
items[itHolyGrail]++;
addMessage(XLAT("Congratulations! You have found the Holy Grail!"));
2018-08-09 17:28:53 +00:00
if(!eubinary) c2->master->alt->emeraldval |= GRAIL_FOUND;
2019-11-03 12:56:42 +00:00
achievement_collection(c2->item);
2016-08-26 09:58:03 +00:00
}
else if(c2->item == itKey) {
2017-03-23 10:53:57 +00:00
playSound(c2, "pickup-key");
for(int i=0; i<isize(yendor::yi); i++) if(yendor::yi[i].actual_key() == c2)
2016-08-26 09:58:03 +00:00
yendor::yi[i].found = true;
items[itKey]++;
}
else if(!telekinesis && cantGetGrimoire(c2)) {
// telekinesis checks the condition earlier
dopickup = false;
}
else if(c2->item == itCompass) {
dopickup = false;
}
else if(c2->item == itBuggy || c2->item == itBuggy2) {
items[itOrbSafety] += 7;
if(shmup::on)
shmup::delayed_safety = true;
2016-08-26 09:58:03 +00:00
else {
buggyGeneration = false;
activateSafety(laCrossroads);
}
return true;
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else if(c2->item == itTreat) {
playSound(c2, "pickup-scroll");
halloween::getTreat(c2);
}
2016-08-26 09:58:03 +00:00
else {
2017-03-23 10:53:57 +00:00
if(c2->item == itBarrow)
for(int i=0; i<c2->landparam; i++) gainItem(c2->item);
else if(c2->item) gainItem(c2->item);
if(c2->item) {
char ch = iinf[c2->item].glyph;
if(ch == '*') playSound(c2, "pickup-gem");
else if(ch == '$' || ch == 'x') playSound(c2, "pickup-gold");
else if(ch == '%' || ch == ';') playSound(c2, "pickup-potion");
else playSound(c2, "pickup-scroll");
}
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(dopickup && c2->item) {
2019-08-09 23:07:39 +00:00
#if CAP_HISTORY
// temporary variable to avoid the "cannot bind bitfield" problem in C++11
eItem dummy = c2->item;
history::findhistory.emplace_back(c2, dummy);
2016-08-26 09:58:03 +00:00
#endif
if(c2->item == itBombEgg && c2->land == laMinefield) {
c2->landparam |= 2;
c2->landparam &= ~1;
}
2018-12-23 16:54:38 +00:00
if(!had_choice)
c2->item = itNone;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
// if(c2->land == laHive)
// c2->heat = 1;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
int numOrb = 0;
for(int i=0; i<ittypes; i++)
if(itemclass(eItem(i)) == IC_ORB && items[i])
numOrb++;
if(numOrb) achievement_count("ORB", numOrb, 0);
2016-01-02 10:09:13 +00:00
2017-07-12 16:03:53 +00:00
if(princess::reviveAt && gold(NO_LOVE) >= princess::reviveAt && !inv::on) {
2017-03-23 10:53:57 +00:00
princess::reviveAt = 0,
items[itSavedPrincess] = 1;
addMessage("You have enough treasure now to revive the Princess!");
}
2016-08-26 09:58:03 +00:00
return false;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void glance_message() {
2019-05-29 21:07:18 +00:00
if(gold() >= 300)
addMessage(XLAT("You feel great, like a true treasure hunter."));
else if(gold() >= 200)
addMessage(XLAT("Your eyes shine like gems."));
else if(gold() >= 100)
addMessage(XLAT("Your eyes shine as you glance at your precious treasures."));
else if(gold() >= 50)
addMessage(XLAT("You glance at your great treasures."));
else if(gold() >= 10)
addMessage(XLAT("You glance at your precious treasures."));
else if(gold() > 0)
addMessage(XLAT("You glance at your precious treasure."));
else
addMessage(XLAT("Your inventory is empty."));
}
2019-08-09 19:00:52 +00:00
EX void dropGreenStone(cell *c) {
if(items[itGreenStone] && !passable(c, NULL, P_MONSTER)) {
2016-08-26 09:58:03 +00:00
// NOTE: PL/CZ translations assume that itGreenStone is dropped to avoid extra forms!
addMessage(XLAT("Cannot drop %the1 here!", itGreenStone));
2016-08-26 09:58:03 +00:00
return;
}
if(items[itGreenStone] && c->item == itNone) {
items[itGreenStone]--;
if(false) {
c->item = itNone;
spill(c, eWall(c->wall ^ waFloorA ^ waFloorB), 3);
addMessage(XLAT("The slime reacts with %the1!", itGreenStone));
}
else {
c->item = itGreenStone;
addMessage(XLAT("You drop %the1.", itGreenStone));
if(isHaunted(cwt.at->land)) survivalist = false;
2016-08-26 09:58:03 +00:00
}
}
else {
if(items[itGreenStone] && c->item == itGreenStone)
addMessage(XLAT("You juggle the Dead Orbs."));
else if(items[itGreenStone] && c->item)
addMessage(XLAT("You give %the1 a grim look.", c->item));
else if(items[itGreenStone]) {
addMessage(XLAT("Cannot drop %the1 here!", itGreenStone));
return;
}
2019-05-29 21:07:18 +00:00
else glance_message();
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX void roundTableMessage(cell *c2) {
if(!euclid && !cwt.at->master->alt) return;
2016-08-26 09:58:03 +00:00
if(!euclid && !c2->master->alt) return;
int dd = celldistAltRelative(c2) - celldistAltRelative(cwt.at);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
bool tooeasy = (roundTableRadius(c2) < newRoundTableRadius());
if(dd>0) {
if(grailWasFound(cwt.at)) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("The Knights congratulate you on your success!"));
knighted = roundTableRadius(cwt.at);
2016-08-26 09:58:03 +00:00
}
else if(!tooeasy)
addMessage(XLAT("The Knights laugh at your failure!"));
}
else {
if(grailWasFound(cwt.at))
2016-08-26 09:58:03 +00:00
addMessage(XLAT("The Knights stare at you!"));
else if(tooeasy) {
if(!tactic::on)
addMessage(XLAT("Come on, this is too easy... find a bigger castle!"));
}
else
addMessage(XLAT("The Knights wish you luck!"));
}
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool in_full_game() {
if(tactic::on) return false;
if(princess::challenge) return false;
if(chaosmode) return true;
if(euclid && isCrossroads(specialland)) return true;
if(weirdhyperbolic && specialland == laCrossroads4) return true;
if(cryst && isCrossroads(specialland)) return true;
if((in_s2xe() || nonisotropic || (hybri && !hybrid::over_sphere())) && isCrossroads(specialland)) return true;
if(geometry == gNormal && !NONSTDVAR) return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX void knightFlavorMessage(cell *c2) {
2016-01-02 10:09:13 +00:00
if(!eubinary && !c2->master->alt) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"I am lost...\""));
return;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
if(tactic::on) {
addMessage(XLAT("\"The Knights of the Horocyclic Table salute you!\""));
return;
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
bool grailfound = grailWasFound(c2);
int rad = roundTableRadius(c2);
bool tooeasy = (rad < newRoundTableRadius());
static int msgid = 0;
retry:
if(msgid >= 32) msgid = 0;
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
if(msgid == 0 && grailfound) {
addMessage(XLAT("\"I would like to congratulate you again!\""));
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(msgid == 1 && !tooeasy) {
addMessage(XLAT("\"Find the Holy Grail to become one of us!\""));
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else if(msgid == 2 && !tooeasy) {
addMessage(XLAT("\"The Holy Grail is in the center of the Round Table.\""));
2015-08-08 13:57:52 +00:00
}
2019-02-17 17:28:20 +00:00
#if CAP_CRYSTAL
else if(msgid == 3 && cryst) {
if(crystal::pure())
addMessage(XLAT("\"Each piece of the Round Table is exactly %1 steps away from the Holy Grail.\"", its(roundTableRadius(c2))));
else
addMessage(XLAT("\"According to Merlin, the Round Table is a perfect Euclidean sphere in %1 dimensions.\"", its(ginf[gCrystal].sides/2)));
}
2019-02-17 17:28:20 +00:00
#endif
else if(msgid == 3 && !peace::on && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"I enjoy watching the hyperbug battles.\""));
2015-08-08 13:57:52 +00:00
}
else if(msgid == 4 && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"Have you visited a temple in R'Lyeh?\""));
2015-08-08 13:57:52 +00:00
}
else if(msgid == 5 && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"Nice castle, eh?\""));
2015-08-08 13:57:52 +00:00
}
else if(msgid == 6 && items[itSpice] < 10 && !peace::on && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"The Red Rock Valley is dangerous, but beautiful.\""));
2015-08-08 13:57:52 +00:00
}
else if(msgid == 7 && items[itSpice] < 10 && !peace::on && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"Train in the Desert first!\""));
2016-01-02 10:09:13 +00:00
}
else if(msgid == 8 && sizes_known() && !tactic::on) {
string s = "";
2019-02-17 17:28:20 +00:00
if(0) ;
#if CAP_CRYSTAL
else if(cryst)
s = crystal::get_table_boundary();
2019-02-17 17:28:20 +00:00
#endif
else if(!quotient)
s = expansion.get_descendants(rad).get_str(100);
if(s == "") { msgid++; goto retry; }
addMessage(XLAT("\"Our Table seats %1 Knights!\"", s));
2016-01-02 10:09:13 +00:00
}
else if(msgid == 9 && sizes_known() && !tactic::on) {
string s = "";
2019-02-17 17:28:20 +00:00
if(0);
#if CAP_CRYSTAL
else if(cryst)
s = crystal::get_table_volume();
2019-02-17 17:28:20 +00:00
#endif
else if(!quotient)
s = expansion.get_descendants(rad-1, expansion.diskid).get_str(100);
if(s == "") { msgid++; goto retry; }
addMessage(XLAT("\"There are %1 floor tiles inside our Table!\"", s));
}
else if(msgid == 10 && !items[itPirate] && !items[itWhirlpool] && !peace::on && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"Have you tried to take a boat and go into the Ocean? Try it!\""));
2016-01-02 10:09:13 +00:00
}
else if(msgid == 11 && !princess::saved && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"When I visited the Palace, a mouse wanted me to go somewhere.\""));
2016-01-02 10:09:13 +00:00
}
else if(msgid == 12 && !princess::saved && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"I wonder what was there...\""));
2016-01-02 10:09:13 +00:00
}
else if(msgid == 13 && !peace::on && in_full_game()) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("\"Be careful in the Rose Garden! It is beautiful, but very dangerous!\""));
2016-01-02 10:09:13 +00:00
}
2017-03-23 10:53:57 +00:00
else if(msgid == 14) {
addMessage(XLAT("\"There is no royal road to geometry.\""));
}
else if(msgid == 15) {
addMessage(XLAT("\"There is no branch of mathematics, however abstract, "));
addMessage(XLAT("which may not some day be applied to phenomena of the real world.\""));
}
else if(msgid == 16) {
addMessage(XLAT("\"It is not possession but the act of getting there, "));
addMessage(XLAT("which grants the greatest enjoyment.\""));
}
else if(msgid == 17) {
addMessage(XLAT("\"We live in a beautiful and orderly world, "));
addMessage(XLAT("and not in a chaos without norms.\""));
}
2016-08-26 09:58:03 +00:00
else if(msgid == 25) {
addMessage(XLAT("\"Thank you very much for talking, and have a great rest of your day!\""));
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
else {
msgid++; goto retry;
2016-01-02 10:09:13 +00:00
}
2016-08-26 09:58:03 +00:00
msgid++;
}
EX int mine_adjacency_rule = 0;
EX map<cell*, vector<cell*>> adj_memo;
2019-08-09 19:00:52 +00:00
EX bool geometry_has_alt_mine_rule() {
2019-05-08 16:33:08 +00:00
if(WDIM == 2) return VALENCE > 3;
if(WDIM == 3) return !among(geometry, gHoroHex, gCell5, gBitrunc3, gCell8, gECell8, gCell120, gECell120);
return true;
}
2019-08-09 19:00:52 +00:00
EX vector<cell*> adj_minefield_cells(cell *c) {
vector<cell*> res;
if(mine_adjacency_rule == 0 || !geometry_has_alt_mine_rule())
forCellCM(c2, c) res.push_back(c2);
2019-05-08 16:33:08 +00:00
else if(WDIM == 2) {
cellwalker cw(c, 0);
cw += wstep;
cw++;
cellwalker cw1 = cw;
do {
res.push_back(cw.at);
cw += wstep;
cw++;
if(cw.cpeek() == c) cw++;
}
while(cw != cw1);
}
else if(adj_memo.count(c)) return adj_memo[c];
else {
const vector<hyperpoint> vertices = currentmap->get_vertices(c);
manual_celllister cl;
cl.add(c);
for(int i=0; i<isize(cl.lst); i++) {
cell *c1 = cl.lst[i];
bool shares = false;
if(c != c1) {
2019-11-26 23:39:41 +00:00
transmatrix T = currentmap->relative_matrix(c1->master, c->master, C0);
for(hyperpoint h: vertices) for(hyperpoint h2: vertices)
if(hdist(h, T * h2) < 1e-6) shares = true;
if(shares) res.push_back(c1);
}
if(shares || c == c1) forCellEx(c2, c1) cl.add(c2);
}
println(hlog, "adjacent to ", c, " = ", isize(res));
adj_memo[c] = res;
}
return res;
}
2019-08-09 19:00:52 +00:00
EX void auto_teleport_charges() {
if(specialland == laMinefield && firstland == laMinefield && bounded)
items[itOrbTeleport] = isFire(cwt.at->wall) ? 0 : 1;
}
2019-08-09 19:00:52 +00:00
EX bool uncoverMines(cell *c, int lev, int dist, bool just_checking) {
bool b = false;
if(c->wall == waMineMine && just_checking) return true;
if(c->wall == waMineUnknown) {
if(just_checking)
return true;
else {
c->wall = waMineOpen;
b = true;
}
}
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
bool minesNearby = false;
bool nominesNearby = false;
bool mineopens = false;
auto adj = adj_minefield_cells(c);
2017-03-23 10:53:57 +00:00
for(cell *c2: adj) {
2017-03-23 10:53:57 +00:00
if(c2->wall == waMineMine) minesNearby = true;
if(c2->wall == waMineOpen) mineopens = true;
if(c2->wall == waMineUnknown && !c2->item) nominesNearby = true;
}
if(lev && (nominesNearby || mineopens) && !minesNearby) for(cell *c2: adj)
if(c2->wall == waMineUnknown || c2->wall == waMineOpen) {
b |= uncoverMines(c2, lev-1, dist+1, just_checking);
if(b && just_checking) return true;
}
2017-03-23 10:53:57 +00:00
if(minesNearby && !nominesNearby && dist == 0) {
for(cell *c2: adj)
2017-03-23 10:53:57 +00:00
if(c2->wall == waMineMine && c2->land == laMinefield)
c2->landparam |= 1;
}
return b;
2017-03-23 10:53:57 +00:00
}
EX namespace orbbull {
2017-03-23 10:53:57 +00:00
cell *prev[MAXPLAYER];
eLastmovetype prevtype[MAXPLAYER];
int count;
bool is(cell *c1, cell *c2, cell *c3) {
int lp = neighborId(c2, c1);
int ln = neighborId(c2, c3);
return lp >= 0 && ln >= 0 && anglestraight(c2, lp, ln);
2017-03-23 10:53:57 +00:00
}
EX void gainBullPowers() {
2017-03-23 10:53:57 +00:00
items[itOrbShield]++; orbused[itOrbShield] = true;
items[itOrbThorns]++; orbused[itOrbThorns] = true;
items[itOrbHorns]++; orbused[itOrbHorns] = true;
}
void check() {
int cp = multi::cpid;
if(cp < 0 || cp >= MAXPLAYER) cp = 0;
if(!items[itOrbBull]) {
prev[cp] = NULL;
return;
}
bool seq = false;
if(prev[cp] && prevtype[cp] == lmMove && lastmovetype == lmMove)
seq = is(prev[cp], lastmove, cwt.at);
2017-03-23 10:53:57 +00:00
if(prev[cp] && prevtype[cp] == lmMove && lastmovetype == lmAttack)
seq = is(prev[cp], cwt.at, lastmove);
2017-03-23 10:53:57 +00:00
if(prev[cp] && prevtype[cp] == lmAttack && lastmovetype == lmAttack && count)
seq = lastmove == prev[cp];
if(prev[cp] && prevtype[cp] == lmAttack && lastmovetype == lmMove && count)
seq = cwt.at == prev[cp];
2017-03-23 10:53:57 +00:00
prev[cp] = lastmove; prevtype[cp] = lastmovetype;
if(seq) {
if(lastmovetype == lmMove) count++;
gainBullPowers();
}
else count = 0;
2015-08-08 13:57:52 +00:00
}
EX }
2016-08-26 09:58:03 +00:00
#if HDR
2017-10-04 19:26:26 +00:00
// predictable or not
static constexpr bool randterra = false;
#endif
2017-10-04 19:26:26 +00:00
2019-08-09 19:00:52 +00:00
EX void terracotta(cell *c) {
2018-11-23 01:58:16 +00:00
if(c->wall == waTerraWarrior && !c->monst && !racing::on) {
2017-10-12 09:33:26 +00:00
bool live = false;
if(randterra) {
c->landparam++;
if((c->landparam == 3 && hrand(3) == 0) ||
(c->landparam == 4 && hrand(2) == 0) ||
c->landparam == 5)
live = true;
}
else {
c->landparam--;
live = !c->landparam;
}
if(live)
c->monst = moTerraWarrior,
c->hitpoints = 7,
c->wall = waNone;
}
}
2019-08-09 19:00:52 +00:00
EX void terracottaAround(cell *c) {
forCellEx(c2, c)
terracotta(c2);
}
2019-08-09 19:00:52 +00:00
EX void terracotta() {
2017-09-30 09:46:41 +00:00
for(int i=0; i<numplayers(); i++)
2017-10-12 09:33:26 +00:00
forCellEx(c, playerpos(i)) {
if(shmup::on) {
forCellEx(c2, c)
terracotta(c2);
2017-09-30 09:46:41 +00:00
}
2017-10-12 09:33:26 +00:00
else
terracotta(c);
}
2017-09-30 09:46:41 +00:00
}
2019-08-10 08:57:14 +00:00
EX eMonster passive_switch = moSwitch2;
2017-12-30 14:12:15 +00:00
2019-08-09 19:00:52 +00:00
EX void checkSwitch() {
2017-12-30 14:12:15 +00:00
passive_switch = (gold() & 1) ? moSwitch1 : moSwitch2;
}
2019-08-09 19:00:52 +00:00
EX void monstersTurn() {
checkSwitch();
2017-07-22 23:33:27 +00:00
mirror::breakAll();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("bfs"));
2016-08-26 09:58:03 +00:00
bfs();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("charge"));
2016-08-26 09:58:03 +00:00
if(elec::havecharge) elec::act();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("mmo"));
2016-08-26 09:58:03 +00:00
int phase2 = (1 & items[itOrbSpeed]);
if(!phase2) movemonsters();
2019-01-18 20:03:55 +00:00
for(int i=0; i<numplayers(); i++) if(playerpos(i)->item == itOrbSafety) {
collectItem(playerpos(i), true);
return;
}
2017-03-23 10:53:57 +00:00
if(playerInPower() && (phase2 || !items[itOrbSpeed]) && (havewhat & HF_FAST))
moveNormals(moWitchSpeed);
2016-08-26 09:58:03 +00:00
if(phase2 && markOrb(itOrbEmpathy)) {
bfs();
movegolems(AF_FAST);
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(dcal); i++) {
2016-08-26 09:58:03 +00:00
if(dcal[i]->monst == moFriendlyGhost && dcal[i]->stuntime)
dcal[i]->stuntime--;
refreshFriend(dcal[i]);
}
2015-08-08 13:57:52 +00:00
}
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("rop"));
2019-05-28 23:09:38 +00:00
if(!dual::state) reduceOrbPowers();
2017-03-23 10:53:57 +00:00
int phase1 = (1 & items[itOrbSpeed]);
2019-05-28 23:09:38 +00:00
if(dual::state && items[itOrbSpeed]) phase1 = !phase1;
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("lc"));
2016-08-26 09:58:03 +00:00
if(!phase1) livecaves();
2017-03-23 10:53:57 +00:00
if(!phase1) ca::simulate();
if(!phase1) heat::processfires();
2018-01-02 10:15:42 +00:00
2018-01-06 22:02:33 +00:00
for(cell *c: crush_now) {
playSound(NULL, "closegate");
if(canAttack(c, moCrusher, c, c->monst, AF_GETPLAYER | AF_CRUSH)) {
attackMonster(c, AF_MSG | AF_GETPLAYER | AF_CRUSH, moCrusher);
2018-01-06 22:02:33 +00:00
}
moveEffect(movei(c, FALL), moDeadBird);
2018-12-25 22:56:39 +00:00
destroyBoats(c, NULL, true);
explodeBarrel(c);
2018-01-06 22:02:33 +00:00
}
2018-01-02 10:15:42 +00:00
crush_now = move(crush_next);
crush_next.clear();
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("heat"));
2017-03-23 10:53:57 +00:00
heat::processheat();
2016-08-26 09:58:03 +00:00
// if(elec::havecharge) elec::drawcharges();
2015-08-08 13:57:52 +00:00
orbbull::check();
if(!phase1) terracotta();
2016-08-26 09:58:03 +00:00
if(items[itOrbFreedom])
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i))
checkFreedom(playerpos(i));
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("check"));
2016-08-26 09:58:03 +00:00
checkmove();
if(canmove) elec::checklightningfast();
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
2019-08-09 23:07:39 +00:00
#if CAP_HISTORY
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i))
history::movehistory.push_back(playerpos(i));
2016-08-26 09:58:03 +00:00
#endif
2015-08-08 13:57:52 +00:00
}
EX void pushThumper(const movei& mi) {
auto &cto = mi.t;
auto &th = mi.s;
2016-08-26 09:58:03 +00:00
eWall w = th->wall;
if(th->land == laAlchemist)
th->wall = isAlch(cwt.at) ? cwt.at->wall : cto->wall;
2016-08-26 09:58:03 +00:00
else th->wall = waNone;
2018-12-16 23:04:59 +00:00
int explode = 0;
if(cto->wall == waArrowTrap && w == waExplosiveBarrel ) explode = max<int>(cto->wparam, 1);
if(cto->wall == waFireTrap) {
if(w == waExplosiveBarrel)
explode = max<int>(cto->wparam, 1);
if(w == waThumperOn)
explode = 2;
}
2018-12-16 23:04:59 +00:00
destroyTrapsOn(cto);
2016-08-26 09:58:03 +00:00
if(cto->wall == waOpenPlate || cto->wall == waClosePlate) {
toggleGates(cto, cto->wall);
2018-12-16 23:04:59 +00:00
addMessage(XLAT("%The1 destroys %the2!", w, cto->wall));
2016-08-26 09:58:03 +00:00
}
if(cellUnstable(cto) && cto->land == laMotion) {
2018-12-16 23:04:59 +00:00
addMessage(XLAT("%The1 falls!", w));
2017-03-23 10:53:57 +00:00
doesFallSound(cto);
2016-08-26 09:58:03 +00:00
}
2017-08-18 01:39:55 +00:00
else if(cellUnstableOrChasm(cto)) {
2018-12-16 23:04:59 +00:00
addMessage(XLAT("%The1 fills the hole!", w));
cto->wall = w == waThumperOn ? waTempFloor : waNone;
2019-04-08 12:55:26 +00:00
cto->wparam = th->wparam;
playSound(cto, "click");
2016-08-26 09:58:03 +00:00
}
else if(isWatery(cto)) {
2018-12-16 23:04:59 +00:00
addMessage(XLAT("%The1 fills the hole!", w));
cto->wall = w == waThumperOn ? waTempBridge : waNone;
2019-04-08 12:55:26 +00:00
cto->wparam = th->wparam;
playSound(cto, "splash"+pick12());
2016-08-26 09:58:03 +00:00
}
else
cto->wall = w;
2018-12-16 23:04:59 +00:00
if(explode) cto->wall = waFireTrap, cto->wparam = explode;
if(cto->wall == waThumperOn)
cto->wparam = th->wparam;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool canPushThumperOn(cell *tgt, cell *thumper, cell *player) {
if(tgt->wall == waBoat || tgt->wall == waStrandedBoat) return false;
2017-03-23 10:53:57 +00:00
if(isReptile(tgt->wall)) return false;
2016-08-26 09:58:03 +00:00
if(isWatery(tgt) && !tgt->monst)
return true;
if(tgt->wall == waChasm && !tgt->monst)
return true;
return
passable(tgt, thumper, P_MIRROR) &&
passable(tgt, player, P_MIRROR) &&
!tgt->item;
2016-01-02 10:09:13 +00:00
}
2019-08-09 19:00:52 +00:00
EX void activateActiv(cell *c, bool msg) {
2016-08-26 09:58:03 +00:00
if(msg) addMessage(XLAT("You activate %the1.", c->wall));
2017-03-23 10:53:57 +00:00
if(c->wall == waThumperOff) {
playSound(c, "click");
c->wall = waThumperOn;
}
if(c->wall == waBonfireOff) {
playSound(c, "fire");
c->wall = waFire;
}
2016-08-26 09:58:03 +00:00
c->wparam = 100;
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool scentResistant() {
2017-03-23 10:53:57 +00:00
return markOrb(itOrbBeauty) || markOrb(itOrbAether) || markOrb(itOrbShield);
}
2019-08-09 19:00:52 +00:00
EX void wouldkill(const char *msg) {
if(who_kills_me == moWarning)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("This move appears dangerous -- are you sure?"));
else if(who_kills_me == moFireball)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Cannot move into the current location of another player!"));
else if(who_kills_me == moAirball)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("Players cannot get that far away!"));
else
addMessage(XLAT(msg, who_kills_me));
2017-03-23 10:53:57 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool havePushConflict(cell *pushto, bool checkonly) {
2017-03-23 10:53:57 +00:00
if(pushto && multi::activePlayers() > 1) {
for(int i=0; i<multi::players; i++) if(i != multi::cpid && multi::playerActive(i))
if(multi::origpos[i] == pushto || multi::origtarget[i] == pushto) {
if(!checkonly)
addMessage(XLAT("Cannot push into another player!"));
return true;
}
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(stalemate::moves); i++) {
2017-03-23 10:53:57 +00:00
if(pushto == stalemate::moves[i].pushto) {
if(!checkonly)
addMessage(XLAT("Cannot push into the same location!"));
return true;
}
}
}
return false;
}
EX cell *global_pushto;
2017-03-23 10:53:57 +00:00
2019-08-09 19:00:52 +00:00
EX void killFriendlyIvy() {
forCellEx(c2, cwt.at) if(c2->monst == moFriendlyIvy)
2017-03-23 10:53:57 +00:00
killMonster(c2, moPlayer, 0);
2015-08-08 13:57:52 +00:00
}
2019-08-09 19:00:52 +00:00
EX bool monsterPushable(cell *c2) {
return (c2->monst != moFatGuard && !(isMetalBeast(c2->monst) && c2->stuntime < 2) && c2->monst != moTortoise && c2->monst != moTerraWarrior && c2->monst != moVizier);
2017-06-18 16:51:46 +00:00
}
EX bool got_survivalist;
2019-08-09 19:00:52 +00:00
EX bool should_switchplace(cell *c1, cell *c2) {
if(isPrincess(c2->monst) || among(c2->monst, moGolem, moIllusion, moMouse, moFriendlyGhost))
return true;
if(peace::on) return c2->monst && !isMultitile(c2->monst);
return false;
}
2019-08-09 19:00:52 +00:00
EX bool warningprotection_hit(eMonster m) {
if(m && warningprotection(XLAT("Are you sure you want to hit %the1?", m)))
return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX bool switchplace_prevent(cell *c1, cell *c2, bool checkonly) {
if(!should_switchplace(c1, c2)) return false;
if(c1->monst && c1->monst != moFriendlyIvy) {
if(!checkonly) addMessage(XLAT("There is no room for %the1!", c2->monst));
return true;
}
if(passable(c1, c2, P_ISFRIEND | (c2->monst == moTameBomberbird ? P_FLYING : 0))) return false;
if(warningprotection_hit(c2->monst)) return true;
return false;
}
2019-08-09 19:00:52 +00:00
EX void handle_switchplaces(cell *c1, cell *c2, bool& switchplaces) {
if(should_switchplace(c1, c2)) {
bool pswitch = false;
if(c2->monst == moMouse)
princess::mouseSqueak(c2);
else if(isPrincess(c2->monst)) {
princess::line(c2);
princess::move(match(c2, c1));
}
else
pswitch = true;
c1->hitpoints = c2->hitpoints;
c1->stuntime = c2->stuntime;
placeGolem(c1, c2, c2->monst);
if(cwt.at->monst != moNone && pswitch)
addMessage(XLAT("You switch places with %the1.", c2->monst));
c2->monst = moNone;
switchplaces = true;
}
}
2019-08-09 19:00:52 +00:00
EX bool movepcto(int d, int subdir IS(1), bool checkonly IS(false)) {
2019-05-28 23:09:38 +00:00
if(dual::state == 1) return dual::movepc(d, subdir, checkonly);
if(d >= 0 && !checkonly && subdir != 1 && subdir != -1) printf("subdir = %d\n", subdir);
2017-03-23 10:53:57 +00:00
global_pushto = NULL;
bool switchplaces = false;
if(d == MD_USE_ORB)
return targetRangedOrb(multi::whereto[multi::cpid].tgt, roMultiGo);
bool errormsgs = multi::players == 1 || multi::cpid == multi::players-1;
2016-08-26 09:58:03 +00:00
if(hardcore && !canmove) return false;
2017-03-23 10:53:57 +00:00
if(!checkonly && d >= 0) {
flipplayer = false;
if(multi::players > 1) multi::flipped[multi::cpid] = false;
}
2019-05-12 23:57:40 +00:00
DEBBI(checkonly ? 0 : DF_TURN, ("movepc"));
2017-03-23 10:53:57 +00:00
int origd = d;
2016-08-26 09:58:03 +00:00
if(d >= 0) {
2018-03-24 11:59:01 +00:00
cwt += d;
2017-07-22 23:33:27 +00:00
mirror::act(d, mirror::SPINSINGLE);
2016-08-26 09:58:03 +00:00
d = cwt.spin;
}
if(d != -1 && !checkonly) playermoved = true;
if(!checkonly) invismove = false;
bool boatmove = false;
2018-02-27 22:43:21 +00:00
if(multi::players > 1)
lastmountpos[multi::cpid] = cwt.at;
2018-02-27 22:43:21 +00:00
else
lastmountpos[0] = cwt.at;
2018-02-27 22:43:21 +00:00
if(againstRose(cwt.at, NULL) && d<0 && !scentResistant()) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
addMessage("You just cannot stand in place, those roses smell too nicely.");
return false;
2016-01-02 10:09:13 +00:00
}
2015-08-08 13:57:52 +00:00
gravity_state = gsNormal;
2019-05-28 23:09:38 +00:00
bool fmsMove = forcedmovetype == fmSkip || forcedmovetype == fmMove;
bool fmsAttack = forcedmovetype == fmSkip || forcedmovetype == fmAttack;
bool fmsActivate = forcedmovetype == fmSkip || forcedmovetype == fmActivate;
2016-08-26 09:58:03 +00:00
if(d >= 0) {
2019-11-22 15:46:25 +00:00
movei mi(cwt.at, d);
cell *& c2 = mi.t;
2017-07-04 13:38:33 +00:00
bool goodTortoise = c2->monst == moTortoise && tortoise::seek() && !tortoise::diff(tortoise::getb(c2)) && !c2->item;
if(items[itOrbGravity]) {
if(c2->monst && !should_switchplace(cwt.at, c2))
gravity_state = get_static_gravity(cwt.at);
else
gravity_state = get_move_gravity(cwt.at, c2);
if(gravity_state) markOrb(itOrbGravity);
}
2015-08-08 13:57:52 +00:00
if(againstRose(cwt.at, c2) && !scentResistant()) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
addMessage("Those roses smell too nicely. You have to come towards them.");
return false;
}
2019-05-28 23:09:38 +00:00
bool try_instant = (forcedmovetype == fmInstant) || (forcedmovetype == fmSkip && !passable(c2, cwt.at, P_ISPLAYER | P_MIRROR | P_USEBOAT | P_FRIENDSWAP));
if(items[itOrbDomination] > ORBBASE && isMountable(c2->monst) && !monstersnear2() && fmsMove) {
if(checkonly) { nextmovetype = lmMove; return true; }
if(!isMountable(cwt.at->monst)) dragon::target = NULL;
movecost(cwt.at, c2, 3);
2016-08-26 09:58:03 +00:00
2017-03-23 10:53:57 +00:00
flipplayer = true; if(multi::players > 1) multi::flipped[multi::cpid] = true;
invismove = (turncount >= noiseuntil) && items[itOrbInvis] > 0;
killFriendlyIvy();
2016-08-26 09:58:03 +00:00
goto mountjump;
}
2019-05-28 23:09:38 +00:00
if(items[itOrbFlash] && try_instant) {
if(checkonly) { nextmovetype = lmInstant; return true; }
if(orbProtection(itOrbFlash)) return true;
2016-08-26 09:58:03 +00:00
activateFlash();
bfs();
2017-03-23 10:53:57 +00:00
if(multi::players > 1) { multi::whereto[multi::cpid].d = MD_UNDECIDED; return false; }
2016-08-26 09:58:03 +00:00
checkmove();
return true;
}
2015-08-08 13:57:52 +00:00
2019-05-28 23:09:38 +00:00
if(items[itOrbLightning] && try_instant) {
if(checkonly) { nextmovetype = lmInstant; return true; }
if(orbProtection(itOrbLightning)) return true;
2016-08-26 09:58:03 +00:00
activateLightning();
keepLightning = true;
bfs();
keepLightning = false;
2017-03-23 10:53:57 +00:00
if(multi::players > 1) { multi::whereto[multi::cpid].d = MD_UNDECIDED; return false; }
2016-08-26 09:58:03 +00:00
checkmove();
return true;
}
2015-08-08 13:57:52 +00:00
2019-05-28 23:09:38 +00:00
if(isActivable(c2) && fmsActivate) {
if(checkonly) { nextmovetype = lmInstant; return true; }
2016-08-26 09:58:03 +00:00
activateActiv(c2, true);
bfs();
2017-03-23 10:53:57 +00:00
if(multi::players > 1) { multi::whereto[multi::cpid].d = MD_UNDECIDED; return false; }
2016-08-26 09:58:03 +00:00
checkmove();
return true;
}
2015-08-08 13:57:52 +00:00
2019-05-28 23:09:38 +00:00
if(isPushable(c2->wall) && !c2->monst && !nonAdjacentPlayer(c2, cwt.at) && fmsMove) {
auto mip = determinePush(cwt, subdir, [c2] (cell *c) { return canPushThumperOn(c, c2, cwt.at); });
if(mip.d == NO_SPACE) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
addMessage(XLAT("No room to push %the1.", c2->wall));
return false;
}
if(monstersnear(c2, NULL, moPlayer, NULL, cwt.at)) {
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs) wouldkill("%The1 would kill you there!");
return false;
}
global_pushto = mip.t;
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmMove; return true; }
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You push %the1.", c2->wall));
lastmovetype = lmPush; lastmove = cwt.at;
pushThumper(mip);
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(c2->item == itHolyGrail && roundTableRadius(c2) < newRoundTableRadius()) {
if(checkonly) return false;
addMessage(XLAT("That was not a challenge. Find a larger castle!"));
return false;
}
if(c2->item == itOrbYendor && !checkonly && !peace::on && !itemHiddenFromSight(c2) && yendor::check(c2)) {
return false;
}
2019-05-28 23:09:38 +00:00
if(isWatery(c2) && !nonAdjacentPlayer(cwt.at,c2) && !c2->monst && cwt.at->wall == waBoat && fmsMove) {
2017-03-23 10:53:57 +00:00
if(havePushConflict(cwt.at, checkonly)) return false;
2016-01-02 10:09:13 +00:00
if(againstWind(c2, cwt.at)) {
2016-08-26 09:58:03 +00:00
if(!checkonly)
addMessage(XLAT(airdist(c2) < 3 ? "The Air Elemental blows you away!" : "You cannot go against the wind!"));
return false;
}
if(againstCurrent(c2, cwt.at) && !markOrb(itOrbWater)) {
if(markOrb(itOrbFish) || markOrb(itOrbAether) || gravity_state) goto escape;
2016-08-26 09:58:03 +00:00
if(!checkonly)
addMessage(XLAT("You cannot go against the current!"));
return false;
}
2017-03-23 10:53:57 +00:00
if(cwt.at->item == itOrbYendor) {
if(markOrb(itOrbFish) || markOrb(itOrbAether) || gravity_state) goto escape;
if(!checkonly) addMessage(XLAT("The Orb of Yendor is locked in with powerful magic."));
return false;
}
if(monstersnear(c2, NULL, moPlayer, NULL, cwt.at)) {
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs) wouldkill("%The1 would kill you there!");
return false;
}
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmMove; return true; }
moveBoat(mi);
2016-08-26 09:58:03 +00:00
boatmove = true;
2017-03-23 10:53:57 +00:00
goto boatjump;
2016-08-26 09:58:03 +00:00
}
if(!c2->monst && cwt.at->wall == waBoat && cwt.at->item != itOrbYendor && boatGoesThrough(c2) && markOrb(itOrbWater) && !nonAdjacentPlayer(c2, cwt.at) && fmsMove) {
2017-03-23 10:53:57 +00:00
if(havePushConflict(cwt.at, checkonly)) return false;
if(monstersnear(c2,NULL,moPlayer,NULL,cwt.at)) {
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs) wouldkill("%The1 would kill you there!");
return false;
}
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmMove; return true; }
if(c2->item && !cwt.at->item) moveItem(c2, cwt.at, false), boatmove = true;
placeWater(c2, cwt.at);
moveBoat(mi);
c2->mondir = revhint(cwt.at, d);
if(c2->item) boatmove = !boatmove;
2017-03-23 10:53:57 +00:00
goto boatjump;
2016-08-26 09:58:03 +00:00
}
escape:
2019-05-28 23:09:38 +00:00
if(c2->wall == waBigStatue && !c2->monst && !nonAdjacentPlayer(c2, cwt.at) && fmsMove) {
if(!canPushStatueOn(cwt.at)) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
if(isFire(cwt.at))
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You have to escape first!"));
else
addMessage(XLAT("There is not enough space!"));
return false;
}
2017-03-23 10:53:57 +00:00
if(havePushConflict(cwt.at, checkonly)) return false;
2017-03-23 10:53:57 +00:00
eWall save_c2 = c2->wall;
eWall save_cw = cwt.at->wall;
c2->wall = cwt.at->wall;
if(doesnotFall(cwt.at))
cwt.at->wall = waBigStatue;
2017-03-23 10:53:57 +00:00
if(monstersnear(c2,NULL,moPlayer,NULL,cwt.at)) {
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs) wouldkill("%The1 would kill you there!");
c2->wall = save_c2; cwt.at->wall = save_cw;
2017-03-23 10:53:57 +00:00
return false;
}
2019-05-28 23:09:38 +00:00
if(checkonly) { c2->wall = save_c2; cwt.at->wall = save_cw; nextmovetype = lmMove; return true; }
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You push %the1 behind you!", waBigStatue));
2019-11-22 17:48:51 +00:00
animateMovement(mi.rev(), LAYER_BOAT);
2017-03-23 10:53:57 +00:00
goto statuejump;
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
2017-07-22 23:33:27 +00:00
bool attackable;
attackable =
c2->wall == waBigTree ||
c2->wall == waSmallTree ||
c2->wall == waMirrorWall;
if(attackable && markOrb(itOrbAether) && c2->wall != waMirrorWall)
attackable = false;
bool nm; nm = attackable;
2019-05-28 23:09:38 +00:00
if(forcedmovetype == fmAttack) attackable = true;
attackable = attackable && (!c2->monst || isFriendly(c2));
attackable = attackable && !nonAdjacentPlayer(cwt.at,c2);
2017-07-22 23:33:27 +00:00
2019-05-28 23:09:38 +00:00
if(attackable && fmsAttack) {
2016-08-26 09:58:03 +00:00
if(checkNeedMove(checkonly, true)) return false;
if(monstersnear(cwt.at,c2,moPlayer,NULL,cwt.at)) {
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs) wouldkill("%The1 would get you!");
return false;
}
if(checkonly) { nextmovetype = nm ? lmAttack : lmSkip; return true; }
2017-07-22 23:33:27 +00:00
if(c2->wall == waSmallTree) {
drawParticles(c2, winf[c2->wall].color, 4);
addMessage(XLAT("You chop down the tree."));
2017-07-22 23:33:27 +00:00
playSound(c2, "hit-axe" + pick123());
c2->wall = waNone;
sideAttack(cwt.at, d, moPlayer, 0);
2019-11-22 15:46:25 +00:00
animateAttack(mi, LAYER_SMALL);
2017-07-22 23:33:27 +00:00
}
else if(c2->wall == waBigTree) {
drawParticles(c2, winf[c2->wall].color, 8);
addMessage(XLAT("You start chopping down the tree."));
2017-07-22 23:33:27 +00:00
playSound(c2, "hit-axe" + pick123());
2017-10-08 09:12:03 +00:00
c2->wall = waSmallTree;
sideAttack(cwt.at, d, moPlayer, 0);
2019-11-22 15:46:25 +00:00
animateAttack(mi, LAYER_SMALL);
2017-07-22 23:33:27 +00:00
}
else {
2017-09-30 09:46:41 +00:00
if(!peace::on) {
2019-05-28 23:09:38 +00:00
if(c2->wall == waMirrorWall)
addMessage(XLAT("You swing your sword at the mirror."));
else if(c2->wall)
addMessage(XLAT("You swing your sword at %the1.", c2->wall));
else
addMessage(XLAT("You swing your sword."));
swing:
sideAttack(cwt.at, d, moPlayer, 0);
2019-11-22 15:46:25 +00:00
animateAttack(mi, LAYER_SMALL);
2017-09-30 09:46:41 +00:00
}
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if(survivalist && isHaunted(c2->land))
survivalist = false;
2017-07-22 23:33:27 +00:00
mirror::act(origd, mirror::SPINMULTI | mirror::ATTACK);
2016-08-26 09:58:03 +00:00
lastmovetype = lmTree; lastmove = c2;
2017-03-23 10:53:57 +00:00
swordAttackStatic();
2016-08-26 09:58:03 +00:00
}
else if(c2->monst == moKnight) {
if(checkonly) return false;
knightFlavorMessage(c2);
return false;
}
2017-07-04 13:38:33 +00:00
else if(c2->monst && (!isFriendly(c2) || c2->monst == moTameBomberbird || isMountable(c2->monst))
&& !(peace::on && !isMultitile(c2->monst) && !goodTortoise)) {
2019-05-28 23:09:38 +00:00
if(!fmsAttack) return false;
2016-08-26 09:58:03 +00:00
flagtype attackflags = AF_NORMAL;
if(items[itOrbSpeed]&1) attackflags |= AF_FAST;
if(items[itOrbSlaying]) attackflags |= AF_CRUSH;
2016-08-26 09:58:03 +00:00
bool ca =canAttack(cwt.at, moPlayer, c2, c2->monst, attackflags);
if(!ca) {
if(forcedmovetype == fmAttack) {
if(monstersnear(cwt.at,c2,moPlayer,NULL,cwt.at)) {
if(!checkonly && errormsgs) wouldkill("%The1 would get you!");
return false;
}
if(checkonly) { nextmovetype = lmSkip; return true; }
addMessage(XLAT("You swing your sword at %the1.", c2->monst));
goto swing;
}
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
if(c2->monst == moWorm || c2->monst == moWormtail || c2->monst == moWormwait)
addMessage(XLAT("You cannot attack Sandworms directly!"));
else if(c2->monst == moHexSnake || c2->monst == moHexSnakeTail)
addMessage(XLAT("You cannot attack Rock Snakes directly!"));
else if(nonAdjacent(c2, cwt.at))
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You cannot attack diagonally!"));
else if(thruVine(c2, cwt.at))
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You cannot attack through the Vine!"));
else if(c2->monst == moTentacle || c2->monst == moTentacletail || c2->monst == moTentaclewait || c2->monst == moTentacleEscaping)
addMessage(XLAT("You cannot attack Tentacles directly!"));
else if(c2->monst == moHedge && !markOrb(itOrbThorns)) {
addMessage(XLAT("You cannot attack %the1 directly!", c2->monst));
addMessage(XLAT("Stab them by walking around them."));
}
2017-03-23 10:53:57 +00:00
else if(c2->monst == moRoseBeauty || isBull(c2->monst) || c2->monst == moButterfly)
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You cannot attack %the1!", c2->monst));
else if(c2->monst == moFlailer && !c2->stuntime) {
addMessage(XLAT("You cannot attack %the1 directly!", c2->monst));
addMessage(XLAT("Make him hit himself by walking away from him."));
}
else if(c2->monst == moVizier && c2->hitpoints > 1 && !(attackflags & AF_FAST)) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("You cannot attack %the1 directly!", c2->monst));
addMessage(XLAT("Hit him by walking away from him."));
}
else if(c2->monst == moShadow)
addMessage(XLAT("You cannot defeat the Shadow!"));
else if(c2->monst == moGreater || c2->monst == moGreaterM)
addMessage(XLAT("You cannot defeat the Greater Demon yet!"));
2017-03-23 10:53:57 +00:00
else if(c2->monst == moDraugr)
addMessage(XLAT("Your mundane weapon cannot hurt %the1!", c2->monst));
else if(isRaider(c2->monst))
addMessage(XLAT("You cannot attack Raiders directly!"));
else if(isSwitch(c2->monst))
addMessage(XLAT("You cannot attack Jellies in their wall form!"));
2016-08-26 09:58:03 +00:00
else
addMessage(XLAT("For some reason... cannot attack!"));
return false;
}
// pushto=c2 means that the monster is not destroyed and thus
2017-06-18 16:51:46 +00:00
// still counts for lightning in monstersnear
movei mip(c2, nullptr, NO_SPACE);
2016-08-26 09:58:03 +00:00
cell *pushto = NULL;
if(isStunnable(c2->monst) && c2->hitpoints > 1) {
2017-06-18 16:51:46 +00:00
if(monsterPushable(c2))
mip = determinePush(cwt, subdir, [c2] (cell *c) { return passable(c, c2, P_BLOW); });
else
mip.t = c2;
2016-08-26 09:58:03 +00:00
}
if(c2->monst == moTroll || c2->monst == moFjordTroll ||
c2->monst == moForestTroll || c2->monst == moStormTroll || c2->monst == moVineSpirit)
mip.t = c2;
2016-08-26 09:58:03 +00:00
global_pushto = mip.t;
2017-03-23 10:53:57 +00:00
if(havePushConflict(mip.t, checkonly)) return false;
2017-03-23 10:53:57 +00:00
if(!(isWatery(cwt.at) && c2->monst == moWaterElemental) && checkNeedMove(checkonly, true))
2017-03-23 10:53:57 +00:00
return false;
if(monstersnear(cwt.at, c2, moPlayer, pushto, cwt.at)) {
2017-03-23 10:53:57 +00:00
if(errormsgs && !checkonly)
wouldkill("You would be killed by %the1!");
2016-08-26 09:58:03 +00:00
return false;
}
2015-08-08 13:57:52 +00:00
if(c2->monst == moTameBomberbird && warningprotection_hit(moTameBomberbird)) return false;
2016-08-26 09:58:03 +00:00
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmAttack; return true; }
2016-08-26 09:58:03 +00:00
/* if(c2->monst == moTortoise) {
printf("seek=%d get=%d <%x/%x> item=%d\n",
tortoise::seeking,
!tortoise::diff(tortoise::getb(c2)),
tortoise::getb(c2) & tortoise::mask,
tortoise::seekbits & tortoise::mask,
!c2->item);
} */
2017-07-22 23:33:27 +00:00
mirror::act(origd, mirror::SPINMULTI | mirror::ATTACK);
int tk = tkills();
2017-07-22 23:33:27 +00:00
2017-07-04 13:38:33 +00:00
if(goodTortoise) {
2016-08-26 09:58:03 +00:00
items[itBabyTortoise] += 4;
updateHi(itBabyTortoise, items[itBabyTortoise]);
c2->item = itBabyTortoise;
tortoise::babymap[c2] = tortoise::seekbits;
2017-03-23 10:53:57 +00:00
playSound(c2, playergender() ? "heal-princess" : "heal-prince");
2016-08-26 09:58:03 +00:00
addMessage(XLAT(playergender() == GEN_F ? "You are now a tortoise heroine!" : "You are now a tortoise hero!"));
c2->stuntime = 2;
2019-11-03 12:56:42 +00:00
achievement_collection(itBabyTortoise);
2016-08-26 09:58:03 +00:00
}
else {
eMonster m = c2->monst;
2017-07-22 23:33:27 +00:00
if(m) {
if((attackflags & AF_CRUSH) && !canAttack(cwt.at, moPlayer, c2, c2->monst, attackflags ^ AF_CRUSH ^ AF_MUSTKILL))
markOrb(itOrbSlaying);
2018-01-25 22:22:33 +00:00
if(c2->monst == moTerraWarrior && hrand(100) > 2 * items[itTerra]) {
if(hrand(2 + jiangshi_on_screen) < 2)
wandering_jiangshi++;
}
attackMonster(c2, attackflags | AF_MSG, moPlayer);
// salamanders are stunned for longer time when pushed into a wall
if(c2->monst == moSalamander && (pushto == c2 || !pushto)) c2->stuntime = 10;
if(!c2->monst) produceGhost(c2, m, moPlayer);
if(mip.proper()) pushMonster(mip);
2019-11-22 15:46:25 +00:00
animateAttack(mi, LAYER_SMALL);
2017-07-22 23:33:27 +00:00
}
2016-08-26 09:58:03 +00:00
}
sideAttack(cwt.at, d, moPlayer, tkills() - tk);
2016-08-26 09:58:03 +00:00
lastmovetype = lmAttack; lastmove = c2;
2017-03-23 10:53:57 +00:00
swordAttackStatic();
2016-08-26 09:58:03 +00:00
}
else if(!passable(c2, cwt.at, P_USEBOAT | P_ISPLAYER | P_MIRROR | P_MONSTER)) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
if(nonAdjacent(cwt.at,c2))
2016-08-26 09:58:03 +00:00
addMessage(XLAT(
2018-08-20 13:24:44 +00:00
geosupport_football() < 2 ?
2016-08-26 09:58:03 +00:00
"You cannot move between the cells without dots here!" :
"You cannot move between the triangular cells here!"
));
else if(againstWind(c2, cwt.at))
addMessage(XLAT(airdist(c2) < 3 ? "The Air Elemental blows you away!" : "You cannot go against the wind!"));
2016-08-26 09:58:03 +00:00
else if(isAlch(c2))
addMessage(XLAT("Wrong color!"));
else if(c2->wall == waRoundTable)
addMessage(XLAT("It would be impolite to land on the table!"));
else if(snakelevel(cwt.at) >= 3 && snakelevel(c2) == 0)
2017-03-23 10:53:57 +00:00
addMessage(XLAT("You would get hurt!", c2->wall));
else if(cellEdgeUnstable(cwt.at) && cellEdgeUnstable(c2)) {
2016-08-26 09:58:03 +00:00
addMessage(XLAT("Gravity does not allow this!"));
}
2017-10-30 08:11:47 +00:00
else if(c2->wall == waChasm && c2->land == laDual)
addMessage(XLAT("You cannot move there!"));
else if(!c2->wall)
addMessage(XLAT("You cannot move there!"));
2016-08-26 09:58:03 +00:00
else {
addMessage(XLAT("You cannot move through %the1!", c2->wall));
}
return false;
}
2019-05-28 23:09:38 +00:00
else if(fmsMove) {
if(mineMarked(c2) && !minesafe() && !checkonly && warningprotection(XLAT("Are you sure you want to step there?")))
2016-08-26 09:58:03 +00:00
return false;
2019-10-26 12:47:22 +00:00
if(snakelevel(c2) <= snakelevel(cwt.at)-2) {
bool can_leave = false;
forCellEx(c3, c2) if(passable(c3, c2, P_ISPLAYER | P_MONSTER)) can_leave = true;
if(!can_leave && !checkonly && warningprotection(XLAT("Are you sure you want to step there?")))
return false;
}
if(monstersnear(c2, NULL, moPlayer, NULL, cwt.at)) {
2016-08-26 09:58:03 +00:00
if(checkonly) return false;
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(items[itOrbFlash]) {
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmInstant; return true; }
if(orbProtection(itOrbFlash)) return true;
2016-08-26 09:58:03 +00:00
activateFlash();
checkmove();
return true;
}
2015-08-08 13:57:52 +00:00
2016-08-26 09:58:03 +00:00
if(items[itOrbLightning]) {
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmInstant; return true; }
if(orbProtection(itOrbLightning)) return true;
2016-08-26 09:58:03 +00:00
activateLightning();
checkmove();
return true;
}
2015-08-08 13:57:52 +00:00
if(who_kills_me == moOutlaw && items[itRevolver]) {
2016-08-26 09:58:03 +00:00
for(int i=0; i<c2->type; i++) {
cell *c3 = c2->move(i);
2016-08-26 09:58:03 +00:00
if(c3) for(int i=0; i<c3->type; i++) {
cell *c4 = c3->move(i);
2016-08-26 09:58:03 +00:00
if(c4 && c4->monst == moOutlaw) {
eItem i = targetRangedOrb(c4, roCheck);
if(i == itRevolver) {
targetRangedOrb(c4, roKeyboard);
return false;
}
}
}
}
}
2015-08-08 13:57:52 +00:00
2017-03-23 10:53:57 +00:00
if(!checkonly && errormsgs)
wouldkill("%The1 would kill you there!");
2016-08-26 09:58:03 +00:00
return false;
}
if(switchplace_prevent(cwt.at, c2, checkonly)) return false;
if(!checkonly && warningprotection_hit(do_we_stab_a_friend(cwt.at, c2, moPlayer)))
return false;
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmMove; return true; }
2017-03-23 10:53:57 +00:00
boatjump:
statuejump:
flipplayer = true; if(multi::players > 1) multi::flipped[multi::cpid] = true;
if(c2->item && isAlch(c2)) {
if(cwt.at->wall == waBoat)
c2->wall = waNone;
else
c2->wall = cwt.at->wall;
}
2016-08-26 09:58:03 +00:00
if(c2->wall == waRoundTable) {
addMessage(XLAT("You jump over the table!"));
}
if(cwt.at->wall == waRoundTable)
2016-08-26 09:58:03 +00:00
roundTableMessage(c2);
invismove = (turncount >= noiseuntil) && items[itOrbInvis] > 0;
if(items[itOrbFire]) {
invismove = false;
if(makeflame(cwt.at, 10, false)) markOrb(itOrbFire);
2016-08-26 09:58:03 +00:00
}
2016-01-02 10:09:13 +00:00
if(1) {
bool haveIvy = false;
forCellEx(c3, cwt.at) if(c3->monst == moFriendlyIvy) haveIvy = true;
bool killIvy = haveIvy;
if(items[itOrbNature]) {
if(c2->monst != moFriendlyIvy && strictlyAgainstGravity(c2, cwt.at, false, MF_IVY)) {
invismove = false;
}
else if(cwt.at->monst) invismove = false;
else if(haveIvy || !cellEdgeUnstable(cwt.at, MF_IVY)) {
cwt.at->monst = moFriendlyIvy;
cwt.at->mondir = neighborId(cwt.at, c2);
invismove = false;
markOrb(itOrbNature);
killIvy = false;
}
2017-03-23 10:53:57 +00:00
}
if(killIvy) killFriendlyIvy();
2017-03-23 10:53:57 +00:00
}
2016-08-26 09:58:03 +00:00
if(items[itOrbDigging]) {
invismove = false;
if(earthMove(mi)) markOrb(itOrbDigging);
2016-08-26 09:58:03 +00:00
}
2015-08-08 13:57:52 +00:00
movecost(cwt.at, c2, 1);
2016-08-26 09:58:03 +00:00
if(!boatmove && collectItem(c2)) return true;
2017-12-30 23:08:55 +00:00
if(doPickupItemsWithMagnetism(c2)) return true;
2015-08-08 13:57:52 +00:00
if(isIcyLand(cwt.at) && cwt.at->wall == waNone && markOrb(itOrbWinter)) {
2016-08-26 09:58:03 +00:00
invismove = false;
cwt.at->wall = waIcewall;
2016-08-26 09:58:03 +00:00
}
if(items[itOrbWinter])
forCellEx(c3, c2) if(c3->wall == waIcewall && c3->item)
markOrb(itOrbWinter), collectItem(c3);
movecost(cwt.at, c2, 2);
2015-08-08 13:57:52 +00:00
handle_switchplaces(cwt.at, c2, switchplaces);
2016-08-26 09:58:03 +00:00
mountjump:
lastmovetype = lmMove; lastmove = cwt.at;
2016-01-02 10:09:13 +00:00
stabbingAttack(cwt.at, c2, moPlayer);
cell *c1 = cwt.at;
2018-03-24 11:59:01 +00:00
cwt += wstep;
if(switchplaces) {
2019-11-22 17:48:51 +00:00
indAnimateMovement(mi, LAYER_SMALL);
indAnimateMovement(mi.rev(), LAYER_SMALL);
commitAnimations(LAYER_SMALL);
}
2017-03-23 10:53:57 +00:00
else
2019-11-22 17:48:51 +00:00
animateMovement(mi, LAYER_SMALL);
current_display->which_copy = current_display->which_copy * adj(mi);
2016-08-26 09:58:03 +00:00
2017-07-22 23:33:27 +00:00
mirror::act(origd, mirror::SPINMULTI | mirror::ATTACK | mirror::GO);
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
playerMoveEffects(c1, c2);
2016-01-02 10:09:13 +00:00
2017-03-23 10:53:57 +00:00
if(c2->monst == moFriendlyIvy) c2->monst = moNone;
2016-08-26 09:58:03 +00:00
countLocalTreasure();
landvisited[cwt.at->land] = true;
2017-03-23 10:53:57 +00:00
afterplayermoved();
2016-01-02 10:09:13 +00:00
}
2019-05-28 23:09:38 +00:00
else return false;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
else {
if(items[itOrbGravity]) {
gravity_state = get_static_gravity(cwt.at);
if(gravity_state) markOrb(itOrbGravity);
}
2016-08-26 09:58:03 +00:00
lastmovetype = lmSkip; lastmove = NULL;
if(checkNeedMove(checkonly, false))
return false;
if(monstersnear(cwt.at, NULL, moPlayer, NULL, cwt.at)) {
2017-03-23 10:53:57 +00:00
if(errormsgs && !checkonly)
wouldkill("%The1 would get you!");
2016-08-26 09:58:03 +00:00
return false;
2015-08-08 13:57:52 +00:00
}
2019-05-28 23:09:38 +00:00
if(checkonly) { nextmovetype = lmSkip; return true; }
2017-03-23 10:53:57 +00:00
swordAttackStatic();
2016-08-26 09:58:03 +00:00
if(d == -2)
dropGreenStone(cwt.at);
if(cellUnstable(cwt.at) && !markOrb(itOrbAether))
doesFallSound(cwt.at);
if(last_gravity_state && !gravity_state)
playerMoveEffects(cwt.at, cwt.at);
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
invisfish = false;
if(items[itOrbFish]) {
invisfish = true;
for(int i=0; i<numplayers(); i++)
2017-03-23 10:53:57 +00:00
if(multi::playerActive(i) && !isWatery(playerpos(i)))
2016-08-26 09:58:03 +00:00
invisfish = false;
2017-03-23 10:53:57 +00:00
if(d < 0) invisfish = false; // no invisibility if staying still
2016-08-26 09:58:03 +00:00
if(invisfish) invismove = true, markOrb(itOrbFish);
}
2017-03-23 10:53:57 +00:00
last_gravity_state = gravity_state;
2017-03-23 10:53:57 +00:00
if(multi::players == 1) monstersTurn();
2015-08-08 13:57:52 +00:00
save_memory();
2017-07-16 21:00:55 +00:00
check_total_victory();
if(items[itWhirlpool] && cwt.at->land != laWhirlpool && !whirlpool::escaped) {
2016-08-26 09:58:03 +00:00
whirlpool::escaped = true;
achievement_gain("WHIRL1");
2016-01-02 10:09:13 +00:00
}
if(items[itLotus] >= 25 && !isHaunted(cwt.at->land) && survivalist && !got_survivalist) {
got_survivalist = true;
2016-08-26 09:58:03 +00:00
achievement_gain("SURVIVAL");
2015-08-08 13:57:52 +00:00
}
if(seenSevenMines && cwt.at->land != laMinefield) {
2016-08-26 09:58:03 +00:00
seenSevenMines = false;
achievement_gain("SEVENMINE");
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
2019-05-12 23:57:40 +00:00
DEBB(DF_TURN, ("done"));
2016-08-26 09:58:03 +00:00
return true;
2015-08-08 13:57:52 +00:00
}
2019-08-10 00:16:48 +00:00
#if HDR
inline bool movepcto(const movedir& md) { return movepcto(md.d, md.subdir); }
#endif
2016-08-26 09:58:03 +00:00
/* bool isPsiTarget(cell *dst) {
return
dst->cpdist > 1 &&
dst->monst &&
!(isWorm(dst) || dst->monst == moShadow);
2017-03-23 10:53:57 +00:00
} */
2015-08-08 13:57:52 +00:00
2019-08-09 19:00:52 +00:00
EX void moveItem1(cell *from, cell *to, bool activateYendor) {
2016-08-26 09:58:03 +00:00
if(from->item == itOrbYendor) {
bool xnew = true;
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(yendor::yi); i++)
2016-08-26 09:58:03 +00:00
if(yendor::yi[i].path[0] == from) xnew = false;
2017-03-23 10:53:57 +00:00
if(xnew && activateYendor) yendor::check(from);
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(yendor::yi); i++)
2016-08-26 09:58:03 +00:00
if(yendor::yi[i].path[0] == from)
yendor::yi[i].path[0] = to;
2015-08-08 13:57:52 +00:00
}
2016-08-26 09:58:03 +00:00
if(from->item == itKey) {
2018-06-22 12:47:24 +00:00
for(int i=0; i<isize(yendor::yi); i++) if(yendor::yi[i].path[YDIST-1] == from)
2016-08-26 09:58:03 +00:00
yendor::yi[i].path[YDIST-1] = to;
for(int i=0; i<isize(yendor::yi); i++) if(yendor::yi[i].actualKey == from)
yendor::yi[i].actualKey = to;
2017-03-23 10:53:57 +00:00
}
if(from->item == itBabyTortoise) {
tortoise::babymap[to] = tortoise::babymap[from];
tortoise::babymap.erase(from);
}
2016-01-02 10:09:13 +00:00
2016-08-26 09:58:03 +00:00
eItem i = to->item;
to->item = from->item;
from->item = i;
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX void moveItem (cell *from, cell *to, bool activateYendor) {
2017-03-23 10:53:57 +00:00
static cell dummy;
dummy.item = itNone;
moveItem1(from, &dummy, activateYendor);
moveItem1(to, from, activateYendor);
moveItem1(&dummy, to, activateYendor);
}
2019-08-09 19:00:52 +00:00
EX void fixWormBug(cell *c) {
if(history::includeHistory) return;
2017-03-23 10:53:57 +00:00
printf("worm bug!\n");
if(c->monst == moWormtail) c->monst = moWormwait;
if(c->monst == moTentacletail || c->monst == moTentacleGhost) c->monst = moTentacle;
if(c->monst == moHexSnakeTail) c->monst = moHexSnake;
}
2019-08-09 19:00:52 +00:00
EX cell *wormhead(cell *c) {
2016-08-26 09:58:03 +00:00
// cell *cor = c;
findhead:
if(c->monst == moTentacle || c->monst == moWorm || c->monst == moHexSnake ||
c->monst == moWormwait || c->monst == moTentacleEscaping || c->monst == moTentaclewait ||
c->monst == moDragonHead) return c;
for(int i=0; i<c->type; i++)
if(c->move(i) && isWorm(c->move(i)->monst) && c->move(i)->mondir == c->c.spin(i)) {
c = c->move(i); goto findhead;
2016-08-26 09:58:03 +00:00
}
2017-03-23 10:53:57 +00:00
fixWormBug(c);
2016-08-26 09:58:03 +00:00
return c;
}
2016-01-02 10:09:13 +00:00
2019-08-09 19:00:52 +00:00
EX int wormpos(cell *c) {
2017-03-23 10:53:57 +00:00
// cell *cor = c;
int cnt = 0;
findhead:
if(c->monst == moTentacle || c->monst == moWorm || c->monst == moHexSnake ||
c->monst == moWormwait || c->monst == moTentacleEscaping || c->monst == moTentaclewait ||
c->monst == moDragonHead) return cnt;
for(int i=0; i<c->type; i++)
if(c->move(i) && isWorm(c->move(i)->monst) && c->move(i)->mondir == c->c.spin(i)) {
c = c->move(i); cnt++; goto findhead;
2017-03-23 10:53:57 +00:00
}
fixWormBug(c);
return cnt;
}
2016-08-26 09:58:03 +00:00
// currently works for worms only
2019-08-09 19:00:52 +00:00
EX bool sameMonster(cell *c1, cell *c2) {
2018-02-27 22:43:21 +00:00
if(!c1 || !c2) return false;
2016-08-26 09:58:03 +00:00
if(c1 == c2) return true;
if(isWorm(c1->monst) && isWorm(c2->monst))
return wormhead(c1) == wormhead(c2);
2017-03-23 10:53:57 +00:00
if(isKraken(c1->monst) && isKraken(c2->monst))
return kraken::head(c1) == kraken::head(c2);
2016-08-26 09:58:03 +00:00
return false;
}
2019-08-09 19:00:52 +00:00
EX eMonster haveMount() {
2017-03-23 10:53:57 +00:00
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i)) {
2018-02-27 22:43:21 +00:00
eMonster m = playerpos(i)->monst;
2017-03-23 10:53:57 +00:00
if(m) return m;
}
return moNone;
}
2019-08-09 19:00:52 +00:00
EX bool mightBeMine(cell *c) {
2017-03-23 10:53:57 +00:00
return c->wall == waMineUnknown || c->wall == waMineMine;
}
2019-09-03 06:26:01 +00:00
EX hookset<bool(cell*)> *hooks_mark;
2019-08-09 19:00:52 +00:00
EX void performMarkCommand(cell *c) {
if(!c) return;
if(callhandlers(false, hooks_mark, c)) return;
2017-03-23 10:53:57 +00:00
if(c->land == laCA && c->wall == waNone)
c->wall = waFloorA;
else if(c->land == laCA && c->wall == waFloorA)
c->wall = waNone;
if(c->land != laMinefield) return;
if(c->item) return;
if(!mightBeMine(c)) return;
bool adj = false;
forCellEx(c2, c) if(c2->wall == waMineOpen) adj = true;
if(adj) c->landparam ^= 1;
}
2019-08-09 19:00:52 +00:00
EX bool mineMarked(cell *c) {
2017-03-23 10:53:57 +00:00
if(!mightBeMine(c)) return false;
if(c->item) return false;
if(c->land != laMinefield) return true;
return c->landparam & 1;
}
2019-08-09 19:00:52 +00:00
EX bool mineMarkedSafe(cell *c) {
2017-03-23 10:53:57 +00:00
if(!mightBeMine(c)) return false;
if(c->item) return true;
if(c->land != laMinefield) return false;
return c->landparam & 2;
}
2019-08-09 19:00:52 +00:00
EX bool minesafe() {
2017-03-23 10:53:57 +00:00
return items[itOrbAether];
}
2019-08-09 19:00:52 +00:00
EX bool warningprotection(const string& s) {
2017-03-23 10:53:57 +00:00
if(hardcore) return false;
if(multi::activePlayers() > 1) return false;
if(items[itWarning]) return false;
pushScreen([s] () {
gamescreen(1);
dialog::addBreak(250);
dialog::init(XLAT("WARNING"), 0xFF0000, 150, 100);
dialog::addBreak(500);
dialog::addInfo(s);
dialog::addBreak(500);
dialog::addItem(XLAT("YES"), 'y');
dialog::lastItem().scale = 200;
auto yes = [] () { items[itWarning] = 1; popScreen(); };
dialog::add_action(yes);
dialog::add_key_action(SDLK_RETURN, yes);
dialog::addItem(XLAT("NO"), 'n');
dialog::lastItem().scale = 200;
dialog::add_action([] () { items[itWarning] = 0; popScreen(); });
dialog::display();
});
2017-03-23 10:53:57 +00:00
return true;
2015-08-08 13:57:52 +00:00
}
2016-01-02 10:09:13 +00:00
}