Advanced Strategic Command
ed_mapcomponent.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #include "ed_mapcomponent.h"
22 #include "edglobal.h"
23 #include "spfst.h"
24 #include "spfst-legacy.h"
25 #include "ed_mapcomponent.h"
26 
27 #include "lua/luastate.h"
28 #include "lua/luarunner.h"
29 
30 int MapComponent::currentPlayer = 0;
31 bool MapComponent::initialized = false;
32 
33 void MapComponent::setPlayer( int player )
34 {
35  currentPlayer = player;
36 };
37 
38 void VehicleItem :: display( Surface& s, const SPoint& pos ) const {
39  if ( actmap ) {
40  int player = selection.getPlayer();
41  if ( player > 7 || player < 0 )
42  player = 0;
43  item->paint ( s, pos, actmap->getPlayer( player ).getPlayerColor());
44  } else
45  item->paint ( s, pos );
46 };
47 
48 
49 MapComponent::MapComponent( const MapItemType* item ) : mapItem( item )
50 {
51  if ( !initialized ) {
52  initialized = true;
53  selection.playerChanged.connect( sigc::ptr_fun( &MapComponent::setPlayer ));
54 
55  }
56 }
57 
58 LuaBrush::LuaBrush( const ASCString& filename ) : script(filename)
59 {
60 
61 }
62 
63 int LuaBrush :: place( const MapCoordinate& mc ) const
64 {
65  LuaState state;
66  LuaRunner runner( state );
67  runner.runFile( script );
68  if ( !runner.getErrors().empty() )
69  errorMessage( runner.getErrors() );
71  return 1;
72 }
73 
75 {
76  return new LuaBrush( script );
77 }
78 
79 
80 
81 
82 
int getPlayer()
Definition: edglobal.h:162
virtual void display(Surface &s, const SPoint &pos) const
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
map accessing and usage routines used by ASC and the mapeditor
void runFile(const ASCString &filename)
Definition: luarunner.cpp:25
PlayerColor getPlayerColor() const
Definition: player.cpp:268
MapComponent(const MapItemType *item)
virtual LuaBrush * clone() const
LuaBrush(const ASCString &filename)
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
const VehicleType * item
int place(const MapCoordinate &mc) const
The base class for everything that can be placed on a map field.
Definition: mapitemtype.h:16
Coordinate on the twodimensional map.
Definition: typen.h:202
ASCString script
sigc::signal< void > updateFieldInfo
Definition: spfst.cpp:47
SDLmm::SPoint SPoint
Definition: surface.h:27
void errorMessage(const ASCString &string)
SelectionHolder selection
Definition: edglobal.cpp:189
void paint(Surface &s, SPoint pos, const PlayerColor &player, int direction=0) const
sigc::signal< void, int > playerChanged
Definition: edglobal.h:164
const ASCString & getErrors()
Definition: luarunner.cpp:61
GameMap * actmap
Definition: spfst.cpp:64