//
// $Id: HGameOverState.m,v 1.2 1997/10/31 03:38:08 nygard Exp $
//

//
//  This file is a part of Empire, a game of exploration and conquest.
//  Copyright (C) 1996  Steve Nygard
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//  You may contact the author by:
//     e-mail:  nygard@telusplanet.net
//

#import "Empire.h"

RCSID ("$Id: HGameOverState.m,v 1.2 1997/10/31 03:38:08 nygard Exp $");

#import "HGameOverState.h"

#import "HInitialState.h"
#import "Human.h"
#import "MapView.h"

//======================================================================
// Give the user a chance to view the map as it was when the player
// either lost or won.  The user can view the maps of other players
// as well -- if the other players are still active, this player has
// a snapshot of their maps when this player lost.  If another player
// had lost before this one, the map shown will be that players final
// map as it was when he lost.  All the maps shown will show the
// explored territory for the target player.
//
// Also, a combined map showing the real position of all units for all
// players is created when a player is removed from the game.
//======================================================================

@implementation HGameOverState

//======================================================================
// Subclass responsibilities
//======================================================================

- (NSString *) stateName
{
    return @"Game Over";
}
  
//----------------------------------------------------------------------

- (NSString *) stateKey
{
    return HS_GAME_OVER;
}
  
//----------------------------------------------------------------------

- (void) stateEntered:(Human *)context
{
    MapView *mapView = [context mapView];
  
    // Set cursor
    [mapView setCursorEnabled:NO];

    // Disable both buttons
    [context enableContinueButton:NO];
    [context enableEndTurnButton:NO];

    [context selectThing:nil];
}

//----------------------------------------------------------------------

- (void) continue:(Human *)context
{
    // We override this to catch the spurious -continue: message sent
    // (delayed) from the HMoveState...
}

//----------------------------------------------------------------------

- (void) showFinalMap:(Human *)context forPlayer:(Player)number
{
    [context showFinalMapForPlayer:number];
}
  
//======================================================================
// Interface Management
//======================================================================

- (BOOL) validateMenuItem:(Human *)context:(NSMenuItem *)menuCell
{
    SEL action = [menuCell action];
    BOOL valid = NO;

    // Commands

    if (action == @selector (showFinalCombinedMap:))
    {
        valid = [context finalMapForPlayer:p_neutral] != nil;
    }
    else if (action == @selector (showFinalPlayer1Map:))
    {
        valid = [context finalMapForPlayer:p_player1] != nil;
    }
    else if (action == @selector (showFinalPlayer2Map:))
    {
        valid = [context finalMapForPlayer:p_player2] != nil;
    }
    else if (action == @selector (showFinalPlayer3Map:))
    {
        valid = [context finalMapForPlayer:p_player3] != nil;
    }
    else if (action == @selector (centerScreen:)
             || action == @selector (centerCursor:))
    {
        valid = YES;
    }
    return valid;
}

@end
