mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-28 02:50:34 +00:00
more fixes to multiplayer
This commit is contained in:
parent
032a6b6df2
commit
40d450676e
@ -1178,9 +1178,9 @@ EX void killThePlayer(eMonster m, int id, flagtype flags) {
|
||||
}
|
||||
|
||||
EX void killThePlayerAt(eMonster m, cell *c, flagtype flags) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(playerpos(i) == c)
|
||||
killThePlayer(m, i, flags);
|
||||
for(int i: player_indices())
|
||||
if(playerpos(i) == c)
|
||||
killThePlayer(m, i, flags);
|
||||
}
|
||||
|
||||
#if HDR
|
||||
|
@ -585,7 +585,9 @@ void celldrawer::setcolors() {
|
||||
bool inrange = c->mpdist <= GUNRANGE;
|
||||
if(inrange) {
|
||||
inrange = false;
|
||||
for(int i=0; i<numplayers(); i++) for(cell *c1: gun_targets(playerpos(i))) if(c1 == c) inrange = true;
|
||||
for(cell *pc: player_positions())
|
||||
for(cell *c1: gun_targets(pc)) if(c1 == c)
|
||||
inrange = true;
|
||||
}
|
||||
if(!inrange)
|
||||
fcol = gradient(fcol, 0, 0, 25, 100),
|
||||
@ -1842,13 +1844,12 @@ void celldrawer::bookkeeping() {
|
||||
playerfound = true;
|
||||
|
||||
if(multi::players > 1) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(playerpos(i) == c) {
|
||||
playerV = V * ddspin(c, multi::player[i].spin, 0);
|
||||
if(multi::player[i].mirrored) playerV = playerV * Mirror;
|
||||
if(orig)
|
||||
multi::whereis[i] = playerV;
|
||||
}
|
||||
for(int i: player_indices()) if(playerpos(i) == c) {
|
||||
playerV = V * ddspin(c, multi::player[i].spin, 0);
|
||||
if(multi::player[i].mirrored) playerV = playerV * Mirror;
|
||||
if(orig)
|
||||
multi::whereis[i] = playerV;
|
||||
}
|
||||
}
|
||||
else {
|
||||
playerV = V * ddspin(c, cwt.spin, 0);
|
||||
|
14
complex2.cpp
14
complex2.cpp
@ -671,8 +671,8 @@ EX void check_around(cell *c) {
|
||||
}
|
||||
|
||||
EX void check() {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
forCellEx(c, playerpos(i)) {
|
||||
for(cell *pc: player_positions())
|
||||
forCellEx(c, pc) {
|
||||
if(shmup::on) {
|
||||
forCellEx(c2, c)
|
||||
check(c2);
|
||||
@ -709,16 +709,16 @@ EX void check_state() {
|
||||
}
|
||||
if(items[itHunting] > 5 && items[itHunting] <= 22) {
|
||||
int q = 0;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
forCellEx(c2, playerpos(i))
|
||||
for(cell *pc: player_positions())
|
||||
forCellEx(c2, pc)
|
||||
if(cl.listed(c2))
|
||||
q++;
|
||||
if(q == 1) havewhat |= HF_FAILED_AMBUSH;
|
||||
if(q == 2) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
forCellEx(c2, playerpos(i))
|
||||
for(cell *pc: player_positions())
|
||||
forCellEx(c2, pc)
|
||||
if(cl.listed(c2))
|
||||
forCellEx(c3, playerpos(i))
|
||||
forCellEx(c3, pc)
|
||||
if(c3 != c2 && isNeighbor(c2,c3))
|
||||
if(cl.listed(c3))
|
||||
havewhat |= HF_FAILED_AMBUSH;
|
||||
|
@ -286,9 +286,7 @@ EX void bfs() {
|
||||
|
||||
recalcTide = false;
|
||||
|
||||
for(int i=0; i<numplayers(); i++) {
|
||||
cell *c = playerpos(i);
|
||||
if(!c) continue;
|
||||
for(cell *c: player_positions()) {
|
||||
if(c->cpdist == 0) continue;
|
||||
c->cpdist = 0;
|
||||
checkTide(c);
|
||||
@ -299,9 +297,7 @@ EX void bfs() {
|
||||
|
||||
int distlimit = gamerange();
|
||||
|
||||
for(int i=0; i<numplayers(); i++) {
|
||||
cell *c = playerpos(i);
|
||||
if(!c) continue;
|
||||
for(cell *c: player_positions()) {
|
||||
if(items[itOrbDomination])
|
||||
if(c->monst == moTentacle || c->monst == moTentaclewait || c->monst == moTentacleEscaping)
|
||||
worms.push_back(c);
|
||||
@ -799,8 +795,9 @@ EX void monstersTurn() {
|
||||
DEBB(DF_TURN, ("mmo"));
|
||||
int phase2 = (1 & items[itOrbSpeed]);
|
||||
if(!phase2) movemonsters();
|
||||
for(int i=0; i<numplayers(); i++) if(playerpos(i)->item == itOrbSafety) {
|
||||
collectItem(playerpos(i), true);
|
||||
|
||||
for(cell *pc: player_positions()) if(pc->item == itOrbSafety) {
|
||||
collectItem(pc, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -852,9 +849,8 @@ EX void monstersTurn() {
|
||||
#endif
|
||||
|
||||
if(items[itOrbFreedom])
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
checkFreedom(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
checkFreedom(pc);
|
||||
|
||||
DEBB(DF_TURN, ("check"));
|
||||
checkmove();
|
||||
@ -862,9 +858,8 @@ EX void monstersTurn() {
|
||||
|
||||
|
||||
#if CAP_HISTORY
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
history::movehistory.push_back(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
history::movehistory.push_back(pc);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ EX int mirrorcolor(bool mirrored) {
|
||||
|
||||
EX bool isMounted(cell *c) {
|
||||
if(c && c->monst && c->monst != moTentacleGhost && isMountable(c->monst)) {
|
||||
for(int i=0; i<numplayers(); i++) {
|
||||
for(int i: player_indices()) {
|
||||
if(playerpos(i)->monst && sameMonster(c, playerpos(i)))
|
||||
return true;
|
||||
if(lastmountpos[i] && lastmountpos[i]->monst && sameMonster(c, lastmountpos[i]))
|
||||
|
4
game.cpp
4
game.cpp
@ -449,8 +449,8 @@ EX bool sameMonster(cell *c1, cell *c2) {
|
||||
}
|
||||
|
||||
EX eMonster haveMount() {
|
||||
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i)) {
|
||||
eMonster m = playerpos(i)->monst;
|
||||
for(cell *pc: player_positions()) {
|
||||
eMonster m = pc->monst;
|
||||
if(m) return m;
|
||||
}
|
||||
return moNone;
|
||||
|
@ -178,8 +178,8 @@ EX int flip_dark(int f, int a0, int a1) {
|
||||
color_t fc(int ph, color_t col, int z) {
|
||||
if(items[itOrbFire]) col = darkena(firecolor(ph), 0, 0xFF);
|
||||
if(items[itOrbAether]) col = (col &~0XFF) | (col&0xFF) / 2;
|
||||
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i))
|
||||
if(items[itOrbFish] && isWatery(playerpos(i)) && z != 3) return watercolor(ph);
|
||||
for(cell *pc: player_positions())
|
||||
if(items[itOrbFish] && isWatery(pc) && z != 3) return watercolor(ph);
|
||||
if(invismove)
|
||||
col =
|
||||
shmup::on ?
|
||||
@ -4194,7 +4194,7 @@ EX void drawMarkers() {
|
||||
if(!(cmode & sm::NORMAL)) return;
|
||||
|
||||
if(should_draw_mouse_cursor()) {
|
||||
for(int i=0; i<numplayers(); i++) if(multi::playerActive(i)) {
|
||||
for(int i: player_indices()) {
|
||||
queueline(ggmatrix(playerpos(i)) * (WDIM == 2 && GDIM == 3 ? zpush0(cgi.WALL) : C0), mouseh, 0xFF00FF, grid_prec() + 1);
|
||||
}
|
||||
}
|
||||
@ -5269,7 +5269,7 @@ EX void drawscreen() {
|
||||
|
||||
if(tmines == 7) seenSevenMines = true;
|
||||
|
||||
for(int p=0; p<numplayers(); p++) if(multi::playerActive(p))
|
||||
for(int p: player_indices())
|
||||
displayfr(vid.xres * (p+.5) / numplayers(),
|
||||
current_display->ycenter - current_display->radius * 3/4, 2,
|
||||
vid.fsize,
|
||||
|
@ -442,14 +442,12 @@ EX namespace inv {
|
||||
|
||||
void evokeOrb(eItem it) {
|
||||
if(it == itOrbFreedom)
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
checkFreedom(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
checkFreedom(pc);
|
||||
|
||||
if(it == itOrbBeauty) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
evokeBeautyAt(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
evokeBeautyAt(pc);
|
||||
if(items[itOrbEmpathy])
|
||||
for(cell *c: dcal) if(isFriendly(c->monst))
|
||||
evokeBeautyAt(c);
|
||||
@ -464,12 +462,11 @@ EX namespace inv {
|
||||
}
|
||||
|
||||
if(it == itOrbSword || it == itOrbSword2) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i)) {
|
||||
cwt.at = playerpos(i);
|
||||
multi::cpid = i;
|
||||
swordAttackStatic(it == itOrbSword2);
|
||||
}
|
||||
for(int i: player_indices()) {
|
||||
cwt.at = playerpos(i);
|
||||
multi::cpid = i;
|
||||
swordAttackStatic(it == itOrbSword2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ EX bool chaosUnlocked = false;
|
||||
EX bool chaosAchieved = false;
|
||||
|
||||
EX void doOvergenerate() {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
setdist(playerpos(i), 7 - getDistLimit() - genrange_bonus, NULL);
|
||||
for(cell *pc: player_positions())
|
||||
setdist(pc, 7 - getDistLimit() - genrange_bonus, NULL);
|
||||
}
|
||||
|
||||
EX bool notDippingFor(eItem i) {
|
||||
|
@ -555,7 +555,7 @@ EX int stayval(cell *c, flagtype mf) {
|
||||
EX int totalbulldistance(cell *c, int k) {
|
||||
shpos.resize(SHSIZE);
|
||||
int tbd = 0;
|
||||
for(int p=0; p<numplayers(); p++) {
|
||||
for(int p: player_indices()) {
|
||||
cell *c2 = shpos[p][(cshpos+SHSIZE-k-1)%SHSIZE];
|
||||
if(c2) tbd += bulldistance(c, c2);
|
||||
}
|
||||
@ -1172,11 +1172,9 @@ EX void groupmove(eMonster movtype, flagtype mf) {
|
||||
else {
|
||||
if(!peace::on) for(int i=0; i<isize(targets); i++) gendfs.push_back(targets[i]);
|
||||
|
||||
if(invisfish && (movtype == moSlime || movtype == moShark || movtype == moKrakenH)) for(int i=0; i<numplayers(); i++) {
|
||||
cell *c = playerpos(i);
|
||||
if(!c) continue;
|
||||
gendfs.push_back(c);
|
||||
}
|
||||
if(invisfish && (movtype == moSlime || movtype == moShark || movtype == moKrakenH))
|
||||
for(cell *pc: player_positions())
|
||||
gendfs.push_back(pc);
|
||||
}
|
||||
|
||||
targetcount = isize(gendfs);
|
||||
@ -1433,7 +1431,7 @@ EX void moveshadow() {
|
||||
cell *shfrom = NULL;
|
||||
|
||||
shpos.resize(SHSIZE);
|
||||
for(int p=0; p<numplayers(); p++) {
|
||||
for(int p: player_indices()) {
|
||||
cell *c = shpos[p][cshpos];
|
||||
if(c && c->monst == moShadow) {
|
||||
for(int j=0; j<c->type; j++)
|
||||
@ -1445,7 +1443,7 @@ EX void moveshadow() {
|
||||
shpos[p][cshpos] = playerpos(p);
|
||||
}
|
||||
cshpos = (cshpos+1) % SHSIZE;
|
||||
for(int p=0; p<numplayers(); p++) {
|
||||
for(int p: player_indices()) {
|
||||
cell* where = shpos[p][cshpos];
|
||||
if(where && where->monst == moNone && where->cpdist && where->land == laGraveyard &&
|
||||
!sword::at(where)) {
|
||||
@ -2038,7 +2036,9 @@ EX void movemonsters() {
|
||||
DEBB(DF_TURN, ("westwall"));
|
||||
if(havewhat & HF_WESTWALL) westwall::move();
|
||||
#endif
|
||||
for(int i=0; i<numplayers(); i++) if(playerpos(i)->item == itOrbSafety) return;
|
||||
for(cell *pc: player_positions())
|
||||
if(pc->item == itOrbSafety)
|
||||
return;
|
||||
DEBB(DF_TURN, ("river"));
|
||||
if(havewhat & HF_RIVER) prairie::move();
|
||||
/* DEBB(DF_TURN, ("magnet"));
|
||||
|
10
multi.cpp
10
multi.cpp
@ -797,7 +797,7 @@ EX void handleInput(int delta) {
|
||||
}
|
||||
|
||||
EX void checklastmove() {
|
||||
for(int i=0; i<numplayers(); i++) if(playerActive(i)) {
|
||||
for(int i: player_indices()) {
|
||||
multi::cpid = i;
|
||||
cwt = multi::player[i]; break;
|
||||
}
|
||||
@ -824,7 +824,7 @@ EX void handleInput(int delta) {
|
||||
multi::player[0] = cwt;
|
||||
}
|
||||
|
||||
for(int i=0; i<numplayers(); i++) if(playerActive(i)) {
|
||||
for(int i: player_indices()) {
|
||||
|
||||
using namespace multi;
|
||||
|
||||
@ -908,13 +908,13 @@ EX void handleInput(int delta) {
|
||||
// check for crashes
|
||||
needinput = true;
|
||||
|
||||
for(int i=0; i<numplayers(); i++) if(playerActive(i)) {
|
||||
for(int i: player_indices()) {
|
||||
origpos[i] = player[i].at;
|
||||
origtarget[i] = multiPlayerTarget(i);
|
||||
}
|
||||
|
||||
for(int i=0; i<numplayers(); i++) if(playerActive(i))
|
||||
for(int j=0; j<numplayers(); j++) if(playerActive(j)) if(i != j) {
|
||||
for(int i: player_indices())
|
||||
for(int j: player_indices()) if(i != j) {
|
||||
if(origtarget[i] == origtarget[j]) {
|
||||
addMessage("Two players cannot move/attack the same location!");
|
||||
return;
|
||||
|
12
orbs.cpp
12
orbs.cpp
@ -293,8 +293,8 @@ EX void checkFreedom(cell *cf) {
|
||||
}
|
||||
addMessage(XLAT("Your %1 activates!", itOrbFreedom));
|
||||
drainOrb(itOrbFreedom);
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
drawBigFlash(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
drawBigFlash(pc);
|
||||
for(int i=0; i<isize(dcal); i++) {
|
||||
cell *c = dcal[i];
|
||||
if(c == cf && !shmup::on) continue;
|
||||
@ -306,8 +306,8 @@ EX void checkFreedom(cell *cf) {
|
||||
EX void activateFlash() {
|
||||
int tk = tkills();
|
||||
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
drawFlash(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
drawFlash(pc);
|
||||
|
||||
addMessage(XLAT("You activate the Flash spell!"));
|
||||
playSound(cwt.at, "storm");
|
||||
@ -513,8 +513,8 @@ EX void activateLightning() {
|
||||
|
||||
drainOrb(itOrbLightning);
|
||||
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
castLightningBoltFrom(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
castLightningBoltFrom(pc);
|
||||
|
||||
elec::afterOrb = true;
|
||||
elec::act();
|
||||
|
@ -137,9 +137,7 @@ EX bool passable(cell *w, cell *from, flagtype flags) {
|
||||
|
||||
if(from && from != w && nonAdjacent(from, w) && !F(P_IGNORE37 | P_BULLET)) return false;
|
||||
|
||||
for(int i=0; i<numplayers(); i++) {
|
||||
cell *pp = playerpos(i);
|
||||
if(!pp) continue;
|
||||
for(cell *pp: player_positions()) {
|
||||
if(w == pp && F(P_ONPLAYER)) return true;
|
||||
if(from == pp && F(P_ONPLAYER) && F(P_REVDIR)) return true;
|
||||
|
||||
|
34
pcmove.cpp
34
pcmove.cpp
@ -324,8 +324,8 @@ bool pcmove::after_move() {
|
||||
invisfish = false;
|
||||
if(items[itOrbFish]) {
|
||||
invisfish = true;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i) && !isWatery(playerpos(i)))
|
||||
for(cell *pc: player_positions())
|
||||
if(!isWatery(pc))
|
||||
invisfish = false;
|
||||
if(d < 0) invisfish = false; // no invisibility if staying still
|
||||
if(invisfish) invismove = true, markOrb(itOrbFish);
|
||||
@ -1193,8 +1193,8 @@ EX bool warningprotection_hit(eMonster m) {
|
||||
}
|
||||
|
||||
EX bool playerInWater() {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i) && isWatery(playerpos(i)) && !playerInBoat(i))
|
||||
for(int i: player_indices())
|
||||
if(isWatery(playerpos(i)) && !playerInBoat(i))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -1203,6 +1203,22 @@ EX int numplayers() {
|
||||
return multi::players;
|
||||
}
|
||||
|
||||
EX vector<cell*> player_positions() {
|
||||
vector<cell*> res;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
res.push_back(playerpos(i));
|
||||
return res;
|
||||
}
|
||||
|
||||
EX vector<int> player_indices() {
|
||||
vector<int> res;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
res.push_back(i);
|
||||
return res;
|
||||
}
|
||||
|
||||
EX cell *playerpos(int i) {
|
||||
if(shmup::on) return shmup::playerpos(i);
|
||||
if(multi::players > 1) return multi::player[i].at;
|
||||
@ -1210,14 +1226,14 @@ EX cell *playerpos(int i) {
|
||||
}
|
||||
|
||||
EX bool allPlayersInBoats() {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i) && playerpos(i)->wall != waBoat) return true;
|
||||
for(cell *pc: player_positions())
|
||||
if(pc->wall != waBoat) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
EX int whichPlayerOn(cell *c) {
|
||||
if(singleused()) return c == singlepos() ? 0 : -1;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
for(int i: player_indices())
|
||||
if(playerpos(i) == c) return i;
|
||||
return -1;
|
||||
}
|
||||
@ -1245,8 +1261,8 @@ EX bool isPlayerInBoatOn(cell *c) {
|
||||
EX bool playerInPower() {
|
||||
if(singleused())
|
||||
return singlepos()->land == laPower || singlepos()->land == laHalloween;
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i) && (playerpos(i)->land == laPower || playerpos(i)->land == laHalloween))
|
||||
for(cell *pc: player_positions())
|
||||
if(pc->land == laPower || pc->land == laHalloween)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
12
system.cpp
12
system.cpp
@ -326,12 +326,11 @@ EX void initgame() {
|
||||
#endif
|
||||
|
||||
if(multi::players > 1 && !shmup::on) {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
makeEmpty(playerpos(i));
|
||||
for(cell *pc: player_positions())
|
||||
makeEmpty(pc);
|
||||
}
|
||||
else {
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
makeEmpty(cwt.at);
|
||||
makeEmpty(cwt.at);
|
||||
}
|
||||
|
||||
if(specialland == laMinefield && bounded) {
|
||||
@ -1258,9 +1257,8 @@ EX void stop_game() {
|
||||
for(int i=0; i<10; i++) for(int l=0; l<landtypes; l++)
|
||||
exploreland[i][l] = 0;
|
||||
|
||||
for(int i=0; i<numplayers(); i++)
|
||||
if(multi::playerActive(i))
|
||||
multi::deaths[i]++;
|
||||
for(int i: player_indices())
|
||||
multi::deaths[i]++;
|
||||
|
||||
#if CAP_SAVE
|
||||
anticheat::tampered = false;
|
||||
|
Loading…
Reference in New Issue
Block a user