.bool snake_tail;
-.int snake_lives;
+.int snake_lives[SNAKE_TEAMS + 1];
.int snake_lost_teams;
for(int i = 1; i <= SNAKE_TEAMS; ++i)
{
entity pl = snake_get_player(minigame, i);
- if(pl)
- if(pl.snake_lives > 0)
+ if(pl && minigame.snake_lives[i] > 0)
{
if(winning_team)
return 0;
- winning_team = pl.team;
+ winning_team = i;
}
}
for(int i = 1; i <= SNAKE_TEAMS; ++i)
{
entity pl = snake_get_player(minigame, i);
- if(pl)
- if(pl.snake_lives > 0)
+ if(pl && minigame.snake_lives[i] > 0)
++alivecnt;
}
return world;
}
-void snake_add_score(entity minigame, int pteam, .int score_field, int thescore)
+void snake_add_score(entity minigame, int pteam, int thescore)
{
#ifdef SVQC
if(!minigame)
entity pl = snake_get_player(minigame, pteam);
if(pl)
{
- pl.score_field += thescore;
+ pl.snake_score += thescore;
pl.SendFlags |= SNAKE_SF_PLAYERSCORE;
}
#endif
int newcnt = tail.cnt + 1;
head.snake_delay = max(autocvar_sv_minigames_snake_delay_min, autocvar_sv_minigames_snake_delay_initial - (newcnt / autocvar_sv_minigames_snake_delay_multiplier));
- snake_add_score(minigame, head.team, snake_score, 1);
+ snake_add_score(minigame, head.team, 1);
entity piece = msle_spawn(minigame,"minigame_board_piece");
piece.cnt = newcnt;
entity head = snake_find_head(minigame, pteam);
if(!head) { return; }
- snake_add_score(minigame, pteam, snake_lives, -1);
+ minigame.snake_lives[pteam] -= 1;
+
+ entity pl = snake_get_player(minigame, pteam);
+#ifdef SVQC
+ pl.SendFlags |= SNAKE_SF_PLAYERSCORE;
+#endif
+
head.nextthink = time + 1; // make sure they don't to eat us somehow
entity e = world;
remove(e);
}
- entity pl = snake_get_player(minigame, pteam);
- if(pl.snake_lives > 0)
- minigame_setup_snake(minigame, pteam);
- else
+ if(minigame.snake_lives[pteam] <= 0)
minigame.snake_lost_teams |= BIT(pteam);
+
+ if(pl && minigame.snake_lives[pteam] > 0)
+ minigame_setup_snake(minigame, pteam);
}
void snake_move_head(entity minigame, entity head)
}
else
{
- snake_add_score(minigame, head.team, snake_score, -1);
+ snake_add_score(minigame, head.team, -1);
snake_eat_team(minigame, head.team);
}
if(hit.cnt)
{
snake_eat_team(minigame, hit.team);
- snake_add_score(minigame, head.team, snake_score, 1);
+ snake_add_score(minigame, head.team, 1);
}
if(ate_mouse)
snake_setup_pieces(minigame);
minigame.minigame_flags = SNAKE_TURN_MOVE;
minigame.snake_lost_teams = 0;
+
+ if(SNAKE_TEAMS > 1)
+ {
+ for(int i = 1; i <= SNAKE_TEAMS; ++i)
+ minigame.snake_lives[i] = autocvar_sv_minigames_snake_lives;
+ }
+ else
+ minigame.snake_lives[1] = 1;
+
return true;
}
case "end":
entity pl = ...(1,entity);
if(pl)
{
- pl.snake_lives = ((SNAKE_TEAMS > 1) ? autocvar_sv_minigames_snake_lives : 1);
+ //pl.snake_lives = ((SNAKE_TEAMS > 1) ? autocvar_sv_minigames_snake_lives : 1);
+ // send score anyway, lives are set
pl.SendFlags |= SNAKE_SF_PLAYERSCORE;
}
minigame_setup_snake(minigame, t);
else if ( sent.classname == "minigame_player" && (sf & SNAKE_SF_PLAYERSCORE ) )
{
WriteLong(MSG_ENTITY,sent.snake_score);
- WriteByte(MSG_ENTITY,max(0, sent.snake_lives));
+ WriteByte(MSG_ENTITY,max(0, minigame.snake_lives[sent.team]));
}
else if ( sent.classname == "minigame" && (sf & MINIG_SF_UPDATE ) )
{
}
}
- if ( (active_minigame.minigame_flags & SNAKE_TURN_LOSS) || (active_minigame.minigame_flags & SNAKE_TURN_WIN) || (minigame_self.snake_lives <= 0) )
+ if ( (active_minigame.minigame_flags & SNAKE_TURN_LOSS) || (active_minigame.minigame_flags & SNAKE_TURN_WIN) || (active_minigame.snake_lives[minigame_self.team] <= 0) )
{
int scores = minigame_self.snake_score;
if(active_minigame.minigame_flags & SNAKE_TURN_WIN)
if((active_minigame.minigame_flags & SNAKE_TURN_TEAM) == minigame_self.team)
victory_text = "You win!";
- if(minigame_self.snake_lives <= 0)
+ if(active_minigame.snake_lives[minigame_self.team] <= 0)
victory_text = "You ran out of lives!";
vector win_pos = pos+eY*(mySize_y-winfs_y)/2;
mypos_x += tile_size_x;
- drawstring(mypos,strcat("1UP: ", ftos(e.snake_lives)),tile_size * 0.6,
+ drawstring(mypos,strcat("1UP: ", ftos(active_minigame.snake_lives[e.team])),tile_size * 0.6,
'0.7 0.84 1', panel_fg_alpha, DRAWFLAG_NORMAL);
}
}
return _("You win!");
}
- if(minigame_self.snake_lives <= 0)
+ if(active_minigame.snake_lives[minigame_self.team] <= 0)
return _("You ran out of lives!");
if ( (snake_find_head(active_minigame, minigame_self.team)).snake_dir == '0 0 0' )
else if ( sent.classname == "minigame_player" && (sf & SNAKE_SF_PLAYERSCORE ) )
{
sent.snake_score = ReadLong();
- sent.snake_lives = ReadByte();
+ minigame.snake_lives[sent.team] = ReadByte();
}
return false;