2016-08-26 09:58:03 +00:00
|
|
|
// Hyperbolic Rogue
|
|
|
|
|
|
|
|
// namespaces for complex features (whirlwind, whirlpool, elec, princess, clearing,
|
2017-10-08 10:10:40 +00:00
|
|
|
// mirror, hive, heat + livecaves, etc.)
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2018-02-08 23:40:26 +00:00
|
|
|
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace whirlwind {
|
|
|
|
|
|
|
|
int fzebra3(cell *c) {
|
|
|
|
if(euclid) {
|
2017-06-09 01:41:33 +00:00
|
|
|
if(torus) return 0;
|
2017-12-28 15:46:10 +00:00
|
|
|
int x, y;
|
|
|
|
tie(x,y) = cell_to_pair(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
return 1+((((signed short)(y)+int(50000))/3)%3);
|
|
|
|
}
|
2017-11-03 19:55:41 +00:00
|
|
|
if(S7 == 5) return getHemisphere(c, 0) > 0 ? 1 : 2;
|
|
|
|
if(S7 < 5) {
|
|
|
|
int d = celldistance(currentmap->gamestart(), c);
|
|
|
|
if(d == 0) return 0;
|
|
|
|
if(S7 == 4 && d == 3) return 0;
|
|
|
|
if(S7 == 3 && d == 2 && !ctof(c)) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
return zebra3(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void switchTreasure(cell *c) {
|
|
|
|
c->item = itNone;
|
|
|
|
if(safety) return;
|
|
|
|
if(hrand(5000) < PT(100 + 2 * (kills[moAirElemental] + kills[moWindCrow]), 200) && notDippingFor(itWindstone)
|
|
|
|
&& getGhostcount() < 2)
|
|
|
|
c->item = itWindstone;
|
|
|
|
else if(hrand(5000) < 20*PRIZEMUL)
|
|
|
|
placeLocalOrbs(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cat(cell *c) {
|
|
|
|
if(c->land != laWhirlwind) return 0;
|
|
|
|
if(c->wall != waNone && c->wall != waChasm &&
|
|
|
|
c->wall != waSea && !isAlchAny(c) &&
|
|
|
|
c->wall != waMineMine && c->wall != waFire) return 0;
|
|
|
|
if(c->item == itKey || c->item == itOrbYendor) return 0;
|
|
|
|
if(airdist(c) < 3) return 0;
|
|
|
|
if(c->monst == moHexSnake || c->monst == moHexSnakeTail) return 0;
|
|
|
|
return fzebra3(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *where;
|
|
|
|
int dfrom[2], dto[2], qdirs;
|
|
|
|
|
|
|
|
int gdist(int d, int e) { return dirdiff(d-e, where->type); }
|
|
|
|
|
|
|
|
void calcdirs(cell *c) {
|
|
|
|
where = c;
|
|
|
|
int d = cat(c);
|
|
|
|
qdirs = 0;
|
|
|
|
if(d == 0) return;
|
|
|
|
int qdf = 0, qdt = 0;
|
2017-10-27 18:07:58 +00:00
|
|
|
int cats[MAX_EDGE];
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=0; i<c->type; i++)
|
|
|
|
cats[i] = cat(createMov(c,i));
|
|
|
|
for(int i=0; i<c->type; i++)
|
|
|
|
if(cats[i] == d) {
|
|
|
|
bool c1 = (cats[(i+1)%c->type] != d);
|
|
|
|
bool c2 = (cats[(i+c->type-1)%c->type] != d);
|
|
|
|
if(c1 && !c2) dto[qdt++] = i;
|
|
|
|
if(c2 && !c1) dfrom[qdf++] = i;
|
|
|
|
}
|
|
|
|
qdirs = qdf;
|
|
|
|
if(qdirs == 2) {
|
|
|
|
int cur = gdist(dfrom[0], dto[0]) + gdist(dfrom[1], dto[1]);
|
|
|
|
int alt = gdist(dfrom[0], dto[1]) + gdist(dfrom[1], dto[0]);
|
|
|
|
if(alt < cur) swap(dto[0], dto[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int mindist(int d, int *tab) {
|
|
|
|
if(qdirs == 0) return NODIR;
|
|
|
|
if(qdirs == 1) return gdist(d, tab[0]);
|
|
|
|
return min(gdist(d, tab[0]), gdist(d, tab[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
int winddir(int d) {
|
|
|
|
if(d == -1) return 0;
|
|
|
|
int mdf = mindist(d, dfrom);
|
|
|
|
int mdt = mindist(d, dto);
|
|
|
|
// printf("dir = %d mdf = %d mdt = %d\n", d, mdf, mdt);
|
|
|
|
if(mdf < mdt) return -1;
|
|
|
|
if(mdf > mdt) return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void build(vector<cell*>& whirlline, int d) {
|
|
|
|
again:
|
|
|
|
cell *at = whirlline[size(whirlline)-1];
|
|
|
|
cell *prev = whirlline[size(whirlline)-2];
|
|
|
|
for(int i=0; i<at->type; i++)
|
|
|
|
if(at->mov[i] && (euclid || at->mov[i]->master->alt) && celldistAlt(at->mov[i]) == d && at->mov[i] != prev) {
|
|
|
|
whirlline.push_back(at->mov[i]);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveAt(cell *c) {
|
|
|
|
if(eq(c->aitmp, sval)) return;
|
|
|
|
calcdirs(c);
|
|
|
|
if(qdirs != 1) return;
|
|
|
|
vector<cell*> whirlline;
|
|
|
|
whirlline.push_back(c);
|
|
|
|
cell *prev = c;
|
|
|
|
cell *c2 = c->mov[dfrom[0]];
|
|
|
|
while(true) {
|
|
|
|
// printf("c = %p dist = %d\n", c2, c2->mpdist);
|
|
|
|
if(c == c2) break;
|
|
|
|
calcdirs(c2);
|
|
|
|
if(qdirs == 0) break;
|
|
|
|
cell *cc2 = c2;
|
|
|
|
if(qdirs == 1) whirlline.push_back(c2), c2 = c2->mov[dfrom[0]];
|
|
|
|
else if(c2->mov[dto[0]] == prev)
|
|
|
|
c2 = c2->mov[dfrom[1]];
|
|
|
|
else
|
|
|
|
c2 = c2->mov[dfrom[0]];
|
|
|
|
prev = cc2;
|
|
|
|
}
|
|
|
|
int z = size(whirlline);
|
|
|
|
// printf("Cycle built from %p, length = %d\n", c, z);
|
|
|
|
for(int i=0; i<z; i++) {
|
|
|
|
// printf("%d%c", whirlline[i]->mpdist, whirlline[i]->item ? '*' : ' ');
|
|
|
|
whirlline[i]->aitmp = sval;
|
|
|
|
if(whirlline[i]->mpdist == BARLEV)
|
|
|
|
switchTreasure(whirlline[i]);
|
|
|
|
}
|
|
|
|
for(int i=0; i<z-1; i++) {
|
|
|
|
moveItem(whirlline[i], whirlline[i+1], true);
|
2017-03-23 10:53:57 +00:00
|
|
|
if(whirlline[i]->item)
|
|
|
|
animateMovement(whirlline[i+1], whirlline[i], LAYER_BOAT);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
for(int i=0; i<z; i++)
|
2017-12-30 22:47:10 +00:00
|
|
|
pickupMovedItems(whirlline[i]);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void move() {
|
|
|
|
sval++;
|
|
|
|
for(int i=0; i<size(dcal); i++) {
|
|
|
|
cell *c = dcal[i];
|
|
|
|
moveAt(c);
|
|
|
|
}
|
|
|
|
// Keys and Orbs of Yendor always move
|
|
|
|
using namespace yendor;
|
|
|
|
for(int i=0; i<size(yi); i++) {
|
|
|
|
moveAt(yi[i].path[0]);
|
|
|
|
moveAt(yi[i].path[YDIST-1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *jumpFromWhereTo(cell *c, bool player) {
|
|
|
|
for(int i=0; i<2; i++) {
|
|
|
|
calcdirs(c);
|
|
|
|
if(qdirs != 1) return NULL;
|
|
|
|
cell *c2 = c->mov[dfrom[0]];
|
|
|
|
if(!passable(c, c2, P_JUMP1)) return NULL;
|
|
|
|
if(player && i == 0 && !passable(c, c2, P_ISPLAYER)) return NULL;
|
|
|
|
c = c2;
|
|
|
|
}
|
|
|
|
calcdirs(c);
|
|
|
|
if(qdirs != 1) return NULL;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *jumpDestination(cell *c) {
|
|
|
|
for(int i=0; i<2; i++) {
|
|
|
|
calcdirs(c);
|
|
|
|
if(qdirs != 1) return NULL;
|
|
|
|
c = c->mov[dto[0]];
|
|
|
|
}
|
|
|
|
calcdirs(c);
|
|
|
|
if(qdirs != 1) return NULL;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace elec {
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
bool havecharge, haveelec, havethunder;
|
2016-08-26 09:58:03 +00:00
|
|
|
bool afterOrb; // extra charge from the Orb of Lightning
|
|
|
|
|
|
|
|
enum eCharge {
|
|
|
|
ecCharged, ecGrounded, ecIsolator, ecConductor
|
|
|
|
};
|
|
|
|
|
|
|
|
bool conduct(eCharge cf, eCharge ct) {
|
|
|
|
if(ct == ecIsolator) return false;
|
|
|
|
if(ct == ecConductor) return true;
|
|
|
|
return ct != cf;
|
|
|
|
}
|
|
|
|
|
|
|
|
eCharge getCharge(cell *c) {
|
|
|
|
bool ao = afterOrb && c->ligon;
|
|
|
|
|
|
|
|
if(c->wall == waCharged) return ecCharged;
|
|
|
|
if(c->wall == waSea || c->wall == waGrounded) return ecGrounded;
|
|
|
|
if(c->wall == waSandstone || c->wall == waDeadTroll ||
|
2017-03-23 10:53:57 +00:00
|
|
|
c->wall == waDeadTroll2 ||
|
2016-08-26 09:58:03 +00:00
|
|
|
c->wall == waVinePlant ||
|
|
|
|
c->wall == waMetal || isAlchAny(c))
|
|
|
|
return c->land == laStorms ? ecConductor : ecGrounded;
|
|
|
|
if(c->wall == waBarrier)
|
|
|
|
return ecIsolator;
|
|
|
|
if(c->wall == waChasm)
|
|
|
|
return ecIsolator;
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
if(shmup::on ? isPlayerOn(c) : (isPlayerOn(c) || stalemate::isMoveto(c) || (items[itOrbEmpathy] && isFriendly(c)))) {
|
2016-08-26 09:58:03 +00:00
|
|
|
if(items[itOrbShield]) return ecIsolator;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(afterOrb) return ecIsolator;
|
|
|
|
if(!items[itOrbAether]) return c->land == laStorms ? ecConductor : ecGrounded;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if(c->monst && stalemate::moveto) printf("%p: isKilled = %d\n", c, stalemate::isKilled(c));
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
else if(
|
|
|
|
(c->monst || stalemate::isPushto(c))
|
2016-08-26 09:58:03 +00:00
|
|
|
&&
|
2017-03-23 10:53:57 +00:00
|
|
|
(stalemate::isPushto(c) || !stalemate::isKilled(c))
|
2016-08-26 09:58:03 +00:00
|
|
|
&&
|
|
|
|
c->monst != moGhost && c->monst != moIvyDead && c->monst != moIvyNext
|
|
|
|
&& !(isDragon(c->monst) && !c->hitpoints)
|
|
|
|
)
|
|
|
|
return c->land == laStorms ? (ao ? ecCharged : ecConductor) : ecGrounded;
|
|
|
|
|
|
|
|
if(c->land != laStorms)
|
|
|
|
return ecGrounded;
|
|
|
|
|
|
|
|
if(ao) return ecCharged;
|
|
|
|
|
|
|
|
return ecIsolator;
|
|
|
|
}
|
|
|
|
|
|
|
|
// To process conductivity, consider the following graph:
|
|
|
|
|
|
|
|
// - edges are between conductors and adjacent charged/grounded/conductor cells
|
|
|
|
// - all charged cells are connected to one special cell '0'
|
|
|
|
// - all grounded cells are connected to one special cell '1'
|
|
|
|
// - cells '0' and '1' are connected
|
|
|
|
|
|
|
|
// If A and B are in the same biconnected component, then there is a closed circuit,
|
|
|
|
// consisting of all other cells in that component.
|
|
|
|
|
|
|
|
// To find biconnected components, we are using the Hopcroft-Tarjan algorithm.
|
|
|
|
|
|
|
|
struct chargedata {
|
|
|
|
cell *c;
|
|
|
|
int otmp;
|
|
|
|
int lowlink;
|
|
|
|
bool instack;
|
|
|
|
bool fire;
|
|
|
|
};
|
|
|
|
|
|
|
|
vector<chargedata> charges;
|
|
|
|
|
|
|
|
vector<pair<int, int> > xstack;
|
|
|
|
|
|
|
|
vector<cell*> chargecells;
|
|
|
|
|
|
|
|
bool hasdata(cell *c) {
|
|
|
|
return c->aitmp >= 0 && c->aitmp < size(charges) && charges[c->aitmp].c == c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void connect(int from, cell *c) {
|
|
|
|
if(hasdata(c)) {
|
|
|
|
// seen again: set the lowlink
|
|
|
|
if(!charges[c->aitmp].instack) return;
|
|
|
|
// printf("edge %d-%d\n", from, c->aitmp);
|
|
|
|
if(c->aitmp < charges[from].lowlink)
|
|
|
|
charges[from].lowlink = c->aitmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int id = size(charges);
|
|
|
|
charges.push_back(chargedata());
|
2018-01-13 16:09:26 +00:00
|
|
|
|
|
|
|
{chargedata& ch(charges[id]);
|
2016-08-26 09:58:03 +00:00
|
|
|
ch.c = c; ch.otmp = c->aitmp; ch.lowlink = id; c->aitmp = id;
|
|
|
|
ch.instack = true; ch.fire = false;
|
2018-01-13 16:09:26 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
// c->landparam = id;
|
|
|
|
|
|
|
|
// printf("edge %d-%d [%s]\n", from, id, dnameof(c->wall));
|
|
|
|
|
|
|
|
xstack.push_back(make_pair(from, id));
|
|
|
|
|
|
|
|
eCharge chh = getCharge(c);
|
|
|
|
|
|
|
|
if(chh == ecGrounded) {
|
|
|
|
xstack.push_back(make_pair(id, 0));
|
2018-01-13 16:09:26 +00:00
|
|
|
charges[id].lowlink = 0;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
else if(chh == ecCharged) {
|
|
|
|
xstack.push_back(make_pair(id, 1));
|
2018-01-13 16:09:26 +00:00
|
|
|
if(from != 1) charges[id].lowlink = 1;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cell *c2 = c->mov[i];
|
|
|
|
if(!c2) continue;
|
|
|
|
if(c2->aitmp == from) continue;
|
|
|
|
eCharge ct = getCharge(c2);
|
|
|
|
if(conduct(chh, ct))
|
|
|
|
connect(id, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf("lowlink of %d [%s] = %d\n", id, dnameof(c->wall), ch.lowlink);
|
2018-01-13 16:09:55 +00:00
|
|
|
if(charges[id].lowlink < charges[from].lowlink)
|
|
|
|
charges[from].lowlink = charges[id].lowlink;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(charges[id].lowlink >= from) {
|
|
|
|
while(xstack.back().first != from || xstack.back().second != id) {
|
|
|
|
// printf("bcc %d,%d\n", xstack.back().first, xstack.back().second);
|
|
|
|
xstack.pop_back();
|
|
|
|
}
|
|
|
|
// printf("bcc %d,%d\n", xstack.back().first, xstack.back().second);
|
|
|
|
xstack.pop_back();
|
|
|
|
// printf("\n");
|
|
|
|
}
|
|
|
|
|
2018-01-13 16:09:26 +00:00
|
|
|
charges[id].instack = false;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void affect(cell *c) {
|
|
|
|
c->ligon = true;
|
|
|
|
if(c->monst) {
|
|
|
|
if(c->monst == moMetalBeast2 && !c->item)
|
|
|
|
c->item = itFulgurite;
|
2017-03-23 10:53:57 +00:00
|
|
|
killMonster(c, moLightningBolt);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
if(isPlayerOn(c)) {
|
|
|
|
killThePlayerAt(moLightningBolt, c, 0);
|
|
|
|
}
|
|
|
|
if(c->wall == waSandstone)
|
2017-03-23 10:53:57 +00:00
|
|
|
c->wall = waNone, c->item = itFulgurite,
|
|
|
|
drawParticles(c, winf[waSandstone].color, 16);
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c->wall == waDeadTroll) c->wall = waCavefloor;
|
|
|
|
if(c->wall == waDeadTroll2 || isAlchAny(c) || c->wall == waVinePlant)
|
2017-03-23 10:53:57 +00:00
|
|
|
drawParticles(c, winf[c->wall].color, 16),
|
2016-08-26 09:58:03 +00:00
|
|
|
c->wall = waNone;
|
|
|
|
/* if(c->wall == waCharged)
|
|
|
|
c->wall = waMetal; */
|
|
|
|
}
|
|
|
|
|
|
|
|
void listChargedCells(cell *c, eCharge last = ecConductor) {
|
|
|
|
if(eq(c->aitmp, sval)) return;
|
|
|
|
eCharge here = getCharge(c);
|
|
|
|
/* if(c->cpdist <= 2) {
|
|
|
|
printf("monst=%s ", dnameof(c->monst));
|
|
|
|
printf("wall=%s ", dnameof(c->wall));
|
|
|
|
printf("c=%p here=%d last=%d\n", c, here, last);
|
|
|
|
} */
|
|
|
|
if(here == ecIsolator) c->aitmp = sval;
|
|
|
|
if(!conduct(last, here)) return;
|
|
|
|
if(here == ecCharged) chargecells.push_back(c);
|
|
|
|
c->aitmp = sval;
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cell *c2 = c->mov[i];
|
|
|
|
if(c2) listChargedCells(c2, here);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
chargecells.clear();
|
2017-03-23 10:53:57 +00:00
|
|
|
if(!haveelec && !afterOrb) return;
|
2016-08-26 09:58:03 +00:00
|
|
|
sval++;
|
|
|
|
for(int i=0; i<size(dcal); i++) listChargedCells(dcal[i]);
|
|
|
|
|
|
|
|
charges.resize(2);
|
|
|
|
charges[0].lowlink = 0; charges[1].lowlink = 1;
|
|
|
|
if(!havecharge) return;
|
|
|
|
|
|
|
|
xstack.clear();
|
|
|
|
|
|
|
|
for(int i=0; i<size(chargecells); i++)
|
|
|
|
connect(1, chargecells[i]);
|
|
|
|
|
|
|
|
havethunder = charges[1].lowlink == 0;
|
|
|
|
if(havethunder) {
|
|
|
|
for(int i=0; i<size(xstack); i++) {
|
|
|
|
int k = xstack[i].first;
|
|
|
|
int l = xstack[i].second;
|
|
|
|
// printf("connected %d-%d\n", k, l);
|
|
|
|
charges[k].fire = true;
|
|
|
|
charges[l].fire = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fire() {
|
|
|
|
if(havethunder) {
|
|
|
|
addMessage(XLAT("There is a flash of thunder!"));
|
2017-03-23 10:53:57 +00:00
|
|
|
playSound(NULL, "storm");
|
2016-08-26 09:58:03 +00:00
|
|
|
drawLightning();
|
|
|
|
for(int i=2; i<size(charges); i++) if(charges[i].fire)
|
|
|
|
affect(charges[i].c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup() {
|
|
|
|
for(int i=2; i<size(charges); i++)
|
|
|
|
charges[i].c->aitmp = charges[i].otmp;
|
|
|
|
charges.resize(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(cell *c, eCharge what) {
|
|
|
|
if(c->ligon) return;
|
|
|
|
c->ligon = true;
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cell *c2 = c->mov[i];
|
|
|
|
if(!c2) continue;
|
|
|
|
eCharge ch = getCharge(c2);
|
|
|
|
if(conduct(what, ch))
|
|
|
|
draw(c2, ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawcharges() {
|
|
|
|
for(int i=0; i<size(dcal); i++)
|
|
|
|
if(getCharge(dcal[i]) == ecCharged)
|
|
|
|
draw(dcal[i], ecCharged);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool affected(cell *c) {
|
|
|
|
if(c->aitmp >= 0 && c->aitmp < size(charges) && charges[c->aitmp].c == c)
|
|
|
|
return charges[c->aitmp].fire;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct builder {
|
|
|
|
builder() { init(); }
|
|
|
|
~builder() { cleanup(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
void act() {
|
|
|
|
int k = tkills();
|
2017-03-23 10:53:57 +00:00
|
|
|
for(int i=0; i<numplayers(); i++)
|
|
|
|
if(multi::playerActive(i) && playerpos(i)->land == laStorms && !afterOrb)
|
|
|
|
markOrb(itOrbShield), markOrb(itOrbAether);
|
2016-08-26 09:58:03 +00:00
|
|
|
builder b;
|
|
|
|
fire();
|
|
|
|
if(!afterOrb)
|
|
|
|
achievement_count("ELEC", tkills() - k, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0 = no close escape, 1 = close escape, 2 = message already shown
|
|
|
|
int lightningfast;
|
|
|
|
void checklightningfast() {
|
|
|
|
if(lightningfast == 1) {
|
|
|
|
addMessage(XLAT("Wow! That was close."));
|
|
|
|
lightningfast = 2;
|
|
|
|
}
|
|
|
|
if(lightningfast > 1) return;
|
|
|
|
builder b;
|
2017-03-23 10:53:57 +00:00
|
|
|
for(int i=0; i<numplayers(); i++)
|
|
|
|
if(multi::playerActive(i) && elec::affected(playerpos(i)))
|
|
|
|
lightningfast = 1;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace princess {
|
|
|
|
|
|
|
|
bool generating = false;
|
|
|
|
bool challenge = false;
|
|
|
|
bool saved = false;
|
|
|
|
bool everSaved = false;
|
|
|
|
|
|
|
|
bool forceVizier = false;
|
|
|
|
bool forceMouse = false;
|
|
|
|
bool gotoPrincess = false;
|
2017-07-16 21:00:55 +00:00
|
|
|
bool nodungeon = false;
|
|
|
|
bool squeaked = false;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
int saveHP = 0, saveArmedHP = 0;
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
int reviveAt;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
vector<info*> infos;
|
|
|
|
|
|
|
|
void assign(info *i) {
|
|
|
|
if(i->alt) i->alt->emeraldval = i->id;
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:55 +00:00
|
|
|
int newInfo(cell *c) {
|
2016-08-26 09:58:03 +00:00
|
|
|
info *i = new info;
|
|
|
|
i->prison = c;
|
|
|
|
i->princess = c;
|
|
|
|
i->alt = c->master->alt;
|
|
|
|
i->id = size(infos);
|
|
|
|
i->bestdist = 0;
|
|
|
|
i->bestnear = OUT_OF_PRISON;
|
|
|
|
infos.push_back(i);
|
|
|
|
assign(i);
|
2017-07-16 21:00:55 +00:00
|
|
|
return i->id;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void newFakeInfo(cell *c) {
|
|
|
|
info *i = new info;
|
|
|
|
i->prison = NULL;
|
|
|
|
i->princess = c;
|
|
|
|
i->alt = NULL;
|
|
|
|
i->id = size(infos);
|
2017-07-16 21:00:55 +00:00
|
|
|
i->bestdist = items[itSavedPrincess] ? OUT_OF_PALACE : OUT_OF_PRISON;
|
2016-08-26 09:58:03 +00:00
|
|
|
i->bestnear = 0;
|
|
|
|
infos.push_back(i);
|
|
|
|
assign(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
info *getPrisonInfo(cell *c) {
|
2017-10-30 21:47:07 +00:00
|
|
|
if(euclid || quotient || sphere) return NULL;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c->land != laPalace) return NULL;
|
|
|
|
if(!c->master->alt) return NULL;
|
2017-07-16 21:00:55 +00:00
|
|
|
int ev = c->master->alt->alt->emeraldval; // NEWYEARFIX
|
2016-08-26 09:58:03 +00:00
|
|
|
if(ev < 0 || ev >= size(infos)) return NULL;
|
|
|
|
if(infos[ev]->alt != c->master->alt->alt) return NULL;
|
|
|
|
return infos[ev];
|
|
|
|
}
|
|
|
|
|
|
|
|
info *getPrincessInfo(cell *c) {
|
|
|
|
for(int i=0; i<size(infos); i++) if(infos[i]->princess == c) {
|
|
|
|
while(i) {
|
|
|
|
infos[i]->id = i-1; assign(infos[i]);
|
|
|
|
infos[i-1]->id = i; assign(infos[i-1]);
|
2017-07-16 21:00:55 +00:00
|
|
|
swap(infos[i], infos[i-1]);
|
2016-08-26 09:58:03 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
return infos[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dist(cell *c) {
|
2017-07-16 21:00:55 +00:00
|
|
|
if(c->land != laPalace && c->land != laDungeon) return OUT_OF_PALACE;
|
2017-06-09 01:41:33 +00:00
|
|
|
else if(quotient || sphere || torus) return OUT_OF_PRISON;
|
2016-08-26 09:58:03 +00:00
|
|
|
else if(euclid) return celldistAlt(c);
|
|
|
|
else if(!c->master->alt) return OUT_OF_PRISON;
|
|
|
|
else return celldistAlt(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
for(int i=0; i<size(infos); i++) delete infos[i];
|
|
|
|
infos.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bringBackAt(cell *c) {
|
|
|
|
if(!c) return false;
|
|
|
|
if(!passable(c, NULL, 0)) return false;
|
|
|
|
c->monst = moPrincessArmed;
|
|
|
|
c->stuntime = 0;
|
|
|
|
c->hitpoints = palaceHP();
|
|
|
|
drawFlash(c);
|
2017-03-23 10:53:57 +00:00
|
|
|
playSound(c, princessgender() ? "heal-princess" : "heal-prince");
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
info *inf = NULL;
|
2017-07-16 21:00:55 +00:00
|
|
|
for(int i=0; i<size(infos); i++) {
|
|
|
|
if(infos[i]->princess && infos[i]->bestdist == OUT_OF_PALACE && isPrincess(infos[i]->princess->monst))
|
2016-08-26 09:58:03 +00:00
|
|
|
inf = infos[i];
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
if(inf) { inf->princess->monst = moNone; inf->princess = c; }
|
|
|
|
else newFakeInfo(c);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bringBack() {
|
|
|
|
if(bringBackAt(cwt.c->mov[cwt.spin])) return;
|
|
|
|
for(int i=1; i<size(dcal); i++)
|
|
|
|
if(bringBackAt(dcal[i])) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setdist(info *i, int newdist) {
|
|
|
|
if(newdist < ALTDIST_ERROR && newdist > i->bestdist) {
|
|
|
|
i->bestdist = newdist;
|
|
|
|
// printf("Improved dist to %d\n", newdist);
|
|
|
|
if(newdist == OUT_OF_PALACE) {
|
|
|
|
if(!princess::saved)
|
2017-07-22 23:33:27 +00:00
|
|
|
#if CAP_INV
|
2017-07-16 21:00:55 +00:00
|
|
|
if(!inv::on || !inv::usedForbidden)
|
|
|
|
#endif
|
2016-08-26 09:58:03 +00:00
|
|
|
achievement_gain("PRINCESS1");
|
|
|
|
princess::saved = true;
|
|
|
|
princess::everSaved = true;
|
2017-07-12 16:03:53 +00:00
|
|
|
if(inv::on && !princess::reviveAt)
|
|
|
|
princess::reviveAt = gold(NO_LOVE);
|
2016-08-26 09:58:03 +00:00
|
|
|
items[itSavedPrincess]++;
|
|
|
|
}
|
|
|
|
if(newdist == OUT_OF_PRISON && princess::challenge) {
|
|
|
|
addMessage(XLAT("Congratulations! Your score is %1.", its(i->value)));
|
|
|
|
achievement_gain("PRINCESS2");
|
|
|
|
if(!cheater) achievement_score(36, i->value);
|
|
|
|
showMissionScreen();
|
|
|
|
}
|
|
|
|
}
|
2017-07-16 21:00:55 +00:00
|
|
|
if(i->princess->land == laDungeon && !saved && !nodungeon) {
|
|
|
|
addMessage(XLAT("%The1 says, \"not this place, it looks even worse...\"", moPrincess));
|
|
|
|
nodungeon = true;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void save(cell *princess) {
|
|
|
|
if(euclid) return;
|
|
|
|
princess::info *i = princess::getPrincessInfo(princess);
|
|
|
|
if(!i || i->bestdist <= 3) princess->monst = moNone;
|
2017-07-16 21:00:55 +00:00
|
|
|
else if(i) setdist(i, OUT_OF_PRISON);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void move(cell *ct, cell *cf) {
|
|
|
|
if(euclid) return;
|
|
|
|
princess::info *i = princess::getPrincessInfo(cf);
|
|
|
|
if(!i) {
|
|
|
|
// note: OK if mapediting or loading
|
2017-07-16 21:00:55 +00:00
|
|
|
printf("Warning: unknown princess\n");
|
|
|
|
if(!cheater)
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage("Warning: unknown princess (that's a bug, please report)");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i->princess = ct;
|
|
|
|
setdist(i, dist(ct));
|
|
|
|
// printf("newdist = %d (vs %d)\n", newdist, i->bestdist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseSqueak(cell *c) {
|
|
|
|
eMonster m = c->monst;
|
|
|
|
info *i = getPrisonInfo(c);
|
|
|
|
int d = dist(c);
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
playSound(c, "mousesqueak", 40);
|
2016-08-26 09:58:03 +00:00
|
|
|
if(!i)
|
|
|
|
addMessage(XLAT("%The1 squeaks in a confused way.", m));
|
|
|
|
else if(i->bestdist >= 6)
|
|
|
|
addMessage(XLAT("%The1 squeaks gratefully!", m));
|
|
|
|
else if(!i->princess)
|
|
|
|
addMessage(XLAT("%The1 squeaks hopelessly.", m));
|
|
|
|
else if(d > 120)
|
|
|
|
addMessage(XLAT("%The1 squeaks in despair.", m));
|
|
|
|
else if(d > 90)
|
|
|
|
addMessage(XLAT("%The1 squeaks sadly.", m));
|
|
|
|
else if(d > 60)
|
|
|
|
addMessage(XLAT("%The1 squeaks with hope!", m));
|
|
|
|
else if(d > 30)
|
|
|
|
addMessage(XLAT("%The1 squeaks happily!", m));
|
|
|
|
else
|
|
|
|
addMessage(XLAT("%The1 squeaks excitedly!", m));
|
|
|
|
}
|
|
|
|
|
|
|
|
void line(cell *c) {
|
|
|
|
int d = (euclid || c->master->alt) ? celldistAlt(c) : 200;
|
|
|
|
eMonster m = c->monst;
|
|
|
|
|
|
|
|
static int msgid = 0;
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
playSound(c, princessgender() ? "speak-princess" : "speak-prince");
|
2016-08-26 09:58:03 +00:00
|
|
|
retry:
|
2017-08-06 12:50:16 +00:00
|
|
|
if(msgid >= 127) msgid = 0;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-07-16 21:00:55 +00:00
|
|
|
bool inpalace = c->land == laPalace || c->land == laDungeon;
|
|
|
|
|
|
|
|
if(msgid == 0 && d < 20 && inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("%The1 kisses you, and begs you to bring %him1 away from here.", m));
|
|
|
|
}
|
2017-07-24 22:21:36 +00:00
|
|
|
else if(msgid == 1 && d >= 20 && inpalace && !peace::on) {
|
2016-08-26 09:58:03 +00:00
|
|
|
if(m == moPrincess)
|
|
|
|
addMessage(XLAT("\"I want my revenge. Stun a guard and leave him for me!\"", m));
|
|
|
|
else
|
|
|
|
addMessage(XLAT("\"That felt great. Thanks!\"", m));
|
|
|
|
}
|
2017-07-16 21:00:55 +00:00
|
|
|
else if(msgid == 2 && d >= 70 && inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("\"Bring me out of here please!\"", m));
|
|
|
|
}
|
2017-07-16 21:00:55 +00:00
|
|
|
else if(msgid == 3 && !inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("%The1 kisses you, and thanks you for saving %him1.", m));
|
|
|
|
}
|
2017-07-24 22:21:36 +00:00
|
|
|
else if(msgid == 4 && !inpalace && m == moPrincess && !peace::on) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("\"I have been trained to fight with a Hypersian scimitar, you know?\"", m));
|
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
else if(msgid == 16 && !inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("\"I would love to come to your world with you!\"", m));
|
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
else if(msgid == 20 && !inpalace) {
|
|
|
|
addMessage(XLAT("\"I do not like butterflies. They are treacherous.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 32 && !inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("\"Straight lines stay close to each other forever, this is so romantic!\"", m));
|
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
else if(msgid == 40 && !inpalace) {
|
|
|
|
addMessage(XLAT("\"I hate roses.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 48 && !inpalace) {
|
2016-08-26 09:58:03 +00:00
|
|
|
addMessage(XLAT("\"Maps... Just like the world, but smaller... how is that even possible?!\"", m));
|
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
else if(msgid == 64) {
|
|
|
|
addMessage(XLAT("\"In this world there is plenty of space for everyone. We do not need wars.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 65) {
|
|
|
|
addMessage(XLAT("\"Only the stupid hyperbugs do not understand this.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 72 && !inpalace) {
|
|
|
|
addMessage(XLAT("\"I have once talked to a Yendorian researcher... he was only interested in infinite trees.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 73 && !inpalace) {
|
|
|
|
addMessage(XLAT("\"Infinite trees are boring. I prefer other graphs.\"", m));
|
|
|
|
}
|
|
|
|
else if(msgid == 80) {
|
|
|
|
addMessage(XLAT("\"Are there Temples of Cthulhu in your world? Why not?\"", m));
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
else {
|
|
|
|
msgid++; goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
msgid++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void playernear(cell *c) {
|
|
|
|
info *i = getPrisonInfo(c);
|
|
|
|
int d = dist(c);
|
|
|
|
// if(i) printf("d=%d bn=%d\n", d, i->bestnear);
|
|
|
|
if(i && d < i->bestnear) {
|
|
|
|
if(i->bestnear > 100 && d <= 100) {
|
|
|
|
i->value = items[itPalace];
|
|
|
|
if(princess::challenge)
|
|
|
|
addMessage(XLAT("Hardness frozen at %1.", its(i->value)));
|
|
|
|
}
|
|
|
|
i->bestnear = d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clearing {
|
|
|
|
|
|
|
|
bool buggyplant = false;
|
|
|
|
|
|
|
|
std::map<heptagon*, clearingdata> bpdata;
|
|
|
|
|
2018-04-14 08:24:02 +00:00
|
|
|
cell *current_root;
|
|
|
|
|
|
|
|
void new_root() {
|
|
|
|
if(!current_root || current_root->monst != moMutant) {
|
|
|
|
auto& ac = currentmap->allcells();
|
|
|
|
int iter = 0;
|
|
|
|
while(!current_root || pseudohept(current_root) || current_root->cpdist < 3) {
|
|
|
|
if(iter++ > 100) return;
|
|
|
|
current_root = ac[hrand(size(ac))];
|
|
|
|
}
|
|
|
|
current_root->monst = moMutant;
|
|
|
|
current_root->mondir = NODIR;
|
|
|
|
current_root->stuntime = (mutantphase + 1) & 15;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
int plantdir(cell *c) {
|
2017-10-30 21:47:07 +00:00
|
|
|
if(!quotient) {
|
|
|
|
generateAlts(c->master);
|
|
|
|
for(int i=0; i<S7; i++)
|
|
|
|
generateAlts(c->master->move[i]);
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
int d = celldistAlt(c);
|
|
|
|
|
2018-01-06 21:34:03 +00:00
|
|
|
if(nonbitrunc) {
|
2017-10-30 21:47:07 +00:00
|
|
|
for(int i=0; i<S7; i++) {
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *c2 = createMov(c, i);
|
|
|
|
if(!pseudohept(c2) && celldistAlt(c2) == d-1)
|
|
|
|
return i;
|
|
|
|
}
|
2017-10-30 21:47:07 +00:00
|
|
|
for(int i=0; i<S7; i++) {
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *c2 = createMov(c, i);
|
|
|
|
if(celldistAlt(c2) == d-1)
|
2017-10-30 21:47:07 +00:00
|
|
|
return (i+1) % S7;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:47:07 +00:00
|
|
|
for(int i=1; i<S6; i+=2) {
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *c2 = createMov(c, i);
|
|
|
|
if(celldistAlt(c2) == d-1)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:47:07 +00:00
|
|
|
int quseful = 0, tuseful = 0, tuseful2 = 0;
|
|
|
|
for(int i=1; i<S6; i+=2) {
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *c2 = c->mov[i];
|
|
|
|
if(celldistAlt(c2) == d) {
|
|
|
|
bool useful = false;
|
2017-10-30 21:47:07 +00:00
|
|
|
for(int j=1; j<S6; j++) {
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *c3 = createMov(c2, j);
|
|
|
|
if(celldistAlt(c3) == d-1)
|
|
|
|
useful = true;
|
|
|
|
}
|
2017-10-30 21:47:07 +00:00
|
|
|
if(useful) quseful++, tuseful += (1<<i), tuseful2 = i;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-30 21:47:07 +00:00
|
|
|
if(quseful == 1) return tuseful2;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(quseful == 2) {
|
|
|
|
int i;
|
2017-10-30 21:47:07 +00:00
|
|
|
if(tuseful == (1<<3)+(1<<5)) i = 3;
|
|
|
|
if(tuseful == (1<<5)+(1<<1)) i = 5;
|
|
|
|
if(tuseful == (1<<1)+(1<<3)) i = 1;
|
|
|
|
if(tuseful == (1<<5)+(1<<7)) i = 5;
|
|
|
|
if(tuseful == (1<<7)+(1<<1)) i = 7;
|
|
|
|
if((d & 7) < 4) i = (i+2) % S6;
|
2016-08-26 09:58:03 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
printf("error in plantdir\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<cell*> onpath;
|
|
|
|
vector<int> pdir;
|
|
|
|
vector<cell*> rpath;
|
|
|
|
|
|
|
|
void generate(cell *c) {
|
2018-04-14 08:24:02 +00:00
|
|
|
if(buggyplant) return;
|
|
|
|
if(sphere) return;
|
2018-04-10 06:05:35 +00:00
|
|
|
if(gp::on) return;
|
2018-04-14 08:24:02 +00:00
|
|
|
if(quotient) return;
|
2018-04-10 06:05:35 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(euclid) {
|
2017-06-09 01:41:33 +00:00
|
|
|
if(torus) return;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(pseudohept(c)) return;
|
|
|
|
c->monst = moMutant;
|
2017-06-09 01:41:33 +00:00
|
|
|
|
2017-12-28 15:46:10 +00:00
|
|
|
int x, y;
|
|
|
|
tie(x,y) = cell_to_pair(c);
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
int xco = x * 2 + y + 1;
|
|
|
|
c->stuntime = (8-xco/2) & 15;
|
|
|
|
// 2, 4, 5, 7
|
|
|
|
|
|
|
|
if(pseudohept(createMov(c, 0)))
|
|
|
|
c->mondir = 1 + hrand(2) * 4;
|
|
|
|
else
|
|
|
|
c->mondir = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cell *oc = c;
|
|
|
|
if(!euclid) generateAlts(c->master);
|
|
|
|
if(pseudohept(c)) return;
|
|
|
|
heptagon *a = euclid ? NULL : c->master->alt->alt;
|
|
|
|
clearingdata& bd(bpdata[a]);
|
|
|
|
if(!bd.root) { bd.root = c; bd.dist = 8; }
|
|
|
|
|
|
|
|
onpath.clear(); pdir.clear(); rpath.clear();
|
|
|
|
|
|
|
|
int steps = 0;
|
|
|
|
|
|
|
|
int ds;
|
|
|
|
|
2017-10-30 21:47:07 +00:00
|
|
|
int stepcount = 0;
|
2016-08-26 09:58:03 +00:00
|
|
|
while(true) {
|
|
|
|
if(c == bd.root) {ds = bd.dist; break; }
|
|
|
|
|
|
|
|
// printf("R %4d C %4d\n", celldistAlt(bd.root), celldistAlt(c));
|
|
|
|
if(celldistAlt(c) > celldistAlt(bd.root)) {
|
2017-10-30 21:47:07 +00:00
|
|
|
stepcount++;
|
|
|
|
if(stepcount > 1000) {
|
|
|
|
printf("buggy #1\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(c->mpdist <= 6) {
|
|
|
|
if(c->monst != moMutant) return; // already cut!
|
|
|
|
// ... else simply extend it
|
|
|
|
ds = c->stuntime; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int d = plantdir(c);
|
|
|
|
steps++;
|
|
|
|
onpath.push_back(c); pdir.push_back(d);
|
|
|
|
// printf("c [%4d] %p -> %p\n", celldistAlt(c), c, c->mov[d]);
|
|
|
|
c = c->mov[d];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bd.dist--;
|
|
|
|
if(bd.dist < -1000) {
|
|
|
|
for(int i=0; i<steps; i++)
|
|
|
|
onpath[i]->item = itBuggy;
|
|
|
|
for(int i=0; i<(int) rpath.size(); i++)
|
|
|
|
rpath[i]->item = itBuggy;
|
|
|
|
buggyplant = true;
|
|
|
|
printf("buggygen\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rpath.push_back(bd.root);
|
|
|
|
// printf("r [%4d] %p -> %p\n", celldistAlt(bd.root), bd.root, bd.root->mov[plantdir(bd.root)]);
|
2017-10-30 21:47:07 +00:00
|
|
|
bd.root = createMov(bd.root, plantdir(bd.root));
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// printf("steps = %d dist = %d [%d]\n", steps, bd.dist, oc->mpdist);
|
|
|
|
|
|
|
|
onpath.push_back(c); pdir.push_back(plantdir(c));
|
|
|
|
while(steps >= 0) {
|
|
|
|
c = onpath[steps];
|
|
|
|
if(steps == 0) {
|
|
|
|
c->monst = moMutant;
|
|
|
|
c->mondir = pdir[steps];
|
|
|
|
if(pdir[steps] != plantdir(c)) {
|
|
|
|
printf("pdir i/ plantdir\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
c->stuntime = ds;
|
|
|
|
}
|
|
|
|
if(c->mpdist <= 7 && c->monst != moMutant)
|
|
|
|
break;
|
|
|
|
steps--; ds++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace whirlpool {
|
|
|
|
|
|
|
|
bool escaped = false; // escaped the Whirlpool?
|
|
|
|
|
|
|
|
// next == +1 -> next
|
|
|
|
// next == -1 -> prev
|
|
|
|
cell *get(cell *c, int next) {
|
|
|
|
int i = 0;
|
|
|
|
if(!euclid && !c->master->alt) return NULL;
|
|
|
|
int d = celldistAlt(c);
|
|
|
|
int d2;
|
|
|
|
while(true) {
|
|
|
|
if(i == c->type) return NULL;
|
|
|
|
if(c->mov[i] && (d2 = celldistAlt(c->mov[i])) != d)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if(i == c->type) return NULL;
|
|
|
|
if(d>d2) next = -next;
|
|
|
|
for(int j=1; j<c->type; j++) {
|
2017-10-30 09:29:15 +00:00
|
|
|
cell *c2 = c->mov[(i+MODFIXER+next*j) % c->type];
|
2016-08-26 09:58:03 +00:00
|
|
|
if(celldistAlt(c2) == d) return c2;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void build(vector<cell*>& whirlline, int d) {
|
|
|
|
again:
|
|
|
|
cell *at = whirlline[size(whirlline)-1];
|
|
|
|
cell *prev = whirlline[size(whirlline)-2];
|
|
|
|
for(int i=0; i<at->type; i++)
|
|
|
|
if(at->mov[i] && (euclid || at->mov[i]->master->alt) && celldistAlt(at->mov[i]) == d && at->mov[i] != prev) {
|
2017-10-30 22:57:46 +00:00
|
|
|
if(at->mov[i] == whirlline[0]) return; // loops in weird geometries?
|
|
|
|
if(at->mov[i] == whirlline[size(whirlline)/2]) return; // even weirder geometry?
|
2016-08-26 09:58:03 +00:00
|
|
|
whirlline.push_back(at->mov[i]);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void generate(cell *wto) {
|
|
|
|
if(wto->wall == waBoat || wto->monst)
|
|
|
|
return;
|
|
|
|
|
2017-10-30 22:57:46 +00:00
|
|
|
wto->wall = waSea;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(hrand(35000) < 40 + items[itWhirlpool] + yendor::hardness())
|
|
|
|
wto->monst = moCShark;
|
|
|
|
else if(hrand(5000) < 500)
|
|
|
|
wto->wall = waBoat;
|
|
|
|
|
|
|
|
if(wto->wall == waBoat && (euclid || wto->master->alt)) {
|
|
|
|
int d = celldistAlt(wto);
|
|
|
|
if(yendor::on) d -= 200;
|
|
|
|
// 250 : hard
|
|
|
|
if(hrand(5000) < 60 + 3 * items[itWhirlpool] + yendor::hardness())
|
|
|
|
wto->monst = moPirate;
|
2017-08-14 18:31:43 +00:00
|
|
|
if(hrand(5000) < 20 && d < -20 && !tactic::on && !inv::on)
|
2016-08-26 09:58:03 +00:00
|
|
|
wto->item = itOrbSafety;
|
|
|
|
else if(hrand(5000) < 20 && d < -20 && !tactic::on && markOrb(itOrbLuck))
|
|
|
|
wto->item = itOrbSafety;
|
|
|
|
else if(hrand(5000) < 20*PRIZEMUL && d < -20)
|
|
|
|
placePrizeOrb(wto);
|
2017-08-14 18:31:43 +00:00
|
|
|
else if(!inv::on && items[itWhirlpool] >= 10 && hrand(5000) < 20 && d < -15)
|
2016-08-26 09:58:03 +00:00
|
|
|
wto->item = itOrbWater;
|
|
|
|
else if(d<-10 && hrand(5000) < 1000-d)
|
|
|
|
wto->item = itWhirlpool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void whirlMove(cell *wto, cell *wfrom) {
|
|
|
|
// monsters don't move
|
2017-03-23 10:53:57 +00:00
|
|
|
if(wfrom && (isPlayerOn(wfrom) || wfrom->monst))
|
2016-08-26 09:58:03 +00:00
|
|
|
return;
|
|
|
|
// disappear
|
|
|
|
if(!wto) { wfrom->wall = waSea; wfrom->item = itNone; }
|
|
|
|
|
|
|
|
if(wfrom && wto && wfrom->wall == waBoat && wto->wall == waSea && !wto->monst) {
|
|
|
|
wfrom->wall = waSea; wto->wall = waBoat;
|
2017-03-23 10:53:57 +00:00
|
|
|
wto->mondir = neighborId(wto, wfrom);
|
|
|
|
animateMovement(wfrom, wto, LAYER_BOAT);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(wfrom && wto && wfrom->item && !wto->item && wfrom->wall != waBoat) {
|
|
|
|
// Keys and Orbs of Yendor never disappear!
|
|
|
|
if(wfrom->item == itKey || wfrom->item == itOrbYendor)
|
|
|
|
for(int i=0; i<wto->type; i++) createMov(wto, i);
|
|
|
|
moveItem(wfrom, wto, false);
|
2017-12-30 22:47:10 +00:00
|
|
|
pickupMovedItems(wfrom);
|
|
|
|
pickupMovedItems(wto);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(wto && !wfrom)
|
|
|
|
generate(wto);
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveAt(cell *c) {
|
|
|
|
if(c->land != laWhirlpool) return;
|
|
|
|
if(eq(c->aitmp, sval)) return;
|
|
|
|
if(!(euclid || c->master->alt)) return;
|
|
|
|
cell *c2 = get(c, 1);
|
|
|
|
if(!c2) return;
|
|
|
|
int d = celldistAlt(c);
|
|
|
|
vector<cell*> whirlline;
|
|
|
|
whirlline.push_back(c);
|
|
|
|
whirlline.push_back(c2);
|
|
|
|
build(whirlline, d);
|
|
|
|
reverse(whirlline.begin(), whirlline.end());
|
|
|
|
build(whirlline, d);
|
|
|
|
int z = size(whirlline);
|
|
|
|
|
|
|
|
for(int i=0; i<z; i++)
|
|
|
|
whirlline[i]->aitmp = sval;
|
|
|
|
|
|
|
|
whirlMove(NULL, whirlline[0]);
|
|
|
|
|
|
|
|
for(int i=0; i<z-1; i++)
|
|
|
|
whirlMove(whirlline[i], whirlline[i+1]);
|
|
|
|
|
|
|
|
whirlMove(whirlline[z-1], NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void move() {
|
|
|
|
sval++;
|
|
|
|
for(int i=0; i<size(dcal); i++) {
|
|
|
|
cell *c = dcal[i];
|
|
|
|
moveAt(c);
|
|
|
|
}
|
|
|
|
// Keys and Orbs of Yendor always move
|
|
|
|
using namespace yendor;
|
|
|
|
for(int i=0; i<size(yi); i++) {
|
|
|
|
moveAt(yi[i].path[0]);
|
|
|
|
moveAt(yi[i].path[YDIST-1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
bool operator == (const cellwalker& c1, const cellwalker& c2) {
|
|
|
|
return c1.c == c2.c && c1.spin == c2.spin && c1.mirrored == c2.mirrored;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
namespace mirror {
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
vector<pair<int, cellwalker>> mirrors;
|
|
|
|
static const int LIGHTNING = -1; // passed instead of cpid
|
|
|
|
|
|
|
|
bool noMirrorOn(cell *c) {
|
2018-04-03 21:34:47 +00:00
|
|
|
return c->monst || (!shmup::on && isPlayerOn(c)) || (geometry != gQuotient2 && geometry != gTorus && c->cpdist > gamerange());
|
2017-07-22 23:33:27 +00:00
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
bool cellMirrorable(cell *c) {
|
2017-07-22 23:33:27 +00:00
|
|
|
if(noMirrorOn(c)) return false;
|
2016-08-26 09:58:03 +00:00
|
|
|
return
|
|
|
|
c->wall == waNone || c->wall == waCavefloor || isAlchAny(c) ||
|
|
|
|
c->wall == waFrozenLake || c->wall == waDeadfloor || c->wall == waDeadfloor2 ||
|
|
|
|
c->wall == waGiantRug || c->wall == waCIsland || c->wall == waCIsland2 ||
|
|
|
|
c->wall == waGargoyleFloor || c->wall == waRubble ||
|
2017-07-16 21:00:55 +00:00
|
|
|
c->wall == waGargoyleBridge || c->wall == waTempFloor || c->wall == waTempBridge ||
|
2017-09-03 10:01:31 +00:00
|
|
|
c->wall == waMirrorWall || c->wall == waPetrifiedBridge;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
|
|
|
|
void destroyKilled() {
|
|
|
|
int j = 0;
|
|
|
|
for(int i=0; i<size(mirrors); i++)
|
|
|
|
if(mirrors[i].second.c->monst == moMimic)
|
|
|
|
mirrors[j++] = mirrors[i];
|
|
|
|
mirrors.resize(j);
|
|
|
|
}
|
2017-07-16 21:00:55 +00:00
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void unlist() {
|
|
|
|
for(auto& m: mirrors)
|
|
|
|
if(m.second.c->monst == moMimic)
|
|
|
|
m.second.c->monst = moNone;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void list() {
|
|
|
|
for(auto& m: mirrors)
|
|
|
|
m.second.c->monst = moMimic;
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroyAll() {
|
|
|
|
unlist();
|
|
|
|
mirrors.clear();
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void createMirror(cellwalker cw, int cpid) {
|
|
|
|
if(!shmup::on && inmirror(cw))
|
|
|
|
cw = reflect(cw);
|
|
|
|
if(cpid == LIGHTNING)
|
|
|
|
castLightningBolt(cw);
|
|
|
|
else if(cellMirrorable(cw.c)) {
|
|
|
|
for(auto& m: mirrors)
|
|
|
|
if(m == make_pair(cpid,cw))
|
|
|
|
return;
|
|
|
|
mirrors.emplace_back(cpid, cw);
|
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void createMirrors(cellwalker cw, int cpid) {
|
|
|
|
cw.mirrored = !cw.mirrored;
|
|
|
|
cell *c = cw.c;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
for(int i=0; i<cw.c->type; i++) {
|
2018-03-24 11:59:01 +00:00
|
|
|
auto cws = cw + wstep;
|
|
|
|
if(cws.c->type == c->type)
|
|
|
|
createMirror(cws+i, cpid);
|
|
|
|
cw += 1;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void createMirages(cellwalker cw, int cpid) {
|
2018-01-06 21:34:03 +00:00
|
|
|
if(nonbitrunc) {
|
2018-03-24 11:59:01 +00:00
|
|
|
for(int i=0; i<cw.c->type; i++)
|
|
|
|
createMirror(cw + i + wstep + 3 + wstep + 5 + wstep + 3 - i, cpid);
|
2016-08-26 09:58:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-29 09:52:02 +00:00
|
|
|
for(int i=0; i<S6; i++) {
|
2018-03-24 11:59:01 +00:00
|
|
|
auto cw0 = cw + i + wstep;
|
|
|
|
if(!ctof(cw0.c)) {
|
|
|
|
createMirror(cw0 + 2 + wstep - (2+i), cpid);
|
|
|
|
createMirror(cw0 - 2 + wstep + (2-i), cpid);
|
2017-07-22 23:33:27 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
|
|
|
|
void createHere(cellwalker cw, int cpid) {
|
2017-08-06 12:50:16 +00:00
|
|
|
if(!cw.c) return;
|
2017-07-22 23:33:27 +00:00
|
|
|
if(cw.c->wall == waCloud)
|
|
|
|
createMirages(cw, cpid);
|
|
|
|
if(cw.c->wall == waMirror)
|
|
|
|
createMirrors(cw, cpid);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void breakMirror(cellwalker cw, int pid) {
|
2017-08-06 12:50:16 +00:00
|
|
|
if(!cw.c) return;
|
2017-07-22 23:33:27 +00:00
|
|
|
cell *c = cw.c;
|
|
|
|
if(c->wall == waMirror || c->wall == waCloud) {
|
|
|
|
drawParticles(c, winf[c->wall].color, 16);
|
|
|
|
playSound(c, "pickup-mirror", 50);
|
|
|
|
if(pid >= 0 && (cw.c->land == laMirror || cw.c->land == laMirrorOld)) {
|
|
|
|
dynamicval<int> d(multi::cpid, pid);
|
|
|
|
gainShard(cw.c, c->wall == waMirror ? "The mirror shatters!" : "The cloud turns into a bunch of images!");
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
c->wall = waNone;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
|
|
|
|
bool isKilledByMirror(cell *c) {
|
2017-09-17 11:37:05 +00:00
|
|
|
for(auto& m: mirrors) {
|
2018-03-24 11:59:01 +00:00
|
|
|
cell *c1 = (m.second + wstep).c;
|
2017-09-17 11:37:05 +00:00
|
|
|
if(inmirror(c1)) c1 = reflect(cellwalker(c1, 0, false)).c;
|
|
|
|
if(c1 == c && canAttack(m.second.c, moMimic, c, c->monst, 0))
|
2017-07-22 23:33:27 +00:00
|
|
|
return true;
|
2017-09-17 11:37:05 +00:00
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
void go(bool fwd) {
|
|
|
|
int tk = tkills();
|
2017-07-22 23:33:27 +00:00
|
|
|
int nummirage = 0;
|
|
|
|
int j = 0;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=0; i<size(mirrors); i++) {
|
2017-07-22 23:33:27 +00:00
|
|
|
auto& m = mirrors[i];
|
|
|
|
bool survive = true;
|
|
|
|
if(m.first == multi::cpid) {
|
|
|
|
cell *c = m.second.c;
|
|
|
|
if(!m.second.mirrored) nummirage++;
|
2018-03-24 11:59:01 +00:00
|
|
|
auto cw2 = m.second + wstep;
|
2017-07-22 23:33:27 +00:00
|
|
|
if(inmirror(cw2)) cw2 = reflect(cw2);
|
|
|
|
cell *c2 = cw2.c;
|
|
|
|
if(c2->monst) {
|
|
|
|
c->monst = moMimic;
|
2017-09-30 09:46:41 +00:00
|
|
|
eMonster m2 = c2->monst;
|
|
|
|
if(!peace::on && canAttack(c,moMimic,c2,m2, 0)) {
|
2018-01-03 20:49:14 +00:00
|
|
|
attackMonster(c2, AF_NORMAL | AF_MSG, moMimic);
|
2017-09-30 09:46:41 +00:00
|
|
|
if(!fwd) produceGhost(c2, m2, moMimic);
|
|
|
|
sideAttack(c, m.second.spin, m2, 0);
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
c->monst = moNone;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c2->wall == waBigTree)
|
|
|
|
c2->wall = waSmallTree;
|
|
|
|
else if(c2->wall == waSmallTree)
|
|
|
|
c2->wall = waNone;
|
2017-07-22 23:33:27 +00:00
|
|
|
if(fwd) {
|
2018-02-11 23:06:11 +00:00
|
|
|
if(noMirrorOn(c2) || !passable_for(moMimic, c2, c, P_MONSTER | P_MIRROR | P_MIRRORWALL)) {
|
2017-07-22 23:33:27 +00:00
|
|
|
survive = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
c->monst = moMimic;
|
|
|
|
moveMonster(c2, c);
|
2016-08-26 09:58:03 +00:00
|
|
|
c2->monst = moNone;
|
2017-07-22 23:33:27 +00:00
|
|
|
empathyMove(c, c2, neighborId(c2, c));
|
|
|
|
m.second = cw2;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
if(survive) {
|
|
|
|
mirrors[j++] = m;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
mirrors.resize(j);
|
2016-08-26 09:58:03 +00:00
|
|
|
achievement_count("MIRRORKILL", tkills(), tk);
|
|
|
|
achievement_count("MIRAGE", nummirage, 0);
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
void act(int d, int flags) {
|
|
|
|
destroyKilled();
|
|
|
|
unlist();
|
|
|
|
if(multi::players == 1) multi::cpid = 0;
|
|
|
|
bool spinning =
|
|
|
|
flags & (multi::players > 1 ? SPINMULTI : SPINSINGLE);
|
|
|
|
if(spinning && d) {
|
|
|
|
for(auto& m: mirrors)
|
|
|
|
if(m.first == multi::cpid)
|
2018-03-24 11:59:01 +00:00
|
|
|
m.second += d;
|
2017-07-22 23:33:27 +00:00
|
|
|
}
|
|
|
|
if(flags & ATTACK)
|
|
|
|
go(flags & GO);
|
|
|
|
list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void breakAll() {
|
|
|
|
destroyKilled();
|
|
|
|
unlist();
|
|
|
|
if(numplayers() == 1)
|
|
|
|
createHere(cwt, 0);
|
|
|
|
else for(int i=0; i<numplayers(); i++)
|
|
|
|
createHere(multi::player[i], i);
|
|
|
|
for(int i=0; i<size(mirrors); i++)
|
|
|
|
createHere(mirrors[i].second, mirrors[i].first);
|
|
|
|
if(numplayers() == 1)
|
|
|
|
breakMirror(cwt, 0);
|
|
|
|
else for(int i=0; i<numplayers(); i++)
|
|
|
|
breakMirror(multi::player[i], i);
|
|
|
|
for(int i=0; i<size(mirrors); i++)
|
|
|
|
breakMirror(mirrors[i].second, -1);
|
|
|
|
list();
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
2017-07-16 21:00:55 +00:00
|
|
|
|
|
|
|
int mirrordir(cell *c) {
|
|
|
|
if(c->type == 7) return c->bardir;
|
|
|
|
|
|
|
|
int icount = 0, isum = 0;
|
|
|
|
for(int i=0; i<6; i+=2) {
|
|
|
|
if(createMov(c, i)->bardir == c->spin(i))
|
|
|
|
icount++, isum+=i;
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
if(icount != 1) return -1;
|
2017-07-16 21:00:55 +00:00
|
|
|
return isum;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair<bool, cellwalker> traceback(vector<int>& v, cellwalker cw) {
|
|
|
|
bool goout = false;
|
|
|
|
for(int i=size(v)-1; i>=0; i--) {
|
2018-03-24 11:59:01 +00:00
|
|
|
if(v[i]) cw -= v[i];
|
2017-07-16 21:00:55 +00:00
|
|
|
else {
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += wstep;
|
2017-07-16 21:00:55 +00:00
|
|
|
if(cw.c->land == laMirrorWall || cw.c->land == laMirror) goout = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return make_pair(goout, cw);
|
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
|
|
|
|
int depth(cell *c) { return c->landparam & 255; }
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2017-09-17 10:32:31 +00:00
|
|
|
cellwalker reflect0(cellwalker cw) {
|
2017-07-16 21:00:55 +00:00
|
|
|
int stepcount = 0;
|
|
|
|
cellwalker cwcopy = cw;
|
|
|
|
static vector<int> v;
|
|
|
|
v.clear();
|
|
|
|
while(true) {
|
|
|
|
if(!inmirror(cw)) break;
|
|
|
|
stepcount++; if(stepcount > 10000) {
|
2017-07-22 23:33:27 +00:00
|
|
|
return cw;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
2018-03-24 11:59:01 +00:00
|
|
|
cell *c0 = (cw+wstep).c;
|
2017-07-16 21:00:55 +00:00
|
|
|
int go = 0;
|
|
|
|
if(!inmirror(c0)) go = 2;
|
2017-08-06 12:50:16 +00:00
|
|
|
else if(depth(c0) && depth(c0) < depth(cw.c)) go = 1;
|
2017-07-16 21:00:55 +00:00
|
|
|
if(go) {
|
|
|
|
v.push_back(0);
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += wstep;
|
2017-07-16 21:00:55 +00:00
|
|
|
if(go == 2) break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
v.push_back(1);
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 1;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(cw.c->land == laMirrorWall || cw.c->land == laMirrorWall2) {
|
|
|
|
if(cw.c->type == 7) {
|
|
|
|
while(cw.spin != cw.c->bardir) {
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 1;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(1);
|
|
|
|
stepcount++; if(stepcount > 10000) { printf("failhep\n"); return cw; }
|
|
|
|
}
|
2018-03-24 11:59:01 +00:00
|
|
|
if(nonbitrunc && (cw+wstep).c == cwcopy.c)
|
2017-07-16 21:00:55 +00:00
|
|
|
v.pop_back();
|
2018-03-24 11:59:01 +00:00
|
|
|
if(nonbitrunc && (cw+3+wstep).c->land == laMirrored && (cw+2+wstep).c->land == laMirrorWall) {
|
|
|
|
cw += wmirror;
|
2017-07-16 21:00:55 +00:00
|
|
|
auto p = traceback(v, cw);
|
|
|
|
if(p.first) return p.second;
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 2;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(2);
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += wstep;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(0);
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 3;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2018-03-24 11:59:01 +00:00
|
|
|
while((cw+wstep).c->type != 7) {
|
|
|
|
cw ++;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(1);
|
|
|
|
}
|
|
|
|
int icount = 0;
|
|
|
|
for(int i=0; i<3; i++) {
|
2018-03-24 11:59:01 +00:00
|
|
|
if((cw+wstep).c->bardir == cw.c->spin(cw.spin))
|
2017-07-16 21:00:55 +00:00
|
|
|
icount++;
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 2;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
|
|
|
if(icount >= 2) {
|
|
|
|
cellwalker cwcopy = cw;
|
|
|
|
for(int a=0; a<3; a++) for(int m=0; m<2; m++) {
|
|
|
|
cellwalker cw = cwcopy;
|
|
|
|
if(m) cw.mirrored = !cw.mirrored;
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += (a*2);
|
2017-07-16 21:00:55 +00:00
|
|
|
auto p = traceback(v,cw);
|
|
|
|
if(p.first) return p.second;
|
|
|
|
}
|
|
|
|
printf("icount >= 2 but failed\n");
|
|
|
|
return cw;
|
|
|
|
}
|
2018-03-24 11:59:01 +00:00
|
|
|
while((cw+wstep).c->bardir != cw.c->spin(cw.spin)) {
|
2017-07-16 21:00:55 +00:00
|
|
|
stepcount++; if(stepcount > 10000) { printf("fail2\n"); return cw; }
|
2018-03-24 11:59:01 +00:00
|
|
|
cw += 2;
|
2017-07-16 21:00:55 +00:00
|
|
|
v.push_back(1);
|
|
|
|
v.push_back(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else v.pop_back();
|
|
|
|
cw.mirrored = !cw.mirrored;
|
|
|
|
cw = traceback(v,cw).second;
|
|
|
|
return cw;
|
|
|
|
}
|
2017-07-22 23:33:27 +00:00
|
|
|
|
2017-08-06 12:50:16 +00:00
|
|
|
static const int CACHESIZE = 1<<12; // must be a power of 2
|
|
|
|
static const int CACHEMASK = CACHESIZE-1;
|
|
|
|
|
|
|
|
pair<cell*, cellwalker> cache[CACHESIZE];
|
|
|
|
int nextcache;
|
|
|
|
|
|
|
|
void clearcache() {
|
|
|
|
for(int i=0; i<CACHESIZE; i++) cache[i].first = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cellwalker reflect(const cellwalker& cw) {
|
|
|
|
if(!cw.c) return cw;
|
2017-09-30 09:41:29 +00:00
|
|
|
if((cw.c->landparam & 255) == 0) {
|
|
|
|
bool cando = false;
|
|
|
|
forCellEx(c2, cw.c) if(c2->landparam & 255) cando = true;
|
|
|
|
if(cando) buildEquidistant(cw.c);
|
|
|
|
}
|
2017-09-30 09:42:45 +00:00
|
|
|
if((cw.c->landparam & 255) == 0) return cw;
|
2017-08-06 12:50:16 +00:00
|
|
|
int cid = (cw.c->landparam >> 8) & CACHEMASK;
|
|
|
|
if(cache[cid].first != cw.c) {
|
|
|
|
cid = nextcache++;
|
|
|
|
nextcache &= CACHEMASK;
|
|
|
|
cw.c->landparam &= ~ (CACHEMASK << 8);
|
2017-09-17 10:28:44 +00:00
|
|
|
cw.c->landparam |= (cid << 8);
|
2017-08-06 12:50:16 +00:00
|
|
|
cache[cid].first = cw.c;
|
2017-09-17 10:32:31 +00:00
|
|
|
cellwalker cw0(cw.c, 0, false);
|
|
|
|
cache[cid].second = reflect0(cw0);
|
|
|
|
int tries = 64;
|
|
|
|
while(inmirror(cache[cid].second.c) && tries--)
|
|
|
|
cache[cid].second = reflect0(cache[cid].second);
|
2017-08-06 12:50:16 +00:00
|
|
|
}
|
2018-03-24 11:59:01 +00:00
|
|
|
cellwalker res = cache[cid].second + cw.spin;
|
2017-08-06 12:50:16 +00:00
|
|
|
if(cw.mirrored) res.mirrored = !res.mirrored;
|
|
|
|
return res;
|
2017-07-16 21:00:55 +00:00
|
|
|
}
|
2017-08-06 12:50:16 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace hive {
|
|
|
|
|
2017-10-08 10:10:40 +00:00
|
|
|
int hivehard() {
|
|
|
|
return items[itRoyalJelly] + hardness_empty();
|
|
|
|
// 0, 5, 40, 135
|
|
|
|
}
|
|
|
|
|
|
|
|
eMonster randomHyperbug() {
|
|
|
|
int h = hivehard();
|
|
|
|
if(hrand(200) < h)
|
|
|
|
return moBug2;
|
|
|
|
return eMonster(moBug0 + hrand(BUGCOLORS));
|
|
|
|
// 50: 25/25/50
|
|
|
|
// 100:
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
struct buginfo_t {
|
|
|
|
cell *where;
|
|
|
|
short dist[BUGCOLORS];
|
|
|
|
};
|
|
|
|
|
|
|
|
vector<buginfo_t> buginfo;
|
|
|
|
|
|
|
|
vector<int> bugqueue[BUGCOLORS];
|
|
|
|
vector<int> bugqueue4[BUGCOLORS];
|
|
|
|
|
|
|
|
struct bugtomove_t {
|
|
|
|
int dist, moves, index;
|
|
|
|
bugtomove_t(int d, int m, int i) { dist=d; moves=m; index=i; }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool operator < (const bugtomove_t& m1, const bugtomove_t& m2) {
|
|
|
|
if(m1.dist != m2.dist) return m1.dist < m2.dist;
|
|
|
|
if(m1.moves != m2.moves) return m1.moves < m2.moves;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<bugtomove_t> bugtomove;
|
|
|
|
vector<cell*> deadbug;
|
|
|
|
vector<cell*> bugcellq;
|
|
|
|
|
|
|
|
int bugcount[BUGCOLORS];
|
|
|
|
|
|
|
|
bool isBugEnemy(cell *c, int k) {
|
2017-03-23 10:53:57 +00:00
|
|
|
if(isPlayerOn(c) && !invismove) return true;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(!c->monst) return false;
|
|
|
|
if(c->monst == moBug0+k) return false;
|
|
|
|
if(isIvy(c)) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// list bugs and targets for each color
|
|
|
|
#define BUGINF 29999
|
|
|
|
|
|
|
|
void bugQueueInsert(int k, int i, int d) {
|
|
|
|
if(buginfo[i].dist[k] > d) {
|
|
|
|
if(buginfo[i].dist[k] != BUGINF) {
|
|
|
|
printf("%d -> %d\n", buginfo[i].dist[k], d);
|
|
|
|
}
|
|
|
|
buginfo[i].dist[k] = d;
|
|
|
|
bugqueue[k].push_back(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bugcell(cell *c) {
|
|
|
|
short& i(c->aitmp);
|
|
|
|
if(i >= 0 && i < size(buginfo) && buginfo[i].where == c)
|
|
|
|
return;
|
|
|
|
i = size(buginfo);
|
|
|
|
buginfo.resize(i+1);
|
|
|
|
buginfo_t& b(buginfo[i]);
|
|
|
|
b.where = c;
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) {
|
|
|
|
b.dist[k] = BUGINF;
|
|
|
|
bool havebug = false, haveother = false;
|
|
|
|
for(int dir=0; dir<c->type; dir++) {
|
|
|
|
cell *c2 = c->mov[dir];
|
|
|
|
if(c2 && isBugEnemy(c2,k) && canAttack(c,eMonster(moBug0+k),c2,c2->monst, AF_TOUGH | AF_NOSHIELD | AF_GETPLAYER)) {
|
|
|
|
if(isBug(c2)) havebug = true;
|
|
|
|
else haveother = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(havebug) bugQueueInsert(k, i, 0);
|
|
|
|
else if(haveother) bugqueue4[k].push_back(i);
|
|
|
|
}
|
|
|
|
/*// bugs communicate if the distance is at most 2
|
|
|
|
// also all nearby cells are inserted to the buginfo structure
|
|
|
|
if(size(buginfo) < 30000) {
|
|
|
|
for(int dir=0; dir<c->type; dir++) {
|
|
|
|
cell *c2 = c->mov[dir];
|
|
|
|
if(c2) {
|
|
|
|
// if(isBug(c)) bugcellq.push_back(c2); => does not help...
|
|
|
|
for(int t=0; t<c2->type; t++)
|
|
|
|
if(c2->mov[t] && isBug(c2->mov[t]))
|
|
|
|
bugcellq.push_back(c2),
|
|
|
|
bugcellq.push_back(c2->mov[t]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
// use pheromones!
|
|
|
|
if(c->land == laHive && c->landparam > 1 && c->wall != waWaxWall) {
|
|
|
|
c->landparam --;
|
|
|
|
for(int dir=0; dir<c->type; dir++) {
|
|
|
|
cell *c2 = c->mov[dir];
|
|
|
|
if(c2) {
|
|
|
|
for(int t=0; t<c2->type; t++)
|
|
|
|
if(c2->mov[t])
|
|
|
|
bugcellq.push_back(c2),
|
|
|
|
bugcellq.push_back(c2->mov[t]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int last_d = -1;
|
|
|
|
|
|
|
|
void handleBugQueue(int k, int t) {
|
|
|
|
int i = bugqueue[k][t];
|
|
|
|
buginfo_t& b(buginfo[i]);
|
|
|
|
cell *c = b.where;
|
|
|
|
int d = b.dist[k];
|
|
|
|
last_d = d;
|
|
|
|
int goodmoves = 0;
|
|
|
|
for(int dir=0; dir<c->type; dir++) {
|
|
|
|
cell *c2 = c->mov[dir];
|
|
|
|
if(!c2) continue;
|
|
|
|
if(c2->aitmp < 0 || c2->aitmp >= size(buginfo)) continue;
|
|
|
|
if(!passable(c, c2, P_MONSTER)) continue;
|
|
|
|
int j = c2->aitmp;
|
|
|
|
if(buginfo[j].where != c2) continue;
|
|
|
|
if(buginfo[j].dist[k] < d) goodmoves++;
|
|
|
|
bugQueueInsert(k, j, d+1);
|
|
|
|
}
|
|
|
|
if(isBug(c) && c->monst == moBug0+k) {
|
|
|
|
bugcount[c->monst - moBug0]++;
|
|
|
|
bugtomove.push_back(bugtomove_t(d,goodmoves,i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
bool fightspam(cell *c) {
|
2018-04-03 21:34:47 +00:00
|
|
|
return c->cpdist >= gamerange() ||
|
2016-08-26 09:58:03 +00:00
|
|
|
isMetalBeast(c->monst) || c->monst == moSkeleton ||
|
|
|
|
isIvy(c->monst) || isMutantIvy(c->monst);
|
|
|
|
}
|
|
|
|
|
|
|
|
void movebugs() {
|
|
|
|
buginfo.clear();
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) bugqueue[k].clear();
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) bugqueue4[k].clear();
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) bugcount[k] = 0;
|
|
|
|
bugtomove.clear();
|
|
|
|
deadbug.clear();
|
|
|
|
|
|
|
|
int xdcs = size(dcal); for(int i=0; i<xdcs; i++) bugcell(dcal[i]);
|
|
|
|
for(int i=0; i<size(bugcellq); i++) bugcell(bugcellq[i]);
|
|
|
|
bugcellq.clear();
|
|
|
|
|
|
|
|
// printf("buginfo = %d\n", size(buginfo));
|
|
|
|
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) {
|
|
|
|
int t = 0;
|
|
|
|
last_d = -1;
|
|
|
|
int invadist = 4 - (items[itRoyalJelly]+10) / 20;
|
|
|
|
if(invadist<0) invadist = 0;
|
|
|
|
for(; t<size(bugqueue[k]) && last_d < invadist-1; t++) handleBugQueue(k, t);
|
|
|
|
for(int u=0; u<size(bugqueue4[k]); u++)
|
|
|
|
bugQueueInsert(k, bugqueue4[k][u], invadist);
|
|
|
|
bugqueue4[k].clear();
|
|
|
|
for(; t<size(bugqueue[k]); t++) handleBugQueue(k, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) {
|
|
|
|
set<int> check;
|
|
|
|
for(int t=0; t<size(bugqueue[k]); t++) {
|
|
|
|
if(check.count(bugqueue[k][t])) {
|
|
|
|
printf("REPETITION! [%d]\n", t);
|
|
|
|
}
|
|
|
|
check.insert(bugqueue[k][t]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 18:23:02 +00:00
|
|
|
hrandom_shuffle(&bugtomove[0], size(bugtomove));
|
2016-08-26 09:58:03 +00:00
|
|
|
sort(bugtomove.begin(), bugtomove.end());
|
|
|
|
|
|
|
|
int battlecount = 0;
|
|
|
|
for(int t=0; t<size(bugtomove); t++) {
|
|
|
|
bugtomove_t& bm(bugtomove[t]);
|
|
|
|
int i = bm.index;
|
|
|
|
|
|
|
|
buginfo_t& b(buginfo[i]);
|
|
|
|
cell *c = b.where;
|
|
|
|
if(!isBug(c)) continue;
|
|
|
|
if(c->stuntime) continue;
|
|
|
|
eMonster m = c->monst;
|
|
|
|
int k = (m - moBug0) % BUGCOLORS;
|
|
|
|
int gmoves[8], q=0, bqual = -1;
|
|
|
|
|
|
|
|
if(againstRose(c, NULL)) bqual = -40;
|
|
|
|
|
|
|
|
for(int dir=0; dir<c->type; dir++) {
|
|
|
|
cell *c2 = c->mov[dir];
|
|
|
|
int qual = -10;
|
|
|
|
if(!c2) continue;
|
|
|
|
else if(againstRose(c, c2)) qual = -50;
|
|
|
|
else if(canAttack(c, m, c2, c2->monst, AF_GETPLAYER))
|
|
|
|
qual = c2->monst == moDeadBug ? -60: isBugEnemy(c2,k) ? 2 : -20;
|
|
|
|
else if(!passable(c2, c, 0))
|
|
|
|
qual = passable(c2, c, P_DEADLY) ? -30 : -60;
|
|
|
|
else if(c2->aitmp < 0 || c2->aitmp >= size(buginfo)) qual = -15;
|
|
|
|
else if(buginfo[c2->aitmp].where != c2) qual = -15;
|
|
|
|
else if(buginfo[c2->aitmp].dist[k] < b.dist[k])
|
|
|
|
qual = 1;
|
|
|
|
else if(buginfo[c2->aitmp].dist[k] == b.dist[k])
|
|
|
|
qual = 0;
|
|
|
|
// printf("%d->#%d %d: %d\n", i, dir, c2->tmp, qual);
|
|
|
|
if(qual > bqual) bqual = qual, q=0;
|
|
|
|
if(qual == bqual) gmoves[q++] = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!q) { if(c->land == laHive) c->landparam += 3; continue; }
|
|
|
|
int d = gmoves[hrand(q)];
|
|
|
|
cell *c2 = c->mov[d];
|
2017-06-09 01:41:33 +00:00
|
|
|
if(c2->monst || isPlayerOn(c2)) {
|
2016-08-26 09:58:03 +00:00
|
|
|
eMonster killed = c2->monst;
|
2017-06-09 01:41:33 +00:00
|
|
|
if(isPlayerOn(c2)) killed = moPlayer;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(isBug(killed)) battlecount++;
|
2017-06-09 01:41:33 +00:00
|
|
|
else if(killed != moPlayer && !fightspam(c2))
|
|
|
|
addMessage(XLAT("%The1 fights with %the2!", c->monst, killed));
|
2018-01-03 20:49:14 +00:00
|
|
|
attackMonster(c2, AF_NORMAL | AF_GETPLAYER, c->monst);
|
2016-08-26 09:58:03 +00:00
|
|
|
// killMonster(c);
|
|
|
|
if(isBug(killed)) {
|
|
|
|
c2->monst = moDeadBug, deadbug.push_back(c2);
|
|
|
|
bugcount[killed - moBug0]--;
|
|
|
|
}
|
|
|
|
// c->monst = moDeadBug, deadbug.push_back(c);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
moveMonster(c2, c);
|
|
|
|
// pheromones!
|
|
|
|
if(c->land == laHive && c->landparam < 90) c->landparam += 5;
|
|
|
|
if(c2->land == laHive && c2->landparam < 90) c2->landparam += 5;
|
|
|
|
// if(isHive(c2->land)) c2->land = eLand(laHive0+k);
|
|
|
|
/* if(c2->item == itRoyalJelly && !isQueen(m)) {
|
|
|
|
// advance!
|
|
|
|
c2->monst = eMonster(m+BUGCOLORS);
|
|
|
|
c2->item = itNone;
|
|
|
|
} */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
for(int i=0; i<size(deadbug); i++) deadbug[i]->monst = moNone;
|
|
|
|
if(battlecount)
|
|
|
|
addMessage(XLAT("The Hyperbugs are fighting!"));
|
|
|
|
|
|
|
|
int maxbug = 0;
|
|
|
|
for(int k=0; k<BUGCOLORS; k++) if(bugcount[k] > maxbug) maxbug = bugcount[k];
|
|
|
|
|
|
|
|
achievement_count("BUG", maxbug, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bugcitycell(cell *c, int d) {
|
|
|
|
short& i = c->aitmp;
|
|
|
|
if(i >= 0 && i < size(buginfo) && buginfo[i].where == c)
|
|
|
|
return;
|
|
|
|
i = size(buginfo);
|
|
|
|
buginfo_t b;
|
|
|
|
b.where = c;
|
|
|
|
b.dist[0] = d;
|
|
|
|
buginfo.push_back(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void createBugArmy(cell *c) {
|
|
|
|
int k = randomHyperbug() - moBug0;
|
|
|
|
int minbugs = 50, maxbugs = 50;
|
|
|
|
int var = 5 + items[itRoyalJelly];
|
|
|
|
if(var>25) var=25;
|
|
|
|
// minbugs += 100; maxbugs += 100;
|
|
|
|
minbugs -= var; maxbugs += var;
|
|
|
|
maxbugs += items[itRoyalJelly];
|
|
|
|
int numbugs = minbugs + hrand(maxbugs - minbugs + 1);
|
|
|
|
|
|
|
|
/* int i = items[itRoyalJelly];
|
|
|
|
int chance = 20 + 25 * i + 9000;
|
|
|
|
// i=0: 16%
|
|
|
|
// i=10: 73%
|
|
|
|
// i=50: 1270 vs 6000
|
|
|
|
eMonster m = eMonster(moBug0 + hrand(BUGCOLORS));
|
|
|
|
if(c->wall) return;
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cell *c2 = createMov(c,i);
|
|
|
|
if(hrand(100+chance) < chance) {
|
|
|
|
if(!c2->wall) c2->monst = m;
|
|
|
|
for(int j=2; j<=c2->type-2; j++) {
|
|
|
|
int jj = (j+c->spn[i]) % c2->type;
|
|
|
|
cell *c3 = createMov(c2, jj);
|
|
|
|
if(hrand(6000+chance) < chance && !c3->wall)
|
|
|
|
c3->monst = m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c->monst = eMonster(m + BUGCOLORS); */
|
|
|
|
|
|
|
|
int gdir = -1;
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
if(c->mov[i] && c->mov[i]->mpdist < c->mpdist) gdir = i;
|
|
|
|
}
|
|
|
|
if(!gdir) return;
|
|
|
|
cellwalker bf(c, gdir);
|
|
|
|
int radius = 9;
|
2017-11-03 21:25:08 +00:00
|
|
|
if(getDistLimit() <= 6) radius = 6;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(chaosmode) radius = 5;
|
2017-11-03 21:25:08 +00:00
|
|
|
if(chaosmode && getDistLimit() <= 5) radius = 4;
|
|
|
|
if(getDistLimit() <= 3) radius = 3;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=2; i<radius; i++) {
|
|
|
|
if(bf.c->type == 6)
|
2018-03-24 11:59:01 +00:00
|
|
|
bf += 3;
|
2016-08-26 09:58:03 +00:00
|
|
|
else
|
2018-03-24 11:59:01 +00:00
|
|
|
bf += 3 + hrand(2);
|
|
|
|
bf += wstep;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
cell *citycenter = bf.c;
|
|
|
|
buginfo.clear();
|
|
|
|
|
|
|
|
|
|
|
|
// mark the area with BFS
|
|
|
|
bugcitycell(citycenter, 0);
|
|
|
|
for(int i=0; i<size(buginfo); i++) {
|
|
|
|
buginfo_t& b(buginfo[i]);
|
|
|
|
cell *c = b.where;
|
|
|
|
int d = b.dist[0];
|
|
|
|
// ERRORS!
|
|
|
|
if(c->land != laHive && c->land != laNone) return;
|
|
|
|
if(c->bardir != NODIR) return;
|
|
|
|
if(c->land == laHive && c->landparam >= 100) return;
|
|
|
|
// bfs
|
|
|
|
if(d < radius) for(int t=0; t<c->type; t++)
|
|
|
|
bugcitycell(createMov(c,t), d+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// place everything
|
|
|
|
for(int i=0; i<size(buginfo); i++) {
|
|
|
|
buginfo_t& b(buginfo[i]);
|
|
|
|
cell *c = b.where;
|
|
|
|
int d = b.dist[0];
|
|
|
|
if(d <= 1 && c->wall == waNone)
|
|
|
|
c->item = itRoyalJelly;
|
2017-03-23 10:53:57 +00:00
|
|
|
preventbarriers(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
if(d == 9 || d == 6 || d == 3)
|
|
|
|
c->barleft = eLand(d/3),
|
|
|
|
c->barright = eLand(k);
|
|
|
|
else
|
|
|
|
c->barleft = laNone;
|
|
|
|
if(numbugs && c->wall == waNone)
|
|
|
|
c->monst = eMonster(moBug0 + k), numbugs--;
|
|
|
|
c->land = laHive;
|
|
|
|
// prevent barriers
|
|
|
|
if(c->mpdist == INFD) c->mpdist = BUGLEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float& HEAT(cell *c) { return c->LHU.heat; }
|
|
|
|
|
|
|
|
namespace heat {
|
|
|
|
|
2017-09-30 09:46:41 +00:00
|
|
|
void affect(cell *c, double delta) {
|
|
|
|
if(isIcyLand(c)) HEAT(c) += delta;
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
double absheat(cell *c) {
|
|
|
|
if(c->land == laCocytus) return HEAT(c) -.6;
|
2017-09-30 09:46:41 +00:00
|
|
|
if(c->land == laIce || c->land == laBlizzard) return HEAT(c) -.4;
|
2016-08-26 09:58:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double celsius(cell *c) { return absheat(c) * 60; }
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
// adjust to the improved heat transfer algorithm in 9.4
|
|
|
|
const float FIX94 = 1.5;
|
2017-09-02 22:33:35 +00:00
|
|
|
|
|
|
|
vector<cell*> offscreen_heat, offscreen_fire; // offscreen cells to take care off
|
|
|
|
|
|
|
|
void processheat(double rate = 1) {
|
2016-08-26 09:58:03 +00:00
|
|
|
if(markOrb(itOrbSpeed)) rate /= 2;
|
2017-09-02 22:33:35 +00:00
|
|
|
int oldmelt = kills[0];
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
vector<cell*> offscreen2;
|
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
sval++;
|
|
|
|
|
2018-04-03 21:34:47 +00:00
|
|
|
int gr = gamerange();
|
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
for(cell *c: offscreen_heat) {
|
2018-04-03 21:34:47 +00:00
|
|
|
if(c->cpdist > gr && !doall) {
|
2017-09-02 22:33:35 +00:00
|
|
|
if(eq(c->aitmp, sval)) continue;
|
|
|
|
c->aitmp = sval;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(isIcyLand(c)) {
|
|
|
|
if(HEAT(c) < .01 && HEAT(c) > -.01)
|
|
|
|
HEAT(c) = 0;
|
|
|
|
else {
|
|
|
|
HEAT(c) *= 1 - rate/10;
|
2017-09-02 22:33:35 +00:00
|
|
|
offscreen2.push_back(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
offscreen_heat = move(offscreen2);
|
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
|
|
|
double xrate = (c->land == laCocytus && shmup::on) ? rate/3 : rate;
|
2018-01-06 21:34:03 +00:00
|
|
|
if(nonbitrunc) xrate *= 1.7;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(!shmup::on) xrate /= FIX94;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(isIcyLand(c))
|
|
|
|
HEAT(c) += (markOrb(itOrbWinter) ? -1.2 : 1.2) * xrate;
|
|
|
|
}
|
|
|
|
|
2017-04-04 09:13:15 +00:00
|
|
|
vector<cell*>& allcells = currentmap->allcells();
|
2017-03-23 10:53:57 +00:00
|
|
|
|
|
|
|
int dcs = size(allcells);
|
|
|
|
|
|
|
|
vector<ld> hmods(dcs, 0);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
for(int i=0; i<dcs; i++) {
|
2017-03-23 10:53:57 +00:00
|
|
|
cell *c = allcells[i];
|
2017-04-14 18:12:23 +00:00
|
|
|
double xrate = (c->land == laCocytus && shmup::on) ? 1/3. : 1;
|
2018-01-06 21:34:03 +00:00
|
|
|
if(nonbitrunc) xrate *= 1.7;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(!shmup::on) xrate /= FIX94;
|
2018-04-03 21:34:47 +00:00
|
|
|
if(c->cpdist > gr && !doall) break;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(isIcyLand(c)) {
|
2017-03-23 10:53:57 +00:00
|
|
|
ld hmod = 0;
|
|
|
|
|
|
|
|
if(c->monst == moRanger) hmod += 3 * xrate;
|
|
|
|
if(c->monst == moDesertman) hmod += 4 * xrate;
|
|
|
|
if(c->monst == moMonkey) hmod += xrate;
|
|
|
|
if(c->wall == waDeadTroll) hmod -= 2 * xrate;
|
|
|
|
if(c->wall == waDeadTroll2) hmod -= 1.5 * xrate;
|
|
|
|
if(c->wall == waBigStatue) hmod -= .5 * xrate;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c->monst == moLesser || c->monst == moLesserM || c->monst == moGreater || c->monst == moGreaterM)
|
2017-03-23 10:53:57 +00:00
|
|
|
hmod += (c->land == laCocytus ? 1.5 : 10) * xrate;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c->monst == moGreaterShark)
|
2017-03-23 10:53:57 +00:00
|
|
|
hmod += 2 * xrate;
|
|
|
|
if(c->monst == moCultist) hmod += 3 * xrate;
|
|
|
|
if(c->monst == moCultistLeader) hmod += 4 * xrate;
|
|
|
|
if(c->monst == moPyroCultist) hmod += 6 * xrate;
|
|
|
|
if(c->monst == moFireFairy) hmod += 6 * xrate;
|
|
|
|
if(c->monst == moFireElemental) hmod += 8 * xrate;
|
|
|
|
if(isDragon(c->monst)) hmod += 2 * xrate;
|
|
|
|
if(c->monst == moGhost) hmod -= xrate;
|
|
|
|
if(c->monst == moFriendlyGhost) hmod -= xrate;
|
|
|
|
if(c->monst == moSkeleton) hmod -= .2 * xrate;
|
|
|
|
if(c->monst == moDraugr) hmod -= .75 * xrate;
|
|
|
|
if(c->monst == moWaterElemental) hmod -= xrate;
|
|
|
|
if(c->monst == moAirElemental) hmod -= .4 * xrate;
|
|
|
|
if(isFire(c)) hmod += 4 * xrate;
|
|
|
|
if(isPrincess(c->monst)) hmod += (markEmpathy(itOrbWinter) ? -1.2 : 1.2) * xrate;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-10-10 10:42:30 +00:00
|
|
|
forCellEx(ct, c) {
|
|
|
|
if(!isIcyLand(ct) && isFire(ct))
|
|
|
|
hmod += xrate*.1;
|
|
|
|
if(ct->land == laVolcano)
|
|
|
|
hmod += xrate * (ct->wall == waMagma ? .4 : .2);
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-09-30 09:46:41 +00:00
|
|
|
forCellEx(ct, c) {
|
|
|
|
if(!isIcyLand(ct)) {
|
2016-08-26 09:58:03 +00:00
|
|
|
// make sure that we can still enter Cocytus,
|
|
|
|
// it won't heat up right away even without Orb of Winter or Orb of Speed
|
2017-10-16 23:51:27 +00:00
|
|
|
if(isPlayerOn(ct) && (c->land != laCocytus || markOrb(itOrbWinter)))
|
2017-04-14 18:12:23 +00:00
|
|
|
hmod += (markOrb(itOrbWinter) ? -1.2 : 1.2) / 4 * xrate;
|
2016-08-26 09:58:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-09-30 09:46:41 +00:00
|
|
|
ld hdiff = absheat(ct) - absheat(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
hdiff /= 10;
|
2017-09-30 09:46:41 +00:00
|
|
|
|
|
|
|
if(ct->land == laBlizzard) {
|
|
|
|
int v = (windmap::at(ct) - windmap::at(c)) & 255;
|
|
|
|
if(v > 128) v -= 256;
|
|
|
|
if(v < windmap::NOWINDFROM && v > -windmap::NOWINDFROM)
|
|
|
|
hdiff = hdiff * (1 - v * 5. / windmap::NOWINDFROM);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(shmup::on && (c->land == laCocytus || ct->land == laCocytus))
|
2016-08-26 09:58:03 +00:00
|
|
|
hdiff /= 3;
|
2017-03-23 10:53:57 +00:00
|
|
|
// if(c->mov[j]->cpdist > 7 && !quotient) hdiff += -HEAT(c) / 30;
|
2016-08-26 09:58:03 +00:00
|
|
|
hmod += hdiff;
|
|
|
|
}
|
2017-09-30 09:46:41 +00:00
|
|
|
// printf("%d ", vsum);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-04-14 18:12:23 +00:00
|
|
|
hmods[i] = hmod;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
if(HEAT(c) && !doall)
|
|
|
|
offscreen_heat.push_back(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
#define MELTCOLOR 0xA04040
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=0; i<dcs; i++) {
|
2017-03-23 10:53:57 +00:00
|
|
|
cell *c = allcells[i];
|
2017-07-22 23:33:27 +00:00
|
|
|
if(!isIcyLand(c)) continue;
|
2017-03-23 10:53:57 +00:00
|
|
|
HEAT(c) += hmods[i] * rate;
|
|
|
|
if(c->monst == moCrystalSage && HEAT(c) >= SAGEMELT) {
|
|
|
|
addMessage(XLAT("%The1 melts away!", c->monst));
|
|
|
|
fallMonster(c);
|
|
|
|
}
|
|
|
|
if(c->wall == waIcewall && HEAT(c) > .4)
|
|
|
|
drawParticles(c, MELTCOLOR, 4, 60),
|
|
|
|
c->wall = waNone, kills[0]++;
|
|
|
|
if(c->wall == waFrozenLake && HEAT(c) > (c->land == laCocytus ? .6 : .4))
|
|
|
|
drawParticles(c, MELTCOLOR, 4, 60),
|
|
|
|
playSound(c, "trapdoor", 50),
|
|
|
|
c->wall = waLake, kills[0]++;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
if(c->wall == waLake && HEAT(c) < (c->land == laCocytus ? -.4 : .4) && c->monst != moGreaterShark) {
|
|
|
|
c->wall = waFrozenLake;
|
|
|
|
if(c->monst == moShark || c->monst == moCShark) {
|
|
|
|
addMessage(XLAT("%The1 is frozen!", c->monst));
|
2017-03-23 10:53:57 +00:00
|
|
|
fallMonster(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(kills[0] != oldmelt) bfs();
|
|
|
|
}
|
2017-09-02 22:33:35 +00:00
|
|
|
|
|
|
|
vector<pair<cell*, int> > newfires;
|
|
|
|
|
|
|
|
void processfires() {
|
|
|
|
newfires.clear();
|
|
|
|
|
|
|
|
vector<cell*> offscreen2;
|
|
|
|
|
|
|
|
sval++;
|
|
|
|
|
2017-04-04 09:13:15 +00:00
|
|
|
vector<cell*>& allcells = currentmap->allcells();
|
2017-06-09 01:41:33 +00:00
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
for(int x: {0,1}) for(cell *c: x==0 ? allcells : offscreen_fire) {
|
|
|
|
if(eq(c->aitmp, sval)) continue;
|
|
|
|
c->aitmp = sval;
|
|
|
|
|
2017-12-21 14:12:25 +00:00
|
|
|
if(isFireOrMagma(c)) {
|
|
|
|
if(c->wall == waMagma) c->wparam = 20;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
cell *last = c->mov[c->type-1];
|
|
|
|
|
|
|
|
forCellEx(c2, c) {
|
|
|
|
|
|
|
|
if(c->wall == waPartialFire) {
|
|
|
|
// two partial fires adjacent are necessary to spread
|
|
|
|
bool ok = false;
|
|
|
|
forCellEx(c3, c2) if(c3 != c && c3->wall == waPartialFire)
|
|
|
|
ok = true;
|
|
|
|
if(!ok) continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c2->wall == waNone && c2->land == laRose && c->wparam >= 10)
|
|
|
|
newfires.emplace_back(c2, c->wparam);
|
|
|
|
if(c2->wall == waFire && c2->land == laRose && c->wparam >= 10 && c2->wparam < c->wparam/2)
|
|
|
|
newfires.emplace_back(c2, c->wparam);
|
|
|
|
if(againstWind(c, c2) && c->wall != waEternalFire && c->wparam >= 10) {
|
|
|
|
if(isFire(c2)) {
|
|
|
|
if(c2->wparam < c->wparam/2)
|
|
|
|
newfires.emplace_back(c2, c->wparam);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newfires.emplace_back(c2, c->wparam);
|
|
|
|
useup(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c2->land == laDryForest && c2->wall != waEternalFire) {
|
|
|
|
c2->landparam++;
|
|
|
|
if(c2->landparam >= (isStandardTree(c2) ? 1 : 10)) newfires.emplace_back(c2, 12);
|
|
|
|
else offscreen2.push_back(c);
|
|
|
|
}
|
|
|
|
else if(c2->wall == waVinePlant || c2->wall == waRose || c2->wall == waSaloon ||
|
|
|
|
c2->wall == waWeakBranch || c2->wall == waCanopy || c2->wall == waTrunk || c2->wall == waSolidBranch ||
|
2017-12-29 00:10:47 +00:00
|
|
|
c2->wall == waBigBush || c2->wall == waSmallBush || c2->wall == waBonfireOff || c2->wall == waSmallTree ||
|
|
|
|
c2->wall == waDock)
|
2017-09-02 22:33:35 +00:00
|
|
|
newfires.emplace_back(c2, 12);
|
|
|
|
else if(cellHalfvine(c2) && last && last->wall == c2->wall)
|
|
|
|
newfires.emplace_back(c2, 12);
|
|
|
|
// both halfvines have to be near fire at once
|
|
|
|
last = c2;
|
2017-06-09 01:41:33 +00:00
|
|
|
}
|
2017-09-02 22:33:35 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-06-09 01:41:33 +00:00
|
|
|
|
2017-09-02 22:33:35 +00:00
|
|
|
if(hasTimeout(c)) {
|
2017-12-29 00:10:47 +00:00
|
|
|
if(c->mpdist == 8 && (c->land == laWineyard || c->land == laEndorian || c->land == laDocks)) {
|
2017-09-02 22:33:35 +00:00
|
|
|
// do not expire, do not store in 'offscreen', do not generate more land
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
useup(c);
|
|
|
|
offscreen2.push_back(c);
|
|
|
|
}
|
2017-09-30 09:46:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-12 09:33:26 +00:00
|
|
|
if(c->wall == waArrowTrap && c->wparam && !shmup::on) {
|
2017-09-30 09:46:41 +00:00
|
|
|
c->wparam++;
|
|
|
|
if(c->wparam == 3) {
|
|
|
|
if(canAttack(c, moArrowTrap, c, c->monst, AF_GETPLAYER))
|
2018-01-03 20:49:14 +00:00
|
|
|
attackMonster(c, AF_NORMAL | AF_MSG | AF_GETPLAYER, moArrowTrap);
|
2017-09-30 09:46:41 +00:00
|
|
|
}
|
|
|
|
if(c->wparam == 4) c->wparam = 0;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-09-02 22:33:35 +00:00
|
|
|
|
|
|
|
for(int i=0; i<size(newfires); i++) {
|
|
|
|
cell* c = newfires[i].first;
|
|
|
|
int qty = newfires[i].second;
|
|
|
|
qty /= 2;
|
|
|
|
if(c->wall == waBonfireOff) activateActiv(c, false);
|
|
|
|
else if(cellHalfvine(c)) destroyHalfvine(c, waPartialFire, 6);
|
|
|
|
else makeflame(c, qty, false);
|
|
|
|
if(c->wparam < qty) c->wparam = qty;
|
|
|
|
offscreen2.push_back(c);
|
|
|
|
if(c->land == laRose || c->land == laWildWest || c->land == laOvergrown || isHaunted(c->land) || c->land == laMountain || c->land == laIce) {
|
|
|
|
for(int j=c->mpdist-1; j>=7; j--) setdist(c, j, NULL);
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
2017-09-02 22:33:35 +00:00
|
|
|
|
|
|
|
offscreen_fire = move(offscreen2);
|
|
|
|
}
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gardener = false;
|
|
|
|
|
|
|
|
bool lifebrought = false; // was Life brought to the Dead Caves?
|
|
|
|
|
|
|
|
void livecaves() {
|
2017-04-04 09:13:15 +00:00
|
|
|
vector<cell*>& allcells = currentmap->allcells();
|
2017-03-23 10:53:57 +00:00
|
|
|
int dcs = size(allcells);
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
vector<cell*> bringlife;
|
2018-04-03 21:34:47 +00:00
|
|
|
int gr = gamerange();
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
for(int i=0; i<dcs; i++) {
|
2017-03-23 10:53:57 +00:00
|
|
|
cell *c = allcells[i];
|
2018-04-03 21:34:47 +00:00
|
|
|
if(!doall && c->cpdist > gr+1) break;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
if(c->wall == waCavefloor || c->wall == waCavewall || c->wall == waDeadTroll) {
|
2016-08-26 09:58:03 +00:00
|
|
|
c->aitmp = 0;
|
|
|
|
if(c->monst == moDarkTroll) c->monst = moTroll;
|
|
|
|
if(c->item || c->monst || c->cpdist == 0) continue;
|
2017-09-03 10:01:31 +00:00
|
|
|
forCellEx(c2, c) {
|
|
|
|
eWall w = c2->wall;
|
|
|
|
if(w == waDeadfloor) c->aitmp++, bringlife.push_back(c2);
|
|
|
|
else if(w == waDeadwall || (w == waDeadfloor2 && !c2->monst))
|
|
|
|
c->aitmp--, bringlife.push_back(c2);
|
|
|
|
else if(w == waCavefloor) c->aitmp++;
|
|
|
|
else if(w == waCavewall) c->aitmp--;
|
|
|
|
else if(w == waRubble) c->aitmp--;
|
|
|
|
else if(w == waGargoyle) c->aitmp--;
|
|
|
|
else if(w == waGargoyleFloor) c->aitmp--;
|
|
|
|
else if(w == waGargoyleBridge) c->aitmp--;
|
2017-10-29 09:52:02 +00:00
|
|
|
else if(w == waStone) ;
|
2017-09-03 10:01:31 +00:00
|
|
|
else if(w == waDeadTroll) c->aitmp -= 5;
|
|
|
|
else if(w == waDeadTroll2) c->aitmp -= 3;
|
|
|
|
else if(w == waPetrified || w == waPetrifiedBridge) c->aitmp -= 2;
|
|
|
|
else if(w == waVinePlant) c->aitmp--;
|
|
|
|
else if(chaosmode && c2->land != laCaves && c2->land != laEmerald) ;
|
|
|
|
else if(c2->land == laTrollheim) ; // trollheim floor does not count
|
|
|
|
else if(w != waBarrier) c->aitmp += 5;
|
2017-03-23 10:53:57 +00:00
|
|
|
|
|
|
|
if(sword::at(c)) c->aitmp += 500;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
2017-09-03 10:01:31 +00:00
|
|
|
if(c2->cpdist == 0 && markOrb(itOrbDigging)) c->aitmp+=100;
|
|
|
|
if(items[itOrbEmpathy] && isFriendly(c2) && markEmpathy(itOrbDigging))
|
2016-08-26 09:58:03 +00:00
|
|
|
c->aitmp+=100;
|
2017-09-03 10:01:31 +00:00
|
|
|
if(w == waThumperOn) c->aitmp+=100;
|
|
|
|
if(w == waFire) c->aitmp+=100;
|
|
|
|
if(w == waBigStatue) c->aitmp-=100;
|
|
|
|
if(c2->item && !peace::on) c->aitmp+=2;
|
|
|
|
if(c2->monst == moZombie) c->aitmp += 10;
|
|
|
|
if(c2->monst == moGhost) c->aitmp += 10;
|
|
|
|
if(c2->monst == moTentacleGhost) c->aitmp += 10;
|
|
|
|
if(c2->monst == moFriendlyGhost) c->aitmp += 10;
|
|
|
|
if(c2->monst == moSkeleton) c->aitmp ++;
|
|
|
|
if(c2->monst == moGargoyle) c->aitmp--;
|
|
|
|
if(c2->monst == moDraugr) c->aitmp--;
|
|
|
|
if(isDragon(c2->monst)) c->aitmp++;
|
|
|
|
if(c2->monst == moNecromancer) c->aitmp += 10;
|
|
|
|
if(c2->monst == moWormtail) c->aitmp++;
|
|
|
|
if(c2->monst == moTentacletail) c->aitmp-=2;
|
|
|
|
if(isIvy(c2)) c->aitmp--;
|
|
|
|
if(isDemon(c2)) c->aitmp-=3;
|
|
|
|
// if(c2->monst) c->tmp++;
|
|
|
|
// if(c2->monst == moTroll) c->tmp -= 3;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(c->land == laLivefjord) {
|
|
|
|
c->aitmp = 0;
|
|
|
|
if(c->monst == moWaterElemental)
|
|
|
|
c->aitmp += 1000;
|
|
|
|
if(isPlayerInBoatOn(c) && markOrb(itOrbWater))
|
|
|
|
c->aitmp += 1000;
|
|
|
|
if(c->monst == moEarthElemental)
|
|
|
|
c->aitmp -= 1000;
|
|
|
|
if(isPlayerOn(c) && markOrb(itOrbDigging))
|
|
|
|
c->aitmp -= 1000;
|
|
|
|
for(int j=0; j<c->type; j++) if(c->mov[j]) {
|
|
|
|
cell *c2 = c->mov[j];
|
|
|
|
if(c2->wall == waNone || c2->wall == waStrandedBoat)
|
|
|
|
c->aitmp -= (c2->land == laLivefjord ? 1 : 100);
|
2017-09-03 10:01:31 +00:00
|
|
|
if(c2->wall == waTempFloor || c2->wall == waTempBridge || c2->wall == waTempBridgeBlocked)
|
2016-08-26 09:58:03 +00:00
|
|
|
;
|
|
|
|
else if(c2->wall == waDeadTroll || c2->wall == waDeadTroll2 || c2->wall == waThumperOn || isFire(c2) || snakelevel(c2))
|
|
|
|
c->aitmp -= 10;
|
2017-09-03 10:01:31 +00:00
|
|
|
else if(c2->wall == waPetrified || c2->wall == waPetrifiedBridge)
|
2017-03-23 10:53:57 +00:00
|
|
|
c->aitmp -= 10;
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c2->wall == waBigStatue)
|
|
|
|
c->aitmp -= 10;
|
|
|
|
if(c2->wall == waSea || c2->wall == waBoat)
|
|
|
|
c->aitmp += (c2->land == laLivefjord ? 1 : 100);
|
|
|
|
if(c2->monst == moWaterElemental)
|
|
|
|
c->aitmp += 1000;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(isPlayerOn(c2) && c2->wall == waBoat && markOrb(itOrbWater))
|
2016-08-26 09:58:03 +00:00
|
|
|
c->aitmp += 1000;
|
|
|
|
if(c2->monst == moEarthElemental)
|
|
|
|
c->aitmp -= 1000;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(isPlayerOn(c2) && markOrb(itOrbDigging))
|
2016-08-26 09:58:03 +00:00
|
|
|
c->aitmp -= 1000;
|
|
|
|
if(items[itOrbEmpathy] && isFriendly(c2) && markEmpathy(itOrbDigging))
|
|
|
|
c->aitmp -= 1000;
|
|
|
|
|
|
|
|
if(c2->wall == waBarrier) {
|
|
|
|
bool landbar = false;
|
|
|
|
for(int k=0; k<c2->type; k++)
|
|
|
|
if(c2->mov[k]) {
|
|
|
|
cell *c3 = c2->mov[k];
|
|
|
|
if(!isSealand(c3->land))
|
|
|
|
landbar = true;
|
|
|
|
}
|
|
|
|
if(landbar) c->aitmp -= 5;
|
|
|
|
else c->aitmp += 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<dcs; i++) {
|
2017-03-23 10:53:57 +00:00
|
|
|
cell *c = allcells[i];
|
2018-04-03 21:34:47 +00:00
|
|
|
if(!doall && c->cpdist > gr+1) break;
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
if(c->wall == waCavefloor || c->wall == waCavewall) {
|
|
|
|
// if(c->land != laCaves) continue;
|
|
|
|
// if(c->wall == waThumper || c->wall == waBonfire) continue;
|
|
|
|
|
|
|
|
if(c->aitmp > 0) c->wall = waCavefloor;
|
|
|
|
if(c->aitmp < 0) {
|
|
|
|
c->wall = waCavewall;
|
|
|
|
if(c->land != laCaves && c->land != laDeadCaves && c->land != laEmerald && !gardener) {
|
|
|
|
gardener = true;
|
|
|
|
achievement_gain("GARDENER");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(c->land == laLivefjord) {
|
|
|
|
if(c->aitmp > 0 && c->wall == waStrandedBoat) c->wall = waBoat;
|
|
|
|
if(c->aitmp > 0 && c->wall == waNone) {
|
|
|
|
if(c->item && c->cpdist == 1 && markOrb(itOrbWater))
|
|
|
|
collectItem(c);
|
|
|
|
c->wall = waSea;
|
|
|
|
}
|
|
|
|
if(c->aitmp < 0 && c->wall == waBoat) c->wall = waStrandedBoat;
|
|
|
|
if(c->aitmp < 0 && c->wall == waSea) c->wall = waNone;
|
2017-12-30 22:47:10 +00:00
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<size(bringlife); i++) {
|
|
|
|
cell *c = bringlife[i];
|
|
|
|
if(c->land == laDeadCaves && !lifebrought) {
|
|
|
|
lifebrought = true;
|
|
|
|
achievement_gain("LIFEBRINGER");
|
|
|
|
}
|
|
|
|
if(c->wall == waDeadfloor) c->wall = waCavefloor;
|
|
|
|
if(c->wall == waDeadfloor2) c->wall = waCavewall;
|
|
|
|
if(c->wall == waDeadwall) c->wall = waCavewall;
|
|
|
|
if(c->wall == waCavewall && c->item) c->wall = waCavefloor;
|
|
|
|
if(c->land == laDeadCaves) c->land = laCaves;
|
|
|
|
if(c->item == itSilver) c->item = itGold;
|
|
|
|
if(c->item == itGreenStone) c->item = itOrbLife;
|
|
|
|
if(c->monst == moEarthElemental) {
|
|
|
|
addMessage(XLAT("%The1 is destroyed by the forces of Life!", c->monst));
|
2017-03-23 10:53:57 +00:00
|
|
|
fallMonster(c);
|
2016-08-26 09:58:03 +00:00
|
|
|
c->item = itOrbDigging;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* evolver */
|
|
|
|
|
|
|
|
namespace tortoise {
|
|
|
|
map<cell*, cell*> emap;
|
|
|
|
map<cell*, int> babymap;
|
2017-05-28 22:16:17 +00:00
|
|
|
int last;
|
2016-08-26 09:58:03 +00:00
|
|
|
|
|
|
|
enum tflag {
|
|
|
|
tfShell, tfScute0, tfScute1, tfScute2, tfScute3,
|
|
|
|
tfEdge1, tfEdge, tfEdge3,
|
|
|
|
tfLongNeck, tfFront, tfRear, tfTail,
|
|
|
|
tfEyeHue, tfShellHue, tfScuteHue, tfSkinHue,
|
|
|
|
tfShellSat, tfScuteSat, tfSkinSat,
|
|
|
|
tfShellDark, tfSkinDark,
|
|
|
|
tfCOUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
const int numbits = (int) tfCOUNT;
|
|
|
|
const int mask = (1<<numbits)-1;
|
|
|
|
|
|
|
|
cell *get(cell *where) {
|
|
|
|
if(emap.count(where)) return emap[where];
|
|
|
|
return where;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getb(cell *where) { return getBits(get(where)); }
|
|
|
|
|
|
|
|
int countBits(int c) {
|
|
|
|
int bi = 0;
|
|
|
|
for(int i=0; i<numbits; i++) if((c >> i)&1) bi++;
|
|
|
|
return bi;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getBit(int bits, int id) { return (bits >> id) & 1; }
|
|
|
|
|
|
|
|
int getRandomBits() { return hrand(1 << numbits); }
|
|
|
|
|
|
|
|
bool seek() { return items[itBabyTortoise] % 5; }
|
|
|
|
int seekbits;
|
|
|
|
double seekval[numbits];
|
|
|
|
double currval[numbits];
|
|
|
|
|
|
|
|
void update(double& val, double target, int delta) {
|
|
|
|
double d = delta / 300.;
|
|
|
|
if(d>1) d = 1;
|
|
|
|
if(target>val+d) val += d;
|
|
|
|
else if(target<val-d) val -= d;
|
|
|
|
else val = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateVals(int delta) {
|
|
|
|
int currbits = getBits(cwt.c);
|
|
|
|
for(int i=0; i<numbits; i++)
|
2017-07-04 13:38:33 +00:00
|
|
|
update(seekval[i], seek() && !(peace::on && !peace::hint) ? getBit(seekbits, i) : .5, delta);
|
2016-08-26 09:58:03 +00:00
|
|
|
for(int i=0; i<numbits; i++)
|
|
|
|
update(currval[i], getBit(currbits, i), delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
double getScent(int bits) {
|
|
|
|
double res = 0;
|
|
|
|
for(int i=0; i<numbits; i++)
|
|
|
|
/* if(getBit(bits, i) != getBit(getBits(cwt.c), i))
|
|
|
|
res += (1 - 2*getBit(bits, i)); */
|
|
|
|
res += (2* seekval[i] - 1) * (getBit(bits, i) - currval[i]);
|
|
|
|
|
|
|
|
// seek curr bit => res
|
|
|
|
// 1 1 1 => 0
|
|
|
|
// 1 1 0 => -1
|
|
|
|
// 1 0 1 => +1
|
|
|
|
// 1 0 0 => 0
|
|
|
|
// 0 1 1 => 0
|
|
|
|
// 0 1 0 => +1
|
|
|
|
// 0 0 1 => -1
|
|
|
|
// 0 0 0 => 0
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int diff(int bits) { return countBits(bits ^ tortoise::seekbits); }
|
|
|
|
int progress(int bits) { return numbits - diff(bits); }
|
|
|
|
|
|
|
|
string measure(int bits) {
|
|
|
|
return "(" + its(progress(bits)) + "/" + its(tortoise::numbits) + ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dragon {
|
|
|
|
|
|
|
|
int whichturn; // which turn has the target been set on
|
|
|
|
cell *target; // actually for all Orb of Control
|
|
|
|
|
|
|
|
void pullback(cell *c) {
|
|
|
|
int maxlen = 1000;
|
|
|
|
while(maxlen-->0) {
|
|
|
|
cell *c2 = c->mov[c->mondir];
|
2017-03-23 10:53:57 +00:00
|
|
|
mountmove(c, c->mondir, true, c2);
|
2016-08-26 09:58:03 +00:00
|
|
|
c->monst = c2->monst;
|
|
|
|
c->hitpoints = c2->hitpoints;
|
2017-03-23 10:53:57 +00:00
|
|
|
animateMovement(c2, c, LAYER_BIG);
|
2016-08-26 09:58:03 +00:00
|
|
|
c->stuntime = 2;
|
|
|
|
if(c2->mondir == NODIR) { c->mondir = NODIR; c2->monst = moNone; return; }
|
|
|
|
c = c2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
bool dragbugs = false;
|
|
|
|
|
2016-08-26 09:58:03 +00:00
|
|
|
cell *findhead(cell *c) {
|
|
|
|
cell *cor = c;
|
|
|
|
int maxlen=1000;
|
|
|
|
findhead:
|
|
|
|
if(maxlen--<0) return c;
|
|
|
|
if(c->monst == moDragonHead) return c;
|
|
|
|
for(int i=0; i<c->type; i++)
|
2017-03-23 10:53:57 +00:00
|
|
|
if(c->mov[i] && isDragon(c->mov[i]->monst) && c->mov[i]->mondir == c->spn(i)) {
|
2016-08-26 09:58:03 +00:00
|
|
|
c = c->mov[i]; goto findhead;
|
|
|
|
}
|
2017-11-12 23:34:49 +00:00
|
|
|
if(cmode & sm::MAP) return c;
|
2017-04-14 18:12:23 +00:00
|
|
|
if(!conformal::includeHistory) {
|
|
|
|
printf("dragon bug #3 (%p -> %p)\n", cor, c);
|
|
|
|
dragbugs = true;
|
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
c->monst = moDragonHead; return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void validate(const char *where) {
|
|
|
|
dragbugs = false;
|
|
|
|
for(int i=0; i<size(dcal); i++)
|
|
|
|
if(dcal[i]->monst == moDragonTail)
|
|
|
|
findhead(dcal[i]);
|
|
|
|
if(dragbugs) {
|
|
|
|
printf("DRAGON BUG in %s\n", where);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int bodypart(cell *c, cell *head) {
|
|
|
|
int i = 0, j = 0;
|
|
|
|
int maxlen = 1000;
|
|
|
|
while(maxlen-->0) {
|
|
|
|
if(head == c) i = j;
|
|
|
|
j++;
|
|
|
|
if(head->mondir == NODIR) break;
|
|
|
|
head = head->mov[head->mondir];
|
|
|
|
}
|
|
|
|
if(i == 0) return 'h';
|
|
|
|
if(i == 1) return 'l';
|
|
|
|
if(i == j-2) return '2';
|
|
|
|
if(i == j-1) return 't';
|
|
|
|
if(i == 2) return 'w';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
void kill(cell *c, eMonster who) {
|
2016-08-26 09:58:03 +00:00
|
|
|
int delay = false;
|
|
|
|
kills[moDragonHead]++;
|
|
|
|
int penalty = 0;
|
|
|
|
int maxlen = 1000;
|
|
|
|
while(maxlen-->0) {
|
|
|
|
makeflame(c, 5, false);
|
2017-03-23 10:53:57 +00:00
|
|
|
eMonster m = c->monst;
|
|
|
|
drawFireParticles(c, 16);
|
2016-08-26 09:58:03 +00:00
|
|
|
c->monst = moNone;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(checkOrb(who, itOrbUndeath))
|
|
|
|
c->monst = moFriendlyGhost;
|
|
|
|
if(checkOrb(who, itOrbStone))
|
|
|
|
c->wparam = m, c->wall = waPetrified;
|
|
|
|
else if(c->wall == waFire) {
|
2016-08-26 09:58:03 +00:00
|
|
|
if(delay) delay = false;
|
|
|
|
else {
|
|
|
|
if(c->land != laDragon) penalty += 3;
|
|
|
|
if(penalty) penalty--;
|
|
|
|
else {
|
|
|
|
c->item = itDragon;
|
|
|
|
c->landparam = shmup::on ? shmup::curtime : turncount;
|
|
|
|
delay = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c->mondir == NODIR) break;
|
|
|
|
c = c->mov[c->mondir];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalhp(cell *c) {
|
|
|
|
int total = 0;
|
|
|
|
int maxlen = 1000;
|
|
|
|
while(maxlen-->0) {
|
|
|
|
if(!isDragon(c->monst)) {
|
2017-04-14 18:12:23 +00:00
|
|
|
if(!conformal::includeHistory) printf("dragon bug #4\n");
|
2016-08-26 09:58:03 +00:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
total += c->hitpoints;
|
|
|
|
if(c->mondir == NODIR) return total;
|
|
|
|
c = c->mov[c->mondir];
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SWAPBITFIELD(x,y,t) { t bak=x; x=y; y=bak; }
|
|
|
|
|
|
|
|
void pullfront(cell *c, cell *until) {
|
|
|
|
int maxlen = 1000;
|
2017-03-23 10:53:57 +00:00
|
|
|
static vector<cell*> allcells;
|
|
|
|
allcells.clear();
|
2016-08-26 09:58:03 +00:00
|
|
|
while(maxlen-->0) {
|
2017-03-23 10:53:57 +00:00
|
|
|
allcells.push_back(c);
|
|
|
|
// SWAPBITFIELD(c->monst, buffer->monst, eMonster);
|
|
|
|
// SWAPBITFIELD(c->hitpoints, buffer->hitpoints, int);
|
2016-08-26 09:58:03 +00:00
|
|
|
c->stuntime = 2;
|
|
|
|
if(c == until) {
|
2017-03-23 10:53:57 +00:00
|
|
|
for(int i=size(allcells)-2; i>=0; i--) {
|
|
|
|
cell *cmt = allcells[i+1];
|
|
|
|
cell *cft = allcells[i];
|
|
|
|
cmt->hitpoints = cft->hitpoints;
|
|
|
|
cmt->monst = cft->monst;
|
|
|
|
cft->monst = moNone;
|
|
|
|
mountmove(cmt, cmt->mondir, true, cft);
|
|
|
|
animateMovement(cft, cmt, LAYER_BIG);
|
|
|
|
}
|
|
|
|
while(c->mondir != NODIR) {
|
2016-08-26 09:58:03 +00:00
|
|
|
c = c->mov[c->mondir];
|
|
|
|
c->stuntime = 2;
|
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
break;
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
if(c->mondir == NODIR) { printf("dragon bug\n"); break; }
|
|
|
|
c = c->mov[c->mondir];
|
2017-04-14 18:12:23 +00:00
|
|
|
if(!c) {
|
|
|
|
if(!conformal::includeHistory) printf("dragon bug #2\n");
|
|
|
|
break;
|
|
|
|
}
|
2016-08-26 09:58:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool move(cell *dt, cell *df) {
|
|
|
|
if(df->monst == moDragonHead) {
|
|
|
|
dt->mondir = neighborId(dt,df);
|
|
|
|
// printf("pull back\n");
|
|
|
|
pullback(dt);
|
|
|
|
dt->stuntime = 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(df->monst == moDragonTail && df->stuntime == 0) {
|
|
|
|
cell *head = findhead(df);
|
|
|
|
if(df->mondir == NODIR) {
|
|
|
|
df->mondir = neighborId(df,dt);
|
|
|
|
dt->mondir = NODIR;
|
|
|
|
// printf("pull all: head = %p, df=%p, dt=%p\n", head, df, dt);
|
|
|
|
pullfront(head, dt);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cell *c2 = df->mov[df->mondir];
|
|
|
|
if(!c2) return false;
|
|
|
|
int id = neighborId(dt, c2);
|
|
|
|
if(id == -1) return false;
|
|
|
|
dt->mondir = id;
|
|
|
|
df->mondir = neighborId(df, dt);
|
|
|
|
// printf("pull front: head = %p, df=%p, dt=%p\n", head, df, dt);
|
|
|
|
pullfront(head, dt);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
|
|
|
|
namespace sword {
|
|
|
|
int angle[MAXPLAYER];
|
|
|
|
|
|
|
|
cell *pos(cell *c, int s) {
|
|
|
|
int t = c->type;
|
|
|
|
s *= 2;
|
|
|
|
s += S42/t;
|
|
|
|
s %= S84;
|
|
|
|
if(s<0) s += S84;
|
|
|
|
s /= (S84/t);
|
|
|
|
return c->mov[s];
|
|
|
|
}
|
|
|
|
|
|
|
|
eItem orbof(bool rev) { return rev ? itOrbSword2 : itOrbSword; }
|
|
|
|
int orbcount(bool rev) { return items[orbof(rev)]; }
|
|
|
|
|
|
|
|
cell *pos(int id, bool rev) {
|
|
|
|
if(!orbcount(rev)) return NULL;
|
|
|
|
return pos(playerpos(id), angle[id] + (rev ? S21 : 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool at(cell *where, bool noplayer) {
|
|
|
|
if(noplayer) return false;
|
|
|
|
if(!orbcount(0) && !orbcount(1)) return false;
|
|
|
|
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i)) for(int b=0; b<2; b++)
|
|
|
|
if(pos(i,b) == where) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool near(cell *where) {
|
|
|
|
if(at(where, false)) return true;
|
|
|
|
forCellEx(w2, where) if(at(w2, false)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// from c1 to c2
|
|
|
|
int shift(cell *c1, cell *c2, int angle) {
|
|
|
|
if(!c1 || !c2) return 0;
|
|
|
|
int s1 = neighborId(c1, c2);
|
|
|
|
int s2 = neighborId(c2, c1);
|
|
|
|
if(s1 < 0 || s2 < 0) return angle;
|
|
|
|
if(c1->mirror(s1))
|
|
|
|
return ((s2*S42/c2->type - angle + s1*S42/c1->type) + S21) % S42;
|
|
|
|
else
|
|
|
|
return ((s2*S42/c2->type - s1*S42/c1->type) + S21 + angle) % S42;
|
|
|
|
}
|
|
|
|
|
2017-08-14 19:32:02 +00:00
|
|
|
void shuffle(int i) {
|
2018-01-06 21:34:03 +00:00
|
|
|
sword::angle[i] = euclid ? S7*hrand(6) : nonbitrunc ? 3*hrand(S14)+1 : hrand(S42);
|
2017-08-14 19:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
items[itOrbSword] = items[itOrbSword2] = 0;
|
|
|
|
shuffle(multi::cpid);
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
void shuffle() {
|
2017-08-14 19:32:02 +00:00
|
|
|
for(int i=0; i<MAXPLAYER; i++) shuffle(i);
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace kraken {
|
|
|
|
|
|
|
|
cell *head(cell *c) {
|
|
|
|
if(c->monst == moKrakenH) return c;
|
|
|
|
if(c->monst == moKrakenT) return c->mov[c->mondir];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void kill(cell *c, eMonster who) {
|
|
|
|
drawParticles(c, minf[moKrakenH].color, 16);
|
|
|
|
c->monst = moNone;
|
|
|
|
if(checkOrb(who, itOrbUndeath)) c->monst = moFriendlyGhost;
|
|
|
|
if(c->land == laKraken && !c->item) c->item = itKraken;
|
|
|
|
kills[moKrakenH]++;
|
|
|
|
if(checkOrb(who, itOrbStone)) c->wall = waNone;
|
|
|
|
for(int i=0; i<c->type; i++)
|
|
|
|
if(c->mov[i]->monst == moKrakenT) {
|
|
|
|
drawParticles(c, minf[moKrakenT].color, 16);
|
|
|
|
c->mov[i]->monst = moNone;
|
|
|
|
if(checkOrb(who, itOrbStone)) {
|
|
|
|
if(isWatery(c->mov[i]))
|
|
|
|
c->mov[i]->wall = waNone;
|
|
|
|
else
|
|
|
|
c->mov[i]->wall = waPetrified, c->mov[i]->wparam = moKrakenT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalhp(cell *c) {
|
|
|
|
int total = 0;
|
|
|
|
for(int i=0; i<c->type; i++)
|
|
|
|
if(c->mov[i]->monst == moKrakenT)
|
|
|
|
total += c->mov[i]->hitpoints;
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
void trymove(cell *c);
|
|
|
|
|
|
|
|
void sleep(cell *c) {
|
|
|
|
if(c->monst == moKrakenT) c = c->mov[c->mondir];
|
|
|
|
c->stuntime = 1;
|
|
|
|
forCellEx(c2, c) c2->stuntime = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void attacks() {
|
|
|
|
bool offboat[MAXPLAYER];
|
|
|
|
for(int i=0; i<MAXPLAYER; i++) offboat[i] = false;
|
|
|
|
for(int i=0; i<size(dcal); i++) {
|
|
|
|
cell *c = dcal[i];
|
|
|
|
if(c->monst == moKrakenT && !c->stuntime) forCellEx(c2, c) {
|
|
|
|
bool dboat = false;
|
|
|
|
if(c2->monst && canAttack(c, moKrakenT, c2, c2->monst, AF_ONLY_FBUG)) {
|
2018-01-03 20:49:14 +00:00
|
|
|
attackMonster(c2, AF_NORMAL | AF_MSG, c->monst);
|
2017-03-23 10:53:57 +00:00
|
|
|
sleep(c);
|
|
|
|
}
|
|
|
|
else for(int i=0; i<numplayers(); i++) if(playerpos(i) == c2) {
|
|
|
|
if(isPlayerInBoatOn(c2, i)) {
|
|
|
|
addMessage(XLAT("%The1 destroys your boat!", moKrakenH));
|
|
|
|
dboat = true;
|
|
|
|
offboat[i] = true;
|
|
|
|
}
|
|
|
|
else if(offboat[i]) ;
|
|
|
|
else killThePlayer(moKrakenH, i, 0);
|
|
|
|
sleep(c);
|
|
|
|
}
|
|
|
|
if(dboat) destroyBoats(c2, c, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(int i=0; i<size(dcal); i++) {
|
|
|
|
cell *c = dcal[i];
|
|
|
|
if(c->monst == moKrakenH && !c->stuntime && !isWateryOrBoat(c)) {
|
|
|
|
int qdir = 0;
|
2017-10-27 18:07:58 +00:00
|
|
|
cell *ctab[MAX_EDGE];
|
2017-03-23 10:53:57 +00:00
|
|
|
forCellEx(c2, c) if(isWatery(c2)) ctab[qdir++] = c2;
|
2018-01-13 18:23:02 +00:00
|
|
|
hrandom_shuffle(ctab, qdir);
|
2017-03-23 10:53:57 +00:00
|
|
|
while(qdir--) trymove(ctab[qdir]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// c is the tentacle which will be the head after the move
|
|
|
|
void trymove(cell *c) {
|
2018-05-07 23:59:29 +00:00
|
|
|
if(kraken_pseudohept(c)) return;
|
2017-03-23 10:53:57 +00:00
|
|
|
cell *c2 = c->mov[c->mondir];
|
|
|
|
if(!isWatery(c)) return;
|
|
|
|
if(againstCurrent(c, c2)) return;
|
|
|
|
forCellIdEx(c3, i, c) {
|
|
|
|
if(c3->monst && c3 != c2 && !(c3->mondir >= 0 && c3->mondir < c3->type &&
|
|
|
|
c3->mov[c3->mondir] == c2))
|
|
|
|
return;
|
|
|
|
if(isPlayerOn(c3)) return;
|
|
|
|
if(sword::at(c3)) return;
|
|
|
|
if(!passable(c3, c, P_FISH | P_MONSTER)) return;
|
|
|
|
}
|
|
|
|
if(c2->stuntime) return;
|
|
|
|
int hpcount[10];
|
|
|
|
forCellIdEx(c3, i, c2) {
|
|
|
|
hpcount[i] = c3->hitpoints;
|
|
|
|
c3->monst = moNone;
|
|
|
|
}
|
|
|
|
c->monst = moKrakenH;
|
|
|
|
vector<pair<cell*, cell*> > acells;
|
|
|
|
acells.push_back(make_pair(c2, c));
|
|
|
|
forCellIdEx(c3, i, c) {
|
|
|
|
c3->monst = moKrakenT, c3->mondir = c->spn(i),
|
|
|
|
c3->aitmp = sval;
|
|
|
|
int i0 = (i+c->spn(c->mondir)-c->mondir+99) % c2->type;
|
|
|
|
c3->hitpoints = hpcount[i0];
|
|
|
|
acells.push_back(make_pair(c2->mov[i0], c3));
|
|
|
|
if(c3->wall == waBoat) {
|
|
|
|
addMessage(XLAT("%The1 destroys %the2!", moKrakenH, waBoat));
|
|
|
|
c3->wall = waSea;
|
|
|
|
}
|
|
|
|
if(c3->wall == waStrandedBoat) {
|
|
|
|
addMessage(XLAT("%The1 destroys %the2!", moKrakenH, waBoat));
|
|
|
|
c3->wall = waNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(size(acells)) {
|
|
|
|
// bool found = false;
|
|
|
|
for(int i=0; i<size(acells); i++) {
|
|
|
|
/* bool noconflict = true;
|
|
|
|
for(int j=0; j<size(acells); j++)
|
|
|
|
if(acells[i].second == acells[j].first)
|
|
|
|
noconflict = false; */
|
|
|
|
/* if(noconflict) */ {
|
|
|
|
// found = true;
|
|
|
|
indAnimateMovement(acells[i].first, acells[i].second, LAYER_BIG);
|
|
|
|
acells[i] = acells[size(acells)-1];
|
|
|
|
acells.resize(size(acells)-1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
commitAnimations(LAYER_BIG);
|
|
|
|
sleep(c);
|
|
|
|
c->aitmp = sval;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool barrierhept(cell *c) {
|
|
|
|
return c->bardir != NOBARRIERS && c->bardir != NODIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace prairie {
|
|
|
|
|
|
|
|
using namespace fieldpattern;
|
|
|
|
|
|
|
|
int getfval(cell *c3) {
|
|
|
|
if(barrierhept(c3)) return btspin(fieldval(c3).first, c3->bardir)+1;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-24 15:24:08 +00:00
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
void spread(cell *c, cell *from) {
|
|
|
|
int rd;
|
|
|
|
|
|
|
|
c->LHU.fi.flowerdist = 8;
|
|
|
|
c->LHU.fi.walldist = 8;
|
|
|
|
c->LHU.fi.walldist2 = 8;
|
|
|
|
|
2017-06-09 01:41:33 +00:00
|
|
|
if(torus) {
|
|
|
|
c->LHU.fi.rval = 0;
|
|
|
|
}
|
|
|
|
else if(euclid) {
|
2017-12-28 15:46:10 +00:00
|
|
|
int x, y;
|
|
|
|
tie(x,y) = cell_to_pair(c);
|
2017-03-23 10:53:57 +00:00
|
|
|
c->LHU.fi.rval = (y&15);
|
|
|
|
}
|
|
|
|
else if(sphere) {
|
2018-01-06 21:34:03 +00:00
|
|
|
c->LHU.fi.rval = celldistance(c, cwt.c) + 8 - (nonbitrunc ? 2 : 3);
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
2017-10-30 18:12:33 +00:00
|
|
|
else if(weirdhyperbolic) {
|
|
|
|
c->LHU.fi.rval = max(celldist(c), 15);
|
|
|
|
}
|
2017-03-23 10:53:57 +00:00
|
|
|
else {
|
2017-11-03 21:19:45 +00:00
|
|
|
if(quotient == 2 || !from) {
|
|
|
|
c->fval = currfp.distflower0;
|
2017-03-23 10:53:57 +00:00
|
|
|
}
|
|
|
|
else if(from && from->land == laPrairie && from->fval)
|
|
|
|
c->fval = from->fval;
|
|
|
|
else {
|
|
|
|
forCellEx(c2, c) if(c2->land == laPrairie && c2->fval)
|
|
|
|
c->fval = c2->fval;
|
|
|
|
if(!c->fval) forCellEx(c2, c) if(!c->fval) c->fval = getfval(c2);
|
|
|
|
if(!c->fval) forCellEx(c2, c) forCellEx(c3, c2) if(!c->fval) c->fval = getfval(c3);
|
|
|
|
if(!c->fval) {
|
|
|
|
|
|
|
|
int barclose = 0;
|
|
|
|
|
|
|
|
forCellEx(c2, c) if(barrierhept(c2)) barclose++;
|
|
|
|
|
|
|
|
forCellEx(c2, c) forCellEx(c3, c2)
|
|
|
|
if(barrierhept(c3)) barclose++;
|
|
|
|
|
|
|
|
printf("c = %p bc = %d\n", c, barclose);
|
|
|
|
|
|
|
|
raiseBuggyGeneration(c, "could not set river fval");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pair<int,bool> fv = fieldpattern::fieldval(c);
|
2017-11-06 22:29:10 +00:00
|
|
|
fv = currfp.gmul(fv, currfp.inverses[c->fval-1]);
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2017-11-06 22:29:10 +00:00
|
|
|
rd = currfp.getdist(fv, currfp.distriver);
|
|
|
|
int rl = currfp.getdist(fv, currfp.distriverleft);
|
|
|
|
int rr = currfp.getdist(fv, currfp.distriverright);
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2017-11-06 22:29:10 +00:00
|
|
|
c->LHU.fi.flowerdist = currfp.getdist(fv, currfp.distflower);
|
|
|
|
c->LHU.fi.walldist = currfp.getdist(fv, currfp.distwall);
|
|
|
|
c->LHU.fi.walldist2 = currfp.getdist(fv, currfp.distwall2);
|
2017-03-23 10:53:57 +00:00
|
|
|
|
|
|
|
c->LHU.fi.rval = 0;
|
|
|
|
if(rd <= 7 && rl < rr)
|
|
|
|
c->LHU.fi.rval = 8 + rd;
|
|
|
|
if(rd <= 7 && rl > rr)
|
|
|
|
c->LHU.fi.rval = 7 - rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c->LHU.fi.flowerdist == 0 && c->type != 6) c->item = itOrbSafety;
|
|
|
|
|
|
|
|
if(c->LHU.fi.walldist == 0) c->wall = waBarrier;
|
|
|
|
|
|
|
|
if(0) if(c->type == 7) for(int i=0; i<7; i++) {
|
2017-10-29 09:52:02 +00:00
|
|
|
eItem m = currfp.markers[fieldpattern::btspin(c->master->fieldval,i)];
|
2017-03-23 10:53:57 +00:00
|
|
|
if(m) {
|
|
|
|
if(c->item) c->item = itBuggy2;
|
|
|
|
else c->item = m, c->mondir = i;
|
|
|
|
if(c->wall == waSea) c->wall = waBoat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-06 21:34:03 +00:00
|
|
|
#define RLOW (sphere?(nonbitrunc?7:6):nonbitrunc?4:2)
|
|
|
|
#define RHIGH (sphere?(nonbitrunc?8:9):nonbitrunc?11:13)
|
2017-03-23 10:53:57 +00:00
|
|
|
|
2018-03-24 15:24:08 +00:00
|
|
|
bool no_worms(cell *c) {
|
|
|
|
int rv = c->LHU.fi.rval;
|
|
|
|
return rv > RLOW+1 && rv < RHIGH-1;
|
|
|
|
}
|
|
|
|
|
2017-03-23 10:53:57 +00:00
|
|
|
bool isriver(cell *c) {
|
|
|
|
return c->land == laPrairie && c->LHU.fi.rval <= RHIGH && c->LHU.fi.rval >= RLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mainriver(cell *c) {
|
|
|
|
return c->LHU.fi.rval <= 8 && c->LHU.fi.rval >= 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nearriver(cell *c) {
|
|
|
|
return c->LHU.fi.rval == RHIGH+1 || c->LHU.fi.rval == RLOW-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *enter;
|
|
|
|
|
|
|
|
bool opposite(cell *c) {
|
|
|
|
return (c->LHU.fi.rval ^ enter->LHU.fi.rval) & 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isleft(cell *c) {
|
|
|
|
return c->LHU.fi.rval & 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
int towerleft(cell *c) {
|
|
|
|
return c->LHU.fi.rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int towerright(cell *c) {
|
|
|
|
return 15^c->LHU.fi.rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *next(cell *c, int pv=1) {
|
|
|
|
for(int i=0; i<c->type; i++) {
|
|
|
|
cell *c1 = createMov(c, i);
|
|
|
|
cell *c2 = createMov(c, (i+pv+c->type)%c->type);
|
|
|
|
if(c1 && c1->LHU.fi.rval == c->LHU.fi.rval)
|
|
|
|
if(c2 && c2->LHU.fi.rval == c->LHU.fi.rval+1)
|
|
|
|
if(isNeighbor(c1,c2))
|
|
|
|
return c1;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cell *prev(cell *c) { return next(c, -1); }
|
|
|
|
|
|
|
|
int beastdist(cell *c, int dir) {
|
|
|
|
cell *cx = c; int n=0;
|
|
|
|
while(true) {
|
|
|
|
if(cx->monst == moHerdBull) return n;
|
|
|
|
cx = next(cx, dir);
|
|
|
|
n++;
|
|
|
|
if(!cx || n >= 1000) return 1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<cell*> beaststogen;
|
|
|
|
|
|
|
|
void generateBeast(cell *c) {
|
|
|
|
int beastdistance = min(beastdist(c, 1), beastdist(c, -1));
|
|
|
|
if(hrand(1000) >= 15 * beastdistance + 2 * items[itGreenGrass]) return;
|
|
|
|
c->monst = moHerdBull;
|
|
|
|
cell *c2 = prev(c);
|
|
|
|
if(c2) c->mondir = neighborId(c, c2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveAt(cell *c) {
|
|
|
|
if(eq(c->aitmp, sval)) return;
|
|
|
|
vector<cell*> whirlline;
|
|
|
|
whirlline.push_back(c);
|
|
|
|
c->aitmp = sval;
|
|
|
|
cell *c2 = prev(c);
|
|
|
|
while(c2 && !eq(c2->aitmp, sval)) {
|
|
|
|
whirlline.push_back(c2), c2->aitmp = sval;
|
|
|
|
c2 = prev(c2);
|
|
|
|
// in sphere/quotient geometries, never break before a bull
|
|
|
|
if((sphere || quotient) && !c2->monst) break;
|
|
|
|
}
|
|
|
|
reverse(whirlline.begin(), whirlline.end());
|
|
|
|
c2 = next(c);
|
|
|
|
while(c2 && !eq(c2->aitmp, sval)) whirlline.push_back(c2), c2->aitmp = sval, c2 = next(c2);
|
|
|
|
int qty = size(whirlline);
|
|
|
|
// for(int i=0; i<qty; i++) whirlline[i]->aitmp = sval;
|
|
|
|
if(shmup::on) {
|
2018-04-03 21:34:47 +00:00
|
|
|
for(int i=0; i<qty; i++) if(whirlline[i]->cpdist <= gamerange()) {
|
2017-03-23 10:53:57 +00:00
|
|
|
generateBeast(whirlline[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
c2 = whirlline[qty-1];
|
|
|
|
if(c2->monst == moHerdBull) c2->monst = moNone;
|
|
|
|
if(!shmup::on) for(int q=qty-2; q>=0; q--) {
|
|
|
|
cell *cp = whirlline[q];
|
|
|
|
cell *cn = whirlline[q+1];
|
|
|
|
if(cp->monst == moHerdBull && !cp->stuntime) {
|
|
|
|
forCellEx(c2, cp) {
|
2018-01-03 20:49:14 +00:00
|
|
|
int flags = AF_GETPLAYER | AF_BULL;
|
2017-03-23 10:53:57 +00:00
|
|
|
if(c2 != cn) flags |= AF_ONLY_FBUG;
|
|
|
|
if(canAttack(c, moHerdBull, c2, c2->monst, flags))
|
|
|
|
attackMonster(c2, flags | AF_MSG, moHerdBull);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cn->monst && !isPlayerOn(cn) && passable_for(cp->monst, cn, cp, P_DEADLY))
|
|
|
|
moveMonster(cn, cp);
|
|
|
|
else {
|
|
|
|
playSound(NULL, "hit-axe"+pick123());
|
|
|
|
beastcrash(cn, cp);
|
|
|
|
cp->monst = moRagingBull;
|
|
|
|
cp->stuntime = 3;
|
|
|
|
cp->mondir = NODIR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!sphere && !quotient) generateBeast(whirlline[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void move() {
|
|
|
|
sval++;
|
|
|
|
for(int i=0; i<size(dcal); i++) {
|
|
|
|
cell *c = dcal[i];
|
|
|
|
if(isriver(c)) moveAt(c);
|
|
|
|
}
|
|
|
|
for(int i=0; i<size(beaststogen); i++)
|
|
|
|
generateBeast(beaststogen[i]);
|
|
|
|
beaststogen.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<cell*> tchoices;
|
|
|
|
|
|
|
|
cell *lasttreasure;
|
|
|
|
|
|
|
|
// vector<cell*> orbs;
|
|
|
|
|
|
|
|
bool thisriver(cell *c) {
|
|
|
|
forCellEx(c2, c) if(c2->mpdist < c->mpdist && !isriver(c2)) return false;
|
|
|
|
forCellEx(c2, c) if(c2->mpdist < c->mpdist) return thisriver(c2);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void generateTreasure(cell *c) {
|
|
|
|
// if(nearriver(c) && op
|
|
|
|
if(enter && nearriver(c) && opposite(c) && thisriver(c)) {
|
|
|
|
int hr = hrand(100);
|
|
|
|
if(hr == 0 && items[itGreenGrass] >= 10) {
|
|
|
|
c->item = itOrbBull;
|
|
|
|
// orbs.push_back(c);
|
|
|
|
}
|
|
|
|
else if(hr < 1+PRIZEMUL) {
|
|
|
|
placePrizeOrb(c);
|
|
|
|
// if(c->item) orbs.push_back(c);
|
|
|
|
}
|
|
|
|
else tchoices.push_back(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void treasures() {
|
|
|
|
if(enter && !isriver(cwt.c)) enter = NULL;
|
|
|
|
else if(!enter && isriver(cwt.c)) enter = cwt.c;
|
|
|
|
if(size(tchoices)) {
|
|
|
|
if(lasttreasure && lasttreasure->item == itGreenGrass) {
|
2018-01-06 21:34:03 +00:00
|
|
|
if(celldistance(lasttreasure, cwt.c) >= (nonbitrunc ? 7 : 10)) {
|
2017-03-23 10:53:57 +00:00
|
|
|
lasttreasure->item = itNone;
|
|
|
|
forCellEx(c2, lasttreasure) if(c2->item == itGreenGrass) c2->item = itNone;
|
|
|
|
}
|
|
|
|
else { tchoices.clear(); return; }
|
|
|
|
}
|
|
|
|
if(size(tchoices) < 3) { tchoices.clear(); return; }
|
|
|
|
lasttreasure = tchoices[hrand(size(tchoices))];
|
|
|
|
lasttreasure->item = itGreenGrass;
|
|
|
|
for(int i=0; i<size(tchoices); i++) if(isNeighbor(tchoices[i], lasttreasure))
|
|
|
|
tchoices[i]->item = itGreenGrass;
|
|
|
|
tchoices.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ca {
|
|
|
|
ld prob = .2;
|
|
|
|
string carule[8][2];
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
// hexagonal variant of Game of Life, as suggested by Wikipedia
|
|
|
|
for(int i=0; i<8; i++)
|
|
|
|
carule[i][0] = "00100000",
|
|
|
|
carule[i][1] = "00011000";
|
|
|
|
}
|
|
|
|
|
2017-07-22 23:33:27 +00:00
|
|
|
#if CAP_COMMANDLINE
|
2017-03-23 10:53:57 +00:00
|
|
|
bool readArg() {
|
|
|
|
using namespace arg;
|
|
|
|
if(argis("-caprob")) {
|
|
|
|
shift(); prob = argf();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(args()[0] != '-') return false;
|
|
|
|
if(args()[1] != 'c') return false;
|
|
|
|
int livedead = args()[2] - '0';
|
|
|
|
if(livedead < 0 || livedead > 1) return false;
|
|
|
|
int nei = -1;
|
|
|
|
if(args()[3]) {
|
|
|
|
nei = args()[3] - '0';
|
|
|
|
if(nei < 0 || nei > 7) return false;
|
|
|
|
if(args()[4]) return false;
|
|
|
|
}
|
|
|
|
shift();
|
|
|
|
string s = args(); s += "00000000";
|
|
|
|
if(nei == -1) for(int i=0; i<8; i++)
|
|
|
|
carule[i][livedead] = s;
|
|
|
|
else
|
|
|
|
carule[nei][livedead] = s;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void simulate() {
|
|
|
|
if(cwt.c->land != laCA) return;
|
2017-04-04 09:13:15 +00:00
|
|
|
vector<cell*>& allcells = currentmap->allcells();
|
2017-03-23 10:53:57 +00:00
|
|
|
int dcs = size(allcells);
|
|
|
|
bool willlive[dcs];
|
|
|
|
for(int i=0; i<dcs; i++) {
|
|
|
|
cell *c = allcells[i];
|
|
|
|
if(c->land != laCA) return;
|
|
|
|
int nei = 0, live = 0;
|
|
|
|
forCellEx(c2, c) if(c2->land == laCA) {
|
|
|
|
nei++; if(c2->wall == waFloorA) live++;
|
|
|
|
}
|
|
|
|
int welive = 0; if(c->wall == waFloorA) welive++;
|
|
|
|
willlive[i] = carule[nei][welive][live] == '1';
|
|
|
|
}
|
|
|
|
for(int i=0; i<dcs; i++) {
|
|
|
|
cell *c = allcells[i];
|
|
|
|
c->wall = willlive[i] ? waFloorA : waNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
auto ccm = addHook(clearmemory, 0, [] () {
|
2017-09-02 22:33:35 +00:00
|
|
|
heat::offscreen_heat.clear();
|
|
|
|
heat::offscreen_fire.clear();
|
2017-07-10 18:47:38 +00:00
|
|
|
princess::clear();
|
2017-07-22 23:33:27 +00:00
|
|
|
mirror::mirrors.clear();
|
2017-07-10 18:47:38 +00:00
|
|
|
clearing::bpdata.clear();
|
|
|
|
tortoise::emap.clear();
|
|
|
|
tortoise::babymap.clear();
|
|
|
|
prairie::lasttreasure = NULL;
|
|
|
|
prairie::enter = NULL;
|
|
|
|
prairie::tchoices.clear();
|
|
|
|
prairie::beaststogen.clear();
|
2017-08-06 12:50:16 +00:00
|
|
|
mirror::clearcache();
|
2018-01-26 00:45:49 +00:00
|
|
|
}) +
|
|
|
|
addHook(hooks_removecells, 0, [] () {
|
|
|
|
eliminate_if(heat::offscreen_heat, is_cell_removed);
|
|
|
|
eliminate_if(heat::offscreen_fire, is_cell_removed);
|
|
|
|
eliminate_if(princess::infos, [] (princess::info*& i) {
|
|
|
|
if(is_cell_removed(i->princess) || is_cell_removed(i->prison)) {
|
|
|
|
DEBSM(printf("removing a princess\n");)
|
|
|
|
if(i->princess && !is_cell_removed(i->princess)) {
|
|
|
|
DEBSM(printf("faking a princess\n");)
|
|
|
|
princess::newFakeInfo(i->princess);
|
|
|
|
}
|
|
|
|
delete i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
set_if_removed(prairie::lasttreasure, NULL);
|
|
|
|
set_if_removed(prairie::enter, NULL);
|
|
|
|
eliminate_if(prairie::tchoices, is_cell_removed);
|
|
|
|
eliminate_if(prairie::beaststogen, is_cell_removed);
|
|
|
|
for(auto& bpd: clearing::bpdata) set_if_removed(bpd.second.root, NULL);
|
|
|
|
});
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2017-10-11 22:20:18 +00:00
|
|
|
// windcode arrays precomputed for speed
|
|
|
|
|
|
|
|
int windcodes18920[] = {164,182,171,158,148,155,163,174,188,205,193,160,167,160,140,128,146,153,159,161,167,180,186,202,190,229,234,24,120,146,165,177,179,169,146,125,113,93,131,157,147,155,158,161,162,157,157,162,173,187,198,176,163,242,204,234,238,249,1,30,77,120,153,165,140,173,173,204,200,165,150,184,130,119,104,86,71,54,70,208,168,141,133,169,158,167,161,161,166,171,142,144,165,153,159,166,175,203,186,216,191,221,168,149,114,70,26,225,241,220,229,244,10,251,7,19,50,85,110,129,148,145,173,180,143,178,174,166,144,54,248,215,170,166,153,134,182,116,118,122,114,96,77,57,69,78,62,18,47,228,189,164,148,126,110,81,217,169,151,156,250,163,168,156,154,170,183,192,149,118,120,138,182,152,158,156,158,164,169,171,202,217,181,243,235,206,182,241,159,149,169,125,97,77,53,28,40,252,234,237,218,4,192,204,220,244,246,24,248,250,1,12,31,4,56,98,120,127,134,129,161,139,156,105,153,209,205,187,148,177,180,177,167,152,174,117,81,44,4,201,232,161,168,162,174,165,153,139,115,160,94,103,120,127,125,129,118,94,66,50,28,40,78,89,50,97,81,76,54,16,10,230,195,174,157,151,162,139,122,98,81,27,58,2,7,245,89,127,132,146,158,249,162,174,191,64,124,230,150,173,193,209,211,224,146,119,174,87,90,93,118,139,203,159,167,164,149,150,157,155,165,172,169,161,159,214,219,195,221,172,11,9,253,253,225,206,187,170,252,166,155,149,141,168,124,101,83,81,68,55,48,38,29,45,26,19,206,254,232,219,199,24,159,174,171,187,208,249,17,219,241,43,29,250,248,241,244,248,1,3,17,30,1,37,63,128,134,147,141,135,124,134,125,173,186,161,114,161,52,50,79,236,241,243,236,163,169,157,150,168,181,186,184,184,171,172,170,149,178,131,108,91,73,64,41,10,216,202,233,154,152,161,177,144,182,176,186,166,152,145,133,106,85,119,112,67,76,85,112,135,129,124,134,132,142,139,125,89,71,42,32,26,45,227,32,71,91,97,112,26,106,89,127,83,88,88,65,30,255,243,220,229,201,174,171,164,154,161,153,146,157,142,139,137,93,78,75,67,36,3,57,255,26,30,48,241,93,105,73,116,121,132,147,161,169,233,232,157,151,180,201,219,6,32,94,129,232,142,159,177,190,207,220,241,237,226,252,170,144,119,95,193,56,60,72,62,70,96,124,136,149,212,223,170,177,183,178,171,149,144,141,144,154,150,157,168,175,184,178,167,139,143,146,208,228,229,232,196,209,231,180,148,6,26,41,37,251,242,232,26,217,212,191,169,160,155,241,251,177,161,174,147,145,144,150,147,167,130,100,75,83,79,65,79,75,40,45,48,49,45,35,46,18,49,73,52,117,48,170,255,239,19,220,221,219,208,184,56,138,133,145,160,155,167,179,185,226,14,46,119,196,237,243,41,83,19,8,1,251,243,232,231,234,249,235,248,245,5,247,7,18,21,21,9,21,29,33,187,158,223,154,168,167,153,128,142,114,116,118,133,115,184,194,170,216,208,209,109,92,162,45,19,13,255,65,241,247,253,255,14,26,82,139,164,157,159,162,167,167,183,144,193,192,188,192,189,197,167,169,173,173,184,191,172,151,179,138,123,108,87,81,98,75,78,70,51,248,29,198,230,213,39,222,157,156,146,140,140,151,176,195,123,187,185,185,182,198,175,159,145,144,146,150,141,96,68,57,83,91,67,50,54,51,54,63,99,129,157,153,124,114,140,89,153,144,133,140,160,158,162,146,58,72,59,60,18,3,6,16,6,75,123,45,170,22,102,98,50,102,98,100,110,149,245,132,108,84,80,166,82,87,90,102,120,108,92,254,11,248,219,228,197,226,205,236,171,147,159,161,163,163,141,154,145,185,165,146,146,144,153,142,143,150,224,57,174,69,68,66,63,69,68,42,15,49,226,64,245,27,231,49,47,43,37,50,232,90,102,100,103,71,106,117,113,117,126,136,148,165,177,199,217,228,206,63,107,246,124,217,215,225,225,230,2,15,238,13,1,171,134,132,221,135,147,165,185,191,179,202,212,227,244,18,9,248,240,1,242,24,178,161,192,143,125,108,96,79,209,53,37,29,34,64,38,51,53,68,86,116,140,130,136,154,221,220,233,189,190,173,194,193,191,191,164,189,149,144,145,141,140,129,128,143,139,154,145,159,173,173,174,186,203,193,183,158,177,120,121,126,116,129,207,201,214,20,239,229,239,251,207,225,198,248,165,195,113,1,14,253,31,51,79,73,78,242,201,238,243,210,114,212,220,226,209,189,167,147,145,156,142,221,227,214,194,199,171,152,173,137,138,142,134,134,154,165,166,152,173,166,141,118,88,64,35,101,91,76,72,15,78,103,163,251,11,33,45,56,42,52,42,49,57,23,58,2,244,87,20,93,76,72,73,133,137,101,149,178,255,4,246,224,40,203,
|
|
|
|
int windcodes5676[] = {152,138,172,172,141,158,157,124,119,130,125,143,190,206,205,187,171,175,136,86,111,80,0,210,177,155,125,96,80,66,162,135,121,119,150,136,86,91,93,193,201,212,203,213,227,230,243,228,210,186,138,68,242,217,216,172,145,199,31,43,57,82,110,119,95,49,31,4,13,17,254,198,173,161,182,204,108,133,122,87,88,103,64,47,44,29,26,255,235,192,133,122,156,154,84,67,68,129,169,191,181,182,140,91,49,51,62,52,76,79,52,19,241,207,175,208,225,235,225,202,207,193,192,235,236,236,224,242,250,237,252,23,13,250,231,230,217,194,193,209,173,105,76,52,39,11,246,236,233,245,240,1,246,206,177,151,91,98,170,212,207,238,5,22,29,34,43,44,45,57,74,80,85,142,153,157,129,126,110,52,13,27,44,41,2,241,248,5,11,18,34,58,59,37,16,216,191,168,172,169,165,167,137,127,231,222,228,251,24,47,81,113,147,163,142,122,82,38,59,80,81,109,154,156,55,33,36,19,42,43,30,16,12,15,24,33,20,13,2,3,6,5,252,231,191,139,91,90,82,103,158,195,205,223,229,57,90,55,42,16,20,30,37,72,128,161,184,207,200,213,220,204,198,206,212,213,185,153,132,103,75,49,23,21,23,24,50,63,53,40,25,25,45,77,92,96,75,69,54,25,23,23,21,2,243,236,220,180,133,134,162,212,241,238,247,236,246,252,250,249,234,196,169,203,221,220,206,162,168,161,106,11,247,241,246,253,242,213,17,235,193,193,240,1,13,22,0,241,228,215,238,10,29,53,31,53,47,12,9,254,234,232,235,249,234,235,228,218,205,167,182,199,208,174,255,247,237,151,184,16,74,73,59,38,23,46,76,10,31,24,252,232,240,253,252,5,222,199,228,9,13,253,241,242,3,42,27,1,12,21,242,213,177,159,186,191,167,112,58,28,47,46,67,119,196,222,238,231,219,195,195,191,16,249,250,3,12,15,18,22,34,31,24,26,41,44,39,45,44,36,23,45,54,44,43,50,88,115,38,53,38,64,105,158,192,191,194,161,189,186,161,152,91,158,144,155,162,111,71,28,1,230,234,7,28,21,28,46,88,76,42,1,224,238,227,233,224,235,251,8,4,2,4,9,26,22,1,20,54,58,57,83,97,120,83,38,31,32,36,109,195,200,202,208,216,130,148,166,191,168,169,180,169,158,161,168,182,197,158,125,131,93,52,34,17,17,250,231,231,243,230,218,235,47,30,16,25,30,21,41,55,96,104,102,113,133,180,196,216,185,142,113,145,150,108,105,63,34,253,250,13,46,63,73,111,85,74,54,77,103,159,197,219,133,191,216,243,16,26,14,15,21,28,38,205,244,32,48,58,44,44,52,40,22,247,254,5,251,8,19,16,255,4,25,35,43,51,34,1,12,20,15,9,255,247,1,17,16,25,4,10,18,14,12,45,17,245,239,228,220,174,150,124,94,87,41,51,68,80,52,45,80,89,104,87,249,196,205,223,224,237,246,240,228,218,211,3,32,62,154,137,79,47,22,24,24,25,6,237,229,234,7,19,32,30,26,12,19,36,85,117,158,175,180,173,157,244,221,220,234,222,204,196,209,233,239,242,232,220,223,196,183,208,206,231,234,224,203,221,237,233,221,209,179,160,138,137,142,132,118,91,76,78,71,56,31,19,9,2,11,14,17,11,3,0,249,19,35,37,80,79,65,53,51,39,26,22,19,12,5,13,16,19,22,45,66,113,102,103,113,135,104,73,60,63,82,65,74,90,50,21,19,1,3,18,24,17,19,35,38,48,249,240,252,244,224,246,253,244,247,223,206,179,138,92,118,139,89,120,126,162,214,243,252,3,3,2,253,236,210,45,25,194,226,255,3,2,254,1,8,5,5,5,14,245,240,248,234,148,161,120,121,180,224,219,230,236,233,225,229,217,233,211,103,110,143,171,157,184,146,102,86,46,16,6,236,250,241,230,238,250,255,253,6,13,5,252,244,229,161,106,53,29,15,246,204,175,173,144,146,247,250,9,2,243,24,30,31,40,52,21,4,246,242,237,237,238,237,191,158,202,239,232,3,14,19,28,38,52,98,152,244,249,43,63,94,100,93,39,21,6,253,2,23,36,50,207,225,213,233,245,226,221,233,14,3,236,198,228,1,251,228,226,220,205,222,228,226,188,129,89,185,167,171,213,211,218,245,36,137,131,85,48,11,241,250,11,14,34,63,87,133,177,193,217,235,8,54,101,90,76,62,57,67,59,41,13,1,6,23,29,41,80,134,168,223,11,31,31,41,38,27,23,16,236,201,194,222,233,237,0,10,4,249,251,14,40,31,7,236,167,136,172,171,15,28,40,44,36,14,5,14,253,234,234,242,244,239,230,0,34,74,88,69,69,16,245,253,248,222,55,61,91,4,5,252,239,217,213,200,150,131,139,145,160,185,209,220,228,210,202,170,131,108,11,246,242,14,27,26,25,28,34,45,60,64,90,151,246,229,236,255,247,253,2,243,235,229,244,10,177,173,195,198,185,202,187,135,103,81,31,246,232,245,241,250,246,251,10,17,16,6,15,21,10,10,19,18,23,29,59,46,31,19,14,20,24,22,10,24,62,57,58,45,28,27,42,58,48,43,53,38,47,38,10,
|
|
|
|
|
2017-09-03 19:12:44 +00:00
|
|
|
namespace windmap {
|
|
|
|
map<int, int> getid;
|
|
|
|
vector<vector<int> > neighbors;
|
|
|
|
vector<cell*> samples;
|
|
|
|
|
|
|
|
int getId(cell *c) {
|
|
|
|
auto i = fieldpattern::fieldval_uniq(c);
|
|
|
|
auto &id = getid[i];
|
|
|
|
if(id == 0) { samples.push_back(c); id = size(samples); }
|
|
|
|
return id-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<unsigned char> windcodes;
|
|
|
|
|
|
|
|
void create() {
|
|
|
|
samples.clear();
|
|
|
|
neighbors.clear();
|
|
|
|
getid.clear();
|
|
|
|
getId(currentmap->gamestart());
|
|
|
|
for(int k=0; k<size(samples); k++) {
|
|
|
|
cell *c = samples[k];
|
|
|
|
neighbors.emplace_back();
|
|
|
|
auto &v = neighbors.back();
|
2018-04-09 15:40:12 +00:00
|
|
|
if(gp::on)
|
2018-04-03 21:39:18 +00:00
|
|
|
for(int l=0; l<S7; l++) v.push_back(getId(createStep(c->master, l)->c7));
|
|
|
|
else
|
|
|
|
for(int l=0; l<c->type; l++) v.push_back(getId(createMov(c, l)));
|
2017-09-03 19:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int N = size(samples);
|
2017-10-11 22:20:18 +00:00
|
|
|
|
|
|
|
int* precomp = NULL;
|
2017-09-03 19:12:44 +00:00
|
|
|
|
2017-10-11 22:20:18 +00:00
|
|
|
windcodes.resize(N);
|
|
|
|
|
|
|
|
if(N == 18920) precomp = windcodes18920;
|
|
|
|
if(N == 5676) precomp = windcodes5676;
|
|
|
|
|
2017-10-29 09:52:02 +00:00
|
|
|
if(precomp && size(currfp.matrices)) {
|
|
|
|
int randval = hrand(size(currfp.matrices));
|
2017-10-11 22:20:18 +00:00
|
|
|
for(int i=0; i<N; i++)
|
|
|
|
windcodes[i] = precomp[getid[fieldpattern::fieldval_uniq_rand(samples[i], randval)]-1];
|
2017-09-03 19:12:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-29 09:52:02 +00:00
|
|
|
|
|
|
|
int tries = 0;
|
2017-10-30 08:04:46 +00:00
|
|
|
int maxtries = specialland == laVolcano || specialland == laBlizzard || chaosmode ? 20 : 1;
|
2017-10-29 09:52:02 +00:00
|
|
|
tryagain:
|
2017-09-03 19:12:44 +00:00
|
|
|
|
|
|
|
for(int i=0; i<N; i++) windcodes[i] = hrand(256);
|
|
|
|
|
|
|
|
bool inqueue[N];
|
|
|
|
vector<int> tocheck;
|
|
|
|
for(int i=0; i<N; i++) tocheck.push_back(i), inqueue[i] = true;
|
2018-01-13 18:23:02 +00:00
|
|
|
hrandom_shuffle(&tocheck[0], size(tocheck));
|
2017-09-03 19:12:44 +00:00
|
|
|
|
|
|
|
for(int a=0; a<size(tocheck); a++) {
|
2017-10-29 09:52:02 +00:00
|
|
|
if(a >= 200*N) { printf("does not converge\n"); break; }
|
2017-09-03 19:12:44 +00:00
|
|
|
int bestval = 1000000000, best = 0;
|
|
|
|
int i = tocheck[a];
|
|
|
|
for(int k=0; k<256; k++) {
|
|
|
|
int j = windcodes[i] + k;
|
|
|
|
int cval = 0;
|
|
|
|
for(int c2: neighbors[i]) {
|
|
|
|
int d = (j - windcodes[c2]) & 255;
|
|
|
|
if(d > 128) d = 256 - d;
|
|
|
|
cval += d*d;
|
|
|
|
}
|
|
|
|
if(cval < bestval) bestval = cval, best = j;
|
|
|
|
}
|
|
|
|
if(windcodes[i] != best)
|
|
|
|
for(int c2: neighbors[i])
|
|
|
|
if(!inqueue[c2])
|
|
|
|
inqueue[c2] = true, tocheck.push_back(c2);
|
|
|
|
inqueue[i] = false;
|
|
|
|
windcodes[i] = best;
|
|
|
|
}
|
2017-10-29 09:52:02 +00:00
|
|
|
|
|
|
|
int ingroup[4];
|
|
|
|
for(int u=0; u<4; u++) ingroup[u] = 0;
|
|
|
|
for(int i=0; i<N; i++) ingroup[windcodes[i] >> 6]++;
|
|
|
|
for(int u=0; u<4; u++) if(!ingroup[u]) {
|
|
|
|
tries++;
|
2017-10-29 11:20:06 +00:00
|
|
|
if(tries < maxtries) goto tryagain;
|
2017-10-29 09:52:02 +00:00
|
|
|
}
|
2017-10-29 11:20:06 +00:00
|
|
|
if(tries >= maxtries && maxtries >= 20) {
|
2017-10-29 09:52:02 +00:00
|
|
|
addMessage("Failed to generate an interesting wind/lava pattern.");
|
|
|
|
}
|
2017-10-29 11:20:06 +00:00
|
|
|
else if(false) {
|
2017-10-11 22:20:18 +00:00
|
|
|
printf("tocheck size = %d\n", size(tocheck));
|
|
|
|
printf("if(N == %d) {\n", N);
|
|
|
|
printf(" windcodes = {");
|
|
|
|
for(int i=0; i<N; i++) printf("%d,", windcodes[i]);
|
|
|
|
printf("};\n");
|
|
|
|
printf(" return;\n");
|
|
|
|
printf(" }\n");
|
|
|
|
}
|
2017-09-03 19:12:44 +00:00
|
|
|
}
|
2017-09-30 09:46:41 +00:00
|
|
|
|
|
|
|
int at(cell *c) {
|
|
|
|
return windmap::windcodes[windmap::getId(c)];
|
|
|
|
}
|
|
|
|
|
2017-10-08 10:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Halloween namespace
|
2017-09-03 19:12:44 +00:00
|
|
|
|
2017-10-08 10:10:40 +00:00
|
|
|
namespace halloween {
|
|
|
|
cell *dragoncells[4];
|
|
|
|
vector<cell*> srch;
|
|
|
|
|
|
|
|
cell *farempty(bool lastresort = false) {
|
|
|
|
int maxdist = 0;
|
|
|
|
vector<cell*> validcells;
|
|
|
|
int firstfar1 = 0;
|
|
|
|
for(int i=1; i<size(dcal); i++) {
|
|
|
|
bool okay =
|
|
|
|
dcal[i]->item == itNone && dcal[i]->monst == moNone && dcal[i]->wall == waNone;
|
|
|
|
if(lastresort)
|
|
|
|
okay = dcal[i]->wall != waChasm && !isMultitile(dcal[i]->monst);
|
|
|
|
if(okay) {
|
|
|
|
if(dcal[i]->cpdist > maxdist)
|
|
|
|
firstfar1 = size(validcells),
|
|
|
|
maxdist = dcal[i]->cpdist;
|
|
|
|
validcells.push_back(dcal[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int qvc = size(validcells);
|
|
|
|
if(qvc == firstfar1) return farempty(true);
|
|
|
|
|
|
|
|
return validcells[firstfar1 + hrand(qvc - firstfar1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
int demoncount;
|
|
|
|
int swordpower;
|
|
|
|
int dragoncount;
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
demoncount = 0;
|
|
|
|
swordpower = 0;
|
|
|
|
dragoncount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
eMonster nextDemon() {
|
|
|
|
demoncount++;
|
|
|
|
if(demoncount % 9 == 0) return moGreater;
|
|
|
|
return moLesser;
|
|
|
|
}
|
|
|
|
|
|
|
|
void putMonster(eMonster m) {
|
|
|
|
cell *c = farempty();
|
|
|
|
c->hitpoints = 3;
|
|
|
|
c->monst = m;
|
|
|
|
playSeenSound(c);
|
|
|
|
if(!kills[m]) switch(m) {
|
|
|
|
case moGhost:
|
|
|
|
addMessage(XLAT("Ghosts can move through chasms!"));
|
|
|
|
break;
|
|
|
|
case moSkeleton:
|
|
|
|
addMessage(XLAT("Push Skeletons into the holes!"));
|
|
|
|
break;
|
|
|
|
case moDraugr:
|
|
|
|
addMessage(XLAT("You'll need your magical sword against the Draugar!"));
|
|
|
|
break;
|
|
|
|
case moLesser:
|
|
|
|
addMessage(XLAT("Demons are slow, but you'll need the experience against stronger ones..."));
|
|
|
|
break;
|
|
|
|
case moGreater:
|
|
|
|
addMessage(XLAT("You will need more experience to defeat the Greater Demon!"));
|
|
|
|
break;
|
|
|
|
case moPyroCultist:
|
|
|
|
addMessage(XLAT("Cultists throw fire at you from distance!"));
|
|
|
|
break;
|
|
|
|
case moFlailer:
|
|
|
|
addMessage(XLAT("Defeat Flail Guards by moving away from them."));
|
|
|
|
break;
|
|
|
|
case moVampire:
|
|
|
|
addMessage(XLAT("Vampire Bats drain your magical powers!"));
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
c->stuntime = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void getTreat(cell *where) {
|
|
|
|
if(!items[itTreat]) reset();
|
|
|
|
gainItem(itTreat);
|
|
|
|
farempty()->item = itTreat;
|
|
|
|
int itr = items[itTreat];
|
|
|
|
items[itOrbTime] += 30;
|
|
|
|
int monpower = 19 + itr + hrand(itr);
|
|
|
|
int mcount = 0;
|
|
|
|
while(monpower > 0) {
|
|
|
|
int id = hrand(10000);
|
|
|
|
|
|
|
|
#define CHANCE(x) (id -= x, id < 0)
|
|
|
|
if(CHANCE(400) && itr >= 5) {
|
|
|
|
putMonster(moGhost);
|
|
|
|
monpower -= 30;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(400)) {
|
|
|
|
putMonster(pick(moWitch, moZombie));
|
|
|
|
monpower -= 20;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(400) && itr >= 5) {
|
|
|
|
putMonster(nextDemon());
|
|
|
|
monpower -= 10;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(100) && itr >= 12) {
|
|
|
|
putMonster(moVampire);
|
|
|
|
monpower -= 10;
|
|
|
|
swordpower -= 5;
|
|
|
|
if(swordpower < 0) swordpower = 0;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(400) && swordpower > 0 && !mcount && itr >= 15) {
|
|
|
|
putMonster(moDraugr);
|
|
|
|
swordpower -= 3;
|
|
|
|
monpower -= 100;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(400) && itr >= 10 && !mcount && itr >= 10) {
|
|
|
|
putMonster(moSkeleton);
|
|
|
|
monpower -= 60;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(10) && itr >= 15) {
|
|
|
|
putMonster(moWitchFire);
|
|
|
|
monpower -= 35;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(100) && itr >= 5) {
|
|
|
|
putMonster(moFlailer);
|
|
|
|
monpower -= 35;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(100) && itr >= 5) {
|
|
|
|
putMonster(moPyroCultist);
|
|
|
|
monpower -= 35;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 20 && kills[moSkeleton]) {
|
|
|
|
putMonster(moFatGuard);
|
|
|
|
monpower -= 35;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 30 && kills[moFlailer]) {
|
|
|
|
putMonster(moHedge);
|
|
|
|
monpower -= 35;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 40 && kills[moHedge]) {
|
|
|
|
putMonster(moLancer);
|
|
|
|
monpower -= 60;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(1) && itr >= 50 && kills[moHedge]) {
|
|
|
|
putMonster(moFireFairy);
|
|
|
|
monpower -= 40;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 60) {
|
|
|
|
putMonster(moBomberbird);
|
|
|
|
monpower -= 25;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 60) {
|
|
|
|
putMonster(moRatlingAvenger);
|
|
|
|
monpower -= 30;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 60) {
|
|
|
|
putMonster(moVineBeast);
|
|
|
|
monpower -= 30;
|
|
|
|
mcount++;
|
|
|
|
}
|
|
|
|
else if(CHANCE(5) && itr >= 60) {
|
|
|
|
dragoncount++;
|
|
|
|
}
|
2018-01-06 21:34:03 +00:00
|
|
|
else if(dragoncount && !nonbitrunc && !mcount) {
|
2017-10-08 10:10:40 +00:00
|
|
|
bool fill = false;
|
|
|
|
for(int i=0; i<4; i++)
|
|
|
|
if(!dragoncells[i] || dragoncells[i]->monst)
|
|
|
|
fill = true;
|
|
|
|
swap(dragoncells[0], dragoncells[3]);
|
|
|
|
swap(dragoncells[1], dragoncells[2]);
|
|
|
|
if(fill) continue;
|
|
|
|
for(int i=0; i<4; i++) {
|
|
|
|
dragoncells[i]->monst = i ? moDragonTail : moDragonHead;
|
|
|
|
dragoncells[i]->mondir = i==3 ? NODIR : neighborId(dragoncells[i], dragoncells[i+1]);
|
|
|
|
dragoncells[i]->hitpoints = 1;
|
|
|
|
dragoncells[i]->stuntime = 1;
|
|
|
|
playSeenSound(dragoncells[i]);
|
|
|
|
}
|
|
|
|
monpower -= 200;
|
|
|
|
mcount++;
|
|
|
|
dragoncount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int id = hrand(100);
|
|
|
|
if(items[itTreat] == 1) {
|
|
|
|
#if ISMOBILE==0
|
|
|
|
addMessage(XLAT("Hint: use arrow keys to scroll."));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if(items[itTreat] == 2) {
|
|
|
|
#if ISMOBILE==0
|
|
|
|
addMessage(XLAT("Hint: press 1 2 3 4 to change the projection."));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if(items[itTreat] == 3) {
|
|
|
|
items[itOrbShell] += 20;
|
|
|
|
addMessage(XLAT("You gain a protective Shell!"));
|
|
|
|
}
|
|
|
|
else if(items[itTreat] == 4) {
|
|
|
|
items[itOrbShell] += 10;
|
|
|
|
addMessage(XLAT("Hint: magical powers from Treats expire after a number of uses."));
|
|
|
|
}
|
|
|
|
else if(kills[moSkeleton] && CHANCE(10)) {
|
|
|
|
addMessage(XLAT("A magical energy sword. Don't waste its power!"));
|
|
|
|
items[itOrbSword] += 5; // todo facing
|
|
|
|
swordpower += 5;
|
|
|
|
}
|
|
|
|
else if(kills[moDraugr] && items[itOrbSword] && CHANCE(10)) {
|
|
|
|
addMessage(XLAT("Another energy sword!"));
|
|
|
|
items[itOrbSword2] += 5;
|
|
|
|
swordpower += 5;
|
|
|
|
}
|
|
|
|
else if(kills[moFlailer] && CHANCE(10)) {
|
|
|
|
items[itOrbThorns] += 5;
|
|
|
|
addMessage(XLAT("You got Thorns! Stab monsters by moving around them."));
|
|
|
|
}
|
|
|
|
else if(kills[moGhost] && CHANCE(10)) {
|
|
|
|
items[itOrbAether] += 5;
|
|
|
|
addMessage(XLAT("Aethereal powers let you go through the holes."));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(items[itOrbShell] > ORBBASE)
|
|
|
|
addMessage(XLAT("The tasty treat increases your protection."));
|
|
|
|
else
|
|
|
|
addMessage(XLAT("You gain your protective Shell back!"));
|
|
|
|
items[itOrbShell] += 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ... also includes the Ivory Tower
|
|
|
|
|
|
|
|
namespace dungeon {
|
|
|
|
|
2017-10-30 18:12:33 +00:00
|
|
|
void towerError(cell *c) {
|
|
|
|
// only care in the standard geometry -- weird ones are intentionally left buggy
|
|
|
|
if(!weirdhyperbolic && !sphere && !quotient)
|
|
|
|
raiseBuggyGeneration(c, "ivory tower/dungeon generation error");
|
|
|
|
}
|
|
|
|
|
2017-10-08 10:10:40 +00:00
|
|
|
void buildIvoryTower(cell *c) {
|
|
|
|
/* if(int(c->landparam) % 5 == 0)
|
|
|
|
c->wall = waCamelot;
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(euclid) {
|
2017-10-30 21:47:07 +00:00
|
|
|
if(torus) return;
|
2017-12-28 15:46:10 +00:00
|
|
|
int x, y;
|
|
|
|
tie(x, y) = cell_to_pair(c);
|
2017-12-29 13:20:38 +00:00
|
|
|
string tab6[] = {
|
2017-10-08 10:10:40 +00:00
|
|
|
".####...",
|
|
|
|
"L...L...",
|
|
|
|
".L..L...",
|
|
|
|
"L...L...",
|
|
|
|
"........",
|
|
|
|
"........"
|
|
|
|
};
|
2017-12-29 13:20:38 +00:00
|
|
|
string tab4[] = {
|
|
|
|
"L####L..",
|
|
|
|
"L....L..",
|
|
|
|
"L....L..",
|
|
|
|
"L....L..",
|
|
|
|
"........",
|
|
|
|
"........"
|
|
|
|
};
|
2017-10-08 10:10:40 +00:00
|
|
|
int y0 = y; if(y>32768) y0 -= 65536;
|
|
|
|
|
|
|
|
y0 += 5; y0 %= 12; if(y0<0) y0+=12;
|
|
|
|
|
|
|
|
if(y0 >= 6) { y0 -= 6; x += 4; }
|
|
|
|
|
2017-12-29 13:20:38 +00:00
|
|
|
char ch = euclid6 ? tab6[y0][(x+(y+1)/2)&7] : tab4[y0][x&7];
|
2017-10-08 10:10:40 +00:00
|
|
|
|
|
|
|
if(ch == '#')
|
|
|
|
c->wall = waPlatform;
|
|
|
|
else if(ch == 'L')
|
|
|
|
c->wall = waLadder;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(true) {
|
|
|
|
|
|
|
|
cell *c2 = c;
|
|
|
|
cell *c3 = c;
|
|
|
|
|
|
|
|
bool rdepths[5];
|
|
|
|
for(int i=0; i<5; i++) {
|
|
|
|
if(coastvalEdge(c2) == 0) {
|
|
|
|
rdepths[i] = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cell *c4 = c2;
|
|
|
|
if(c2 != c3 && !isNeighbor(c2, c3)) {
|
|
|
|
for(int i=0; i<c2->type; i++) if(c2->mov[i] && isNeighbor(c2->mov[i], c3))
|
|
|
|
c4 = c2->mov[i];
|
|
|
|
}
|
|
|
|
rdepths[i] = c2 && c3 && c4 && (c2->landflags == 3 || c3->landflags == 3 || c4->landflags == 3);
|
|
|
|
c2 = chosenDown(c2, 1, 0); // if(!c2) break;
|
|
|
|
c3 = chosenDown(c3, -1, 0);
|
2017-10-30 18:12:33 +00:00
|
|
|
if(!c2) { towerError(c); return; }
|
|
|
|
if(!c3) { towerError(c); return; }
|
2017-10-08 10:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(rdepths[3]) {
|
|
|
|
c->wall = waPlatform;
|
|
|
|
// if(!c4->item) c4->item = itPalace;
|
|
|
|
}
|
|
|
|
else if(!rdepths[2] && !rdepths[4] && !rdepths[1]) {
|
|
|
|
c2 = c;
|
|
|
|
c3 = c;
|
|
|
|
cell *c4 = chosenDown(c, 1, 1);
|
|
|
|
cell *c5 = chosenDown(c, -1, -1);
|
|
|
|
for(int i=0; i<3; i++) {
|
|
|
|
if(coastvalEdge(c2) == 0) break;
|
|
|
|
if(c2 && c4 && c4->landflags == 3 && c2->landflags != 3 && c4 == chosenDown(c2, 1, 1))
|
|
|
|
c->wall = waLadder;
|
|
|
|
if(c3 && c5 && c5->landflags == 3 && c3->landflags != 3 && c5 == chosenDown(c3, -1, -1))
|
|
|
|
c->wall = waLadder;
|
|
|
|
buildEquidistant(c4); buildEquidistant(c5);
|
|
|
|
if(c2) c2 = chosenDown(c2, 1, 0);
|
|
|
|
if(c3) c3 = chosenDown(c3, -1, 0);
|
|
|
|
if(c4) c4 = chosenDown(c4, 1, 0);
|
|
|
|
if(c5) c5 = chosenDown(c5, -1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else c->wall = waCIsland;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dungeonFlags(cell *c) {
|
|
|
|
if(!c) return 0;
|
|
|
|
buildEquidistant(c);
|
|
|
|
bool rdepths[5];
|
|
|
|
|
|
|
|
cell *c2 = c;
|
|
|
|
cell *c3 = c;
|
|
|
|
|
|
|
|
int switchcount = 0;
|
|
|
|
for(int i=0; i<5; i++) {
|
|
|
|
if(coastvalEdge(c2) == 0) {
|
|
|
|
rdepths[i] = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cell *c4 = c2;
|
|
|
|
if(c2 != c3 && !isNeighbor(c2, c3)) {
|
|
|
|
for(int i=0; i<c2->type; i++) if(c2->mov[i] && isNeighbor(c2->mov[i], c3))
|
|
|
|
c4 = c2->mov[i];
|
|
|
|
}
|
|
|
|
rdepths[i] = c2 && c3 && c4 && (c2->landflags == 3 || c3->landflags == 3 || c4->landflags == 3);
|
|
|
|
if((c2&&c2->landflags == 1) || (c3&&c3->landflags == 1) || (c4&&c4->landflags == 1))
|
|
|
|
switchcount++;
|
|
|
|
c2 = chosenDown(c2, 1, 0); // if(!c2) break;
|
|
|
|
c3 = chosenDown(c3, -1, 0);
|
2017-10-30 18:12:33 +00:00
|
|
|
if(!c2) { towerError(c); return 0; }
|
|
|
|
if(!c3) { towerError(c); return 0; }
|
2017-10-08 10:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if(rdepths[3]) res |= 1;
|
|
|
|
if(rdepths[2]) res |= 2;
|
|
|
|
if(switchcount&1) res |= 4;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void placeGate(cell *c, eWall w) {
|
|
|
|
if(w == waOpenGate) {
|
|
|
|
c->wall = waClosedGate;
|
|
|
|
toggleGates(c, waOpenPlate, 0);
|
|
|
|
}
|
|
|
|
if(w == waClosedGate) {
|
|
|
|
c->wall = waOpenGate;
|
|
|
|
toggleGates(c, waClosePlate, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isGate(eWall w) {
|
|
|
|
return w == waOpenGate || w == waClosedGate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void placeRandomGate(cell *c) {
|
|
|
|
placeGate(c, hrand(2) ? waOpenGate : waClosedGate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void build(cell *c) {
|
|
|
|
/* if(int(c->landparam) % 5 == 0)
|
|
|
|
c->wall = waCamelot;
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(true) {
|
|
|
|
|
|
|
|
if(coastvalEdge(c) == 1) forCellEx(c2, c)
|
|
|
|
if(c2->land != laBarrier && c2->land != laDungeon) {
|
|
|
|
c->wall = waLadder;
|
|
|
|
c->wparam = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
int df = dungeonFlags(c);
|
|
|
|
|
|
|
|
if(df&1) {
|
|
|
|
int df1 = dungeonFlags(chosenDown(c,1,1));
|
|
|
|
int df2 = dungeonFlags(chosenDown(c,-1,-1));
|
|
|
|
|
|
|
|
c->wparam = 0;
|
|
|
|
if(hrand(100) < (c->landparam % 5 == 0 ? 80 : 20)) {
|
|
|
|
if(!(df1&1)) c->wparam = 1;
|
|
|
|
if(!(df2&1)) c->wparam = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(df&4)
|
|
|
|
placeRandomGate(c);
|
|
|
|
else if(c->wparam == 0 && c->landparam % 5 == 0 && hrand(100) < 10) {
|
|
|
|
c->wall = waLadder;
|
|
|
|
c->wparam = 3 + hrand(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c->wall = waPlatform;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(c->wparam) {
|
|
|
|
/* int q = 0;
|
2017-10-27 18:07:58 +00:00
|
|
|
cell* downs[MAX_EDGE];
|
2017-10-08 10:10:40 +00:00
|
|
|
forCellEx(c2, c) {
|
|
|
|
buildEquidistant(c2);
|
|
|
|
if(coastvalEdge(c2) > coastvalEdge(c)) downs[q++] = c2;
|
|
|
|
}
|
|
|
|
if(q) downs[hrand(q)]->wall = waLadder;
|
|
|
|
*/
|
|
|
|
cell *c2 =
|
|
|
|
c->wparam == 1 ? chosenDown(c, 1, 2) :
|
|
|
|
c->wparam == 2 ? chosenDown(c, -1, -2) :
|
|
|
|
c->wparam == 3 ? chosenDown(c, 1, 3) :
|
|
|
|
c->wparam == 4 ? chosenDown(c, -1, -3) :
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
if(c2) {
|
|
|
|
c2->wall = c->wall, c2->wparam = c->wparam;
|
|
|
|
if(c2->wall == waPlatform && hrand(10) < 2)
|
|
|
|
placeRandomGate(c2);
|
|
|
|
if(isGate(c2->wall) && hrand(10) < 2)
|
|
|
|
c2->wall = waPlatform;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else c->wall = waCIsland;
|
|
|
|
}
|
|
|
|
|
|
|
|
void buildPlates(cell *c) {
|
|
|
|
if(c->wall) return;
|
|
|
|
int neargate = 0;
|
|
|
|
int neargateDown = 0;
|
|
|
|
int neargateEq = 0;
|
|
|
|
int qup = 0;
|
|
|
|
forCellEx(c2, c) {
|
|
|
|
int d = coastvalEdge(c2) - coastvalEdge(c);
|
|
|
|
if(isGate(c2->wall)) {
|
|
|
|
neargate++;
|
|
|
|
if(d>0) neargateDown++;
|
|
|
|
if(d==0) neargateEq = 0;
|
|
|
|
}
|
|
|
|
if(d<0) qup++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!neargate) return;
|
|
|
|
|
|
|
|
int hr = 99;
|
|
|
|
|
|
|
|
if(neargate == neargateDown && qup == 1)
|
|
|
|
hr = hrand(12);
|
|
|
|
else if((zebra40(c) >= 40) && !(neargateEq && neargateDown))
|
|
|
|
hr = hrand(36);
|
|
|
|
else if(zebra40(c) >= 40)
|
|
|
|
hr = hrand(5000);
|
|
|
|
|
|
|
|
if(hr < 5) c->wall = waClosePlate;
|
|
|
|
else if(hr < 10) c->wall = waOpenPlate;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is02(int i) { return i == 0 || i == 2; }
|
|
|
|
|
|
|
|
void all(cell *c, int d) {
|
|
|
|
if(d == 8 && (c->land == laIvoryTower || c->land == laDungeon) && !euclid) {
|
|
|
|
|
|
|
|
if(hrand(1000) < 75 && (c->landparam & 1) ) {
|
|
|
|
c->landflags = 3;
|
|
|
|
}
|
|
|
|
else c->landflags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d == 8 && c->land == laDungeon && !euclid) {
|
|
|
|
if(hrand(1000) < 240 && is02(c->landparam%5) ) {
|
|
|
|
c->landflags = 3;
|
|
|
|
}
|
|
|
|
else if(hrand(1000) < 90)
|
|
|
|
c->landflags = 1;
|
|
|
|
else c->landflags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(d == 7 && c->land == laIvoryTower) buildIvoryTower(c);
|
|
|
|
if(d == 8 && c->land == laDungeon) build(c);
|
|
|
|
if(d == 7 && c->land == laDungeon) buildPlates(c);
|
|
|
|
}
|
|
|
|
}
|