2007-01-15 12:09:25 -08:00
/*
This file is part of Warzone 2100.
Copyright ( C ) 1999 - 2004 Eidos Interactive
2013-01-16 12:34:57 -08:00
Copyright ( C ) 2005 - 2013 Warzone 2100 Project
2007-01-15 12:09:25 -08:00
Warzone 2100 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 .
Warzone 2100 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 Warzone 2100 ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
2008-02-16 05:05:34 -08:00
/**
* @ file design . c
2007-06-28 10:47:08 -07:00
*
* Functions for design screen .
*
*/
2006-11-06 06:40:07 -08:00
# include <string.h>
2007-06-28 10:47:08 -07:00
2006-05-27 09:37:17 -07:00
# include "lib/framework/frame.h"
2006-09-23 10:24:55 -07:00
# include "lib/framework/strres.h"
2006-05-27 09:37:17 -07:00
# include "lib/widget/widget.h"
2007-06-28 10:47:08 -07:00
# include "objects.h"
# include "loop.h"
# include "map.h"
/* Includes direct access to render library */
2010-12-31 13:37:14 -08:00
# include "lib/ivis_opengl/ivisdef.h"
# include "lib/ivis_opengl/bitimage.h"
# include "lib/ivis_opengl/pieblitfunc.h"
2006-05-27 09:37:17 -07:00
// FIXME Direct iVis implementation include!
# include "lib/ivis_opengl/piematrix.h"//matrix code
2010-12-31 13:37:14 -08:00
# include "lib/ivis_opengl/piestate.h"
2009-03-08 05:40:42 -07:00
# include "lib/ivis_opengl/screen.h"
2010-12-31 13:37:14 -08:00
# include "lib/ivis_opengl/piemode.h"
2007-06-28 10:47:08 -07:00
# include "display3d.h"
# include "edit3d.h"
# include "structure.h"
# include "research.h"
2006-05-27 09:37:17 -07:00
# include "lib/gamelib/gtime.h"
2007-06-28 10:47:08 -07:00
# include "hci.h"
# include "stats.h"
# include "game.h"
# include "power.h"
2006-05-27 09:37:17 -07:00
# include "lib/sound/audio.h"
# include "lib/widget/widgint.h"
# include "lib/widget/bar.h"
# include "lib/widget/form.h"
# include "lib/widget/label.h"
# include "lib/widget/button.h"
# include "lib/widget/editbox.h"
# include "lib/widget/slider.h"
2007-06-28 10:47:08 -07:00
# include "order.h"
# include "projectile.h"
# include "intimage.h"
# include "intdisplay.h"
# include "design.h"
# include "component.h"
2006-05-27 09:37:17 -07:00
# include "lib/script/script.h"
2007-06-28 10:47:08 -07:00
# include "scripttabs.h"
2007-09-24 11:16:10 -07:00
# include "main.h"
2007-06-28 10:47:08 -07:00
# include "objects.h"
# include "display.h"
# include "console.h"
# include "cmddroid.h"
# include "scriptextern.h"
2007-11-12 11:08:55 -08:00
# include "mission.h"
2011-12-17 15:23:51 -08:00
# include "template.h"
2007-06-28 10:47:08 -07:00
# include "multiplay.h"
# include "multistat.h"
2013-01-16 13:49:17 -08:00
# include "qtscript.h"
2007-06-28 10:47:08 -07:00
2012-02-11 03:24:24 -08:00
# define MAX_DESIGN_COMPONENTS 40 // Max number of stats the design screen can cope with.
# define MAX_SYSTEM_COMPONENTS 128
2007-06-28 10:47:08 -07:00
/***************************************************************************************/
/* Max values for the design bar graphs */
# define DBAR_TEMPLATEMAXPOINTS 8400 //maximum body points for a template
# define DBAR_TEMPLATEMAXPOWER 1000 //maximum power points for a template
/* The maximum number of characters on the component buttons */
# define DES_COMPBUTMAXCHAR 5
/* Which type of system is displayed on the design screen */
2011-02-25 12:30:13 -08:00
enum DES_SYSMODE
2007-06-28 10:47:08 -07:00
{
IDES_SENSOR , // The sensor clickable is displayed
IDES_ECM , // The ECM clickable is displayed
IDES_CONSTRUCT , // The Constructor clickable is displayed
IDES_REPAIR , // The Repair clickable is displayed
IDES_WEAPON , // The Weapon clickable is displayed
IDES_COMMAND , // The command droid clickable is displayed
IDES_NOSYSTEM , // No system clickable has been displayed
2011-02-25 12:30:13 -08:00
} ;
2008-10-12 02:26:40 -07:00
static DES_SYSMODE desSysMode ;
2007-06-28 10:47:08 -07:00
/* The major component tabs on the design screen */
# define IDES_MAINTAB 0
# define IDES_EXTRATAB 1
/* Which component type is being selected on the design screen */
2009-05-21 19:41:13 -07:00
//added IDES_TURRET_A,IDES_TURRET_B,changing the name of IDES_TURRET might break exist codes
2011-02-25 12:30:13 -08:00
enum DES_COMPMODE
2007-06-28 10:47:08 -07:00
{
IDES_SYSTEM , // The main system for the droid (sensor, ECM, constructor)
IDES_TURRET , // The weapon for the droid
IDES_BODY , // The droid body
IDES_PROPULSION , // The propulsion system
IDES_NOCOMPONENT , // No system has been selected
2006-11-04 14:56:28 -08:00
IDES_TURRET_A , // The 2nd turret
IDES_TURRET_B , // The 3rd turret
2011-02-25 12:30:13 -08:00
} ;
2008-10-12 02:26:40 -07:00
static DES_COMPMODE desCompMode ;
2007-06-28 10:47:08 -07:00
/* Which type of propulsion is being selected */
2011-02-25 12:30:13 -08:00
enum DES_PROPMODE
2007-06-28 10:47:08 -07:00
{
IDES_GROUND , // Ground propulsion (wheeled, tracked, etc).
IDES_AIR , // Air propulsion
2008-10-12 02:26:40 -07:00
IDES_NOPROPULSION , // No propulsion has been selected
2011-02-25 12:30:13 -08:00
} ;
2008-10-12 02:26:40 -07:00
static DES_PROPMODE desPropMode ;
2007-06-28 10:47:08 -07:00
2008-03-21 15:49:01 -07:00
# define STRING_BUFFER_SIZE (32 * MAX_STR_LENGTH)
2007-06-28 10:47:08 -07:00
char StringBuffer [ STRING_BUFFER_SIZE ] ;
/* Design screen positions */
# define DESIGN_Y (59 + D_H) //the top left y value for all forms on the design screen
# define DES_TABBUTGAP 2
# define DES_TABBUTWIDTH 60
# define DES_TABBUTHEIGHT 46
# define DES_LEFTFORMX RET_X
# define DES_LEFTFORMY DESIGN_Y
# define DES_LEFTFORMWIDTH RET_FORMWIDTH
2013-05-21 11:48:17 -07:00
# define DES_LEFTFORMHEIGHT 273
2007-06-28 10:47:08 -07:00
# define DES_LEFTFORMBUTX 2
# define DES_LEFTFORMBUTY 2
# define DES_CENTERFORMWIDTH 315
# define DES_CENTERFORMHEIGHT 262
# define DES_CENTERFORMX POW_X
# define DES_CENTERFORMY DESIGN_Y
# define DES_3DVIEWX 8
# define DES_3DVIEWY 25
# define DES_3DVIEWWIDTH 236
# define DES_3DVIEWHEIGHT 192
# define DES_STATSFORMX POW_X
# define DES_STATSFORMY (DES_CENTERFORMY + DES_CENTERFORMHEIGHT + 3)
# define DES_STATSFORMWIDTH DES_CENTERFORMWIDTH
# define DES_STATSFORMHEIGHT 100
# define DES_PARTFORMX DES_3DVIEWX + DES_3DVIEWWIDTH + 2
# define DES_PARTFORMY DES_3DVIEWY
# define DES_PARTFORMHEIGHT DES_3DVIEWHEIGHT
# define DES_POWERFORMX DES_3DVIEWX
# define DES_POWERFORMY (DES_3DVIEWY + DES_3DVIEWHEIGHT + 2)
# define DES_POWERFORMWIDTH (DES_CENTERFORMWIDTH - 2*DES_POWERFORMX)
# define DES_POWERFORMHEIGHT 40
# define DES_RIGHTFORMWIDTH (RET_FORMWIDTH + 20)
# define DES_RIGHTFORMHEIGHT DES_LEFTFORMHEIGHT
# define DES_RIGHTFORMBUTX 2
# define DES_RIGHTFORMBUTY 2
# define DES_BARFORMX 6
# define DES_BARFORMY 6
# define DES_BARFORMWIDTH 300
# define DES_BARFORMHEIGHT 85
# define DES_NAMEBOXX DES_3DVIEWX
# define DES_NAMEBOXY 6
# define DES_NAMEBOXWIDTH DES_CENTERFORMWIDTH - 2*DES_NAMEBOXX
# define DES_NAMEBOXHEIGHT 14
/* The central boxes on the design screen */
# define DES_COMPBUTWIDTH 150
# define DES_COMPBUTHEIGHT 85
# define DES_POWERX 1
# define DES_POWERY 6
# define DES_POWERSEPARATIONX 4
# define DES_POWERSEPARATIONY 2
# define DES_PARTSEPARATIONX 6
# define DES_PARTSEPARATIONY 6
/* Positions of stuff on the clickable boxes (Design screen) */
# define DES_CLICKBARX 154
# define DES_CLICKBARY 7
# define DES_CLICKBARWIDTH 140
# define DES_CLICKBARHEIGHT 11
# define DES_CLICKGAP 9
# define DES_CLICKBARNAMEX 126
# define DES_CLICKBARNAMEWIDTH 20
# define DES_CLICKBARNAMEHEIGHT 19
# define DES_CLICKBARMAJORRED 255 //0xcc
# define DES_CLICKBARMAJORGREEN 235 //0
# define DES_CLICKBARMAJORBLUE 19 //0
# define DES_CLICKBARMINORRED 0x55
# define DES_CLICKBARMINORGREEN 0
# define DES_CLICKBARMINORBLUE 0
# define DES_WEAPONBUTTON_X 26
# define DES_SYSTEMBUTTON_X 68
# define DES_SYSTEMBUTTON_Y 10
// Stat bar y positions.
# define DES_STATBAR_Y1 (DES_CLICKBARY)
# define DES_STATBAR_Y2 (DES_CLICKBARY+DES_CLICKBARHEIGHT + DES_CLICKGAP)
# define DES_STATBAR_Y3 (DES_CLICKBARY+(DES_CLICKBARHEIGHT + DES_CLICKGAP)*2)
# define DES_STATBAR_Y4 (DES_CLICKBARY+(DES_CLICKBARHEIGHT + DES_CLICKGAP)*3)
/* the widget screen */
extern W_SCREEN * psWScreen ;
/* default droid design template */
2013-05-09 14:17:05 -07:00
static DROID_TEMPLATE sDefaultDesignTemplate ;
2007-06-28 10:47:08 -07:00
2011-12-29 08:13:04 -08:00
static void desSetupDesignTemplates ( ) ;
static void setDesignPauseState ( ) ;
static void resetDesignPauseState ( ) ;
2013-03-10 06:29:28 -07:00
static bool intAddTemplateButtons ( ListTabWidget * templList , DROID_TEMPLATE * psSelected ) ;
2013-02-26 01:45:50 -08:00
static void intDisplayDesignForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset ) ;
2007-06-28 10:47:08 -07:00
/* Set the current mode of the design screen, and display the appropriate component lists */
2013-05-21 11:48:17 -07:00
static void intSetDesignMode ( DES_COMPMODE newCompMode , bool forceRefresh = false ) ;
2007-06-28 10:47:08 -07:00
/* Set all the design bar graphs from a design template */
static void intSetDesignStats ( DROID_TEMPLATE * psTemplate ) ;
/* Set up the system clickable form of the design screen given a set of stats */
2011-03-12 17:32:15 -08:00
static bool intSetSystemForm ( COMPONENT_STATS * psStats ) ;
2007-06-28 10:47:08 -07:00
/* Set up the propulsion clickable form of the design screen given a set of stats */
2011-03-12 17:32:15 -08:00
static bool intSetPropulsionForm ( PROPULSION_STATS * psStats ) ;
2007-06-28 10:47:08 -07:00
/* Add the component tab form to the design screen */
2013-03-10 06:29:28 -07:00
static ListTabWidget * intAddComponentForm ( ) ;
2007-06-28 10:47:08 -07:00
/* Add the template tab form to the design screen */
2011-03-12 17:32:15 -08:00
static bool intAddTemplateForm ( DROID_TEMPLATE * psSelected ) ;
2007-06-28 10:47:08 -07:00
/* Add the system buttons (weapons, command droid, etc) to the design screen */
2011-03-12 17:32:15 -08:00
static bool intAddSystemButtons ( DES_COMPMODE mode ) ;
2007-06-28 10:47:08 -07:00
/* Add the component buttons to the main tab of the system or component form */
2013-03-10 06:29:28 -07:00
static bool intAddComponentButtons ( ListTabWidget * compList , COMPONENT_STATS * psStats , unsigned size , UBYTE * aAvailable , unsigned numEntries , unsigned compID ) ;
2007-06-28 10:47:08 -07:00
/* Add the component buttons to the main tab of the component form */
2013-03-10 06:29:28 -07:00
static bool intAddExtraSystemButtons ( ListTabWidget * compList , unsigned sensorIndex , unsigned ecmIndex , unsigned constIndex , unsigned repairIndex , unsigned brainIndex ) ;
2007-06-28 10:47:08 -07:00
/* Set the bar graphs for the system clickable */
2008-07-11 08:37:46 -07:00
static void intSetSystemStats ( COMPONENT_STATS * psStats ) ;
2007-06-28 10:47:08 -07:00
/* Set the shadow bar graphs for the system clickable */
2008-07-11 08:37:46 -07:00
static void intSetSystemShadowStats ( COMPONENT_STATS * psStats ) ;
2007-06-28 10:47:08 -07:00
/* Set the bar graphs for the sensor stats */
static void intSetSensorStats ( SENSOR_STATS * psStats ) ;
/* Set the shadow bar graphs for the sensor stats */
static void intSetSensorShadowStats ( SENSOR_STATS * psStats ) ;
/* Set the bar graphs for the ECM stats */
static void intSetECMStats ( ECM_STATS * psStats ) ;
/* Set the shadow bar graphs for the ECM stats */
static void intSetECMShadowStats ( ECM_STATS * psStats ) ;
/* Set the bar graphs for the Repair stats */
static void intSetRepairStats ( REPAIR_STATS * psStats ) ;
/* Set the shadow bar graphs for the Repair stats */
static void intSetRepairShadowStats ( REPAIR_STATS * psStats ) ;
/* Set the bar graphs for the Constructor stats */
static void intSetConstructStats ( CONSTRUCT_STATS * psStats ) ;
/* Set the shadow bar graphs for the Constructor stats */
static void intSetConstructShadowStats ( CONSTRUCT_STATS * psStats ) ;
/* Set the bar graphs for the Weapon stats */
static void intSetWeaponStats ( WEAPON_STATS * psStats ) ;
/* Set the shadow bar graphs for the weapon stats */
static void intSetWeaponShadowStats ( WEAPON_STATS * psStats ) ;
/* Set the bar graphs for the Body stats */
static void intSetBodyStats ( BODY_STATS * psStats ) ;
/* Set the shadow bar graphs for the Body stats */
static void intSetBodyShadowStats ( BODY_STATS * psStats ) ;
/* Set the bar graphs for the Propulsion stats */
static void intSetPropulsionStats ( PROPULSION_STATS * psStats ) ;
/* Set the shadow bar graphs for the Propulsion stats */
static void intSetPropulsionShadowStats ( PROPULSION_STATS * psStats ) ;
/* Sets the Design Power Bar for a given Template */
static void intSetDesignPower ( DROID_TEMPLATE * psTemplate ) ;
/* Sets the Power shadow Bar for the current Template with new stat*/
2008-07-11 08:37:46 -07:00
static void intSetTemplatePowerShadowStats ( COMPONENT_STATS * psStats ) ;
2007-06-28 10:47:08 -07:00
/* Sets the Body Points Bar for a given Template */
static void intSetBodyPoints ( DROID_TEMPLATE * psTemplate ) ;
/* Sets the Body Points shadow Bar for the current Template with new stat*/
2008-07-11 08:37:46 -07:00
static void intSetTemplateBodyShadowStats ( COMPONENT_STATS * psStats ) ;
2009-12-30 20:45:51 -08:00
/* set flashing flag for button */
2013-02-02 13:47:48 -08:00
static void intSetButtonFlash ( UDWORD id , bool bFlash ) ;
2006-05-27 09:37:17 -07:00
/*Function to set the shadow bars for all the stats when the mouse is over
2007-06-28 10:47:08 -07:00
the Template buttons */
static void runTemplateShadowStats ( UDWORD id ) ;
2011-03-12 17:32:15 -08:00
static bool intCheckValidWeaponForProp ( void ) ;
2007-06-28 10:47:08 -07:00
2011-03-12 17:32:15 -08:00
static bool checkTemplateIsVtol ( DROID_TEMPLATE * psTemplate ) ;
2007-06-28 10:47:08 -07:00
2008-03-24 09:51:17 -07:00
/* save the current Template if valid. Return true if stored */
2011-02-13 09:57:25 -08:00
static bool saveTemplate ( ) ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
static void desCreateDefaultTemplate ( void ) ;
2007-06-28 10:47:08 -07:00
2011-12-18 03:20:48 -08:00
/**
* Updates the status of the stored template toggle button .
*
* @ param isStored If the template is stored or not .
*/
static void updateStoreButton ( bool isStored ) ;
2007-06-28 10:47:08 -07:00
/* The current name of the design */
2013-02-24 01:06:51 -08:00
static char aCurrName [ MAX_STR_LENGTH ] ;
2007-06-28 10:47:08 -07:00
/* Store a list of component stats pointers for the design screen */
extern UDWORD maxComponent ;
extern UDWORD numComponent ;
2008-07-11 08:37:46 -07:00
extern COMPONENT_STATS * * apsComponentList ;
2007-06-28 10:47:08 -07:00
extern UDWORD maxExtraSys ;
extern UDWORD numExtraSys ;
2008-07-11 08:37:46 -07:00
extern COMPONENT_STATS * * apsExtraSysList ;
2007-06-28 10:47:08 -07:00
/* The button id of the component that is in the design */
static UDWORD desCompID ;
static UDWORD droidTemplID ;
/* The current design being edited on the design screen */
2013-03-12 02:22:42 -07:00
static DROID_TEMPLATE sCurrDesign ;
static bool haveCurrentDesign = false ;
2007-06-28 10:47:08 -07:00
2013-02-26 01:45:50 -08:00
static void intDisplayStatForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset ) ;
static void intDisplayViewForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset ) ;
2007-06-28 10:47:08 -07:00
2011-03-12 17:32:15 -08:00
extern bool bRender3DOnly ;
2007-06-28 10:47:08 -07:00
/* Add the design widgets to the widget screen */
2013-05-21 11:48:17 -07:00
bool intAddDesign ( bool bShowCentreScreen )
2007-06-28 10:47:08 -07:00
{
W_FORMINIT sFormInit ;
W_LABINIT sLabInit ;
W_EDBINIT sEdInit ;
W_BUTINIT sButInit ;
W_BARINIT sBarInit ;
desSetupDesignTemplates ( ) ;
//set which states are to be paused while design screen is up
setDesignPauseState ( ) ;
2013-02-02 13:17:27 -08:00
if ( GetGameMode ( ) = = GS_NORMAL & & ! bMultiPlayer )
{
2011-03-12 17:32:15 -08:00
bool radOnScreen = radarOnScreen ;
2008-03-24 09:51:17 -07:00
bRender3DOnly = true ;
radarOnScreen = false ;
2013-02-02 13:17:27 -08:00
// Just display the 3d, no interface
2007-06-28 10:47:08 -07:00
displayWorld ( ) ;
radarOnScreen = radOnScreen ;
2008-03-24 09:51:17 -07:00
bRender3DOnly = false ;
2007-06-28 10:47:08 -07:00
}
2013-02-27 23:29:08 -08:00
WIDGET * parent = psWScreen - > psForm ;
2007-06-28 10:47:08 -07:00
/* Add the main design form */
2013-02-27 23:29:08 -08:00
IntFormAnimated * desForm = new IntFormAnimated ( parent , false ) ;
desForm - > id = IDDES_FORM ;
desForm - > setGeometry ( DES_CENTERFORMX , DES_CENTERFORMY , DES_CENTERFORMWIDTH , DES_CENTERFORMHEIGHT ) ;
2007-06-28 10:47:08 -07:00
/* add the edit name box */
sEdInit . formID = IDDES_FORM ;
sEdInit . id = IDDES_NAMEBOX ;
sEdInit . x = DES_NAMEBOXX ;
sEdInit . y = DES_NAMEBOXY ;
sEdInit . width = DES_NAMEBOXWIDTH ;
sEdInit . height = DES_NAMEBOXHEIGHT ;
2007-04-01 13:15:46 -07:00
sEdInit . pText = _ ( " New Vehicle " ) ;
2007-06-28 10:47:08 -07:00
sEdInit . pBoxDisplay = intDisplayEditBox ;
if ( ! widgAddEditBox ( psWScreen , & sEdInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2013-03-12 02:22:42 -07:00
haveCurrentDesign = false ;
2007-06-28 10:47:08 -07:00
/* Initialise the current design */
2013-05-09 14:17:05 -07:00
sDefaultDesignTemplate . droidType = DROID_ANY ;
2011-02-13 09:57:25 -08:00
sCurrDesign = sDefaultDesignTemplate ;
2011-12-18 03:20:48 -08:00
sCurrDesign . stored = false ;
2011-02-13 09:57:25 -08:00
sstrcpy ( aCurrName , _ ( " New Vehicle " ) ) ;
2013-05-12 14:50:57 -07:00
sCurrDesign . name = aCurrName ;
2007-06-28 10:47:08 -07:00
/* Add the design templates form */
2011-02-13 09:57:25 -08:00
if ( ! intAddTemplateForm ( NULL ) ) // Was psCurrTemplate instead of NULL, but psCurrTemplate was always NULL. Deleted psCurrTemplate, but leaving this here, in case intAddTemplateForm(NULL) does something useful.
2007-06-28 10:47:08 -07:00
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the 3D View form */
sFormInit . formID = IDDES_FORM ;
sFormInit . id = IDDES_3DVIEW ;
sFormInit . style = WFORM_PLAIN ;
sFormInit . x = DES_3DVIEWX ;
sFormInit . y = DES_3DVIEWY ;
sFormInit . width = DES_3DVIEWWIDTH ;
sFormInit . height = DES_3DVIEWHEIGHT ;
sFormInit . pDisplay = intDisplayViewForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the part button form */
sFormInit . formID = IDDES_FORM ;
sFormInit . id = IDDES_PARTFORM ;
sFormInit . style = WFORM_PLAIN ;
sFormInit . x = DES_PARTFORMX ;
sFormInit . y = DES_PARTFORMY ;
sFormInit . width = ( UWORD ) ( iV_GetImageWidth ( IntImages , IMAGE_DES_TURRET ) +
2013-02-02 13:47:48 -08:00
2 * DES_PARTSEPARATIONX ) ;
2007-06-28 10:47:08 -07:00
sFormInit . height = DES_PARTFORMHEIGHT ;
sFormInit . pDisplay = intDisplayDesignForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
// add the body part button
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_BODYBUTTON ;
sButInit . x = DES_PARTSEPARATIONX ;
sButInit . y = DES_PARTSEPARATIONY ;
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_BODY ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Vehicle Body " ) ;
2007-06-28 10:47:08 -07:00
sButInit . pDisplay = intDisplayButtonFlash ;
2007-11-09 13:01:23 -08:00
sButInit . UserData = PACKDWORD_TRI ( 1 , IMAGE_DES_BODYH , IMAGE_DES_BODY ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
// add the propulsion part button
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_PROPBUTTON ;
sButInit . x = DES_PARTSEPARATIONX ;
2006-05-27 09:37:17 -07:00
sButInit . y = ( UWORD ) ( iV_GetImageHeight ( IntImages , IMAGE_DES_PROPULSION ) +
2013-02-02 13:47:48 -08:00
2 * DES_PARTSEPARATIONY ) ;
2007-06-28 10:47:08 -07:00
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_PROPULSION ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_PROPULSION ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Vehicle Propulsion " ) ;
2007-06-28 10:47:08 -07:00
sButInit . pDisplay = intDisplayButtonFlash ;
2007-11-09 13:01:23 -08:00
sButInit . UserData = PACKDWORD_TRI ( 1 , IMAGE_DES_PROPULSIONH , IMAGE_DES_PROPULSION ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
// add the turret part button
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_SYSTEMBUTTON ;
sButInit . x = DES_PARTSEPARATIONX ;
sButInit . y = ( UWORD ) ( iV_GetImageHeight ( IntImages , IMAGE_DES_PROPULSION ) +
2013-02-02 13:47:48 -08:00
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
3 * DES_PARTSEPARATIONY ) ;
2007-06-28 10:47:08 -07:00
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_TURRET ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_TURRET ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Vehicle Turret " ) ;
2007-06-28 10:47:08 -07:00
sButInit . pDisplay = intDisplayButtonFlash ;
2007-11-09 13:01:23 -08:00
sButInit . UserData = PACKDWORD_TRI ( 1 , IMAGE_DES_TURRETH , IMAGE_DES_TURRET ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2009-05-21 19:41:13 -07:00
// add the turret_a button
2006-11-04 14:56:28 -08:00
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_WPABUTTON ;
sButInit . x = DES_PARTSEPARATIONX ;
2009-05-21 19:41:13 -07:00
// use BODY height for now
2006-11-04 14:56:28 -08:00
sButInit . y = ( UWORD ) ( iV_GetImageHeight ( IntImages , IMAGE_DES_PROPULSION ) +
2013-02-02 13:47:48 -08:00
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
4 * DES_PARTSEPARATIONY ) ;
2006-11-04 14:56:28 -08:00
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_TURRET ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_TURRET ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Vehicle Turret " ) ;
2006-11-04 14:56:28 -08:00
sButInit . pDisplay = intDisplayButtonFlash ;
2007-11-09 13:01:23 -08:00
sButInit . UserData = PACKDWORD_TRI ( 1 , IMAGE_DES_TURRETH , IMAGE_DES_TURRET ) ;
2006-11-04 14:56:28 -08:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2006-11-04 14:56:28 -08:00
}
2009-05-21 19:41:13 -07:00
// add the turret_b button
2006-11-04 14:56:28 -08:00
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_WPBBUTTON ;
sButInit . x = DES_PARTSEPARATIONX ;
2009-05-21 19:41:13 -07:00
//use body height for now
2006-11-04 14:56:28 -08:00
sButInit . y = ( UWORD ) ( iV_GetImageHeight ( IntImages , IMAGE_DES_PROPULSION ) +
2013-02-02 13:47:48 -08:00
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
iV_GetImageHeight ( IntImages , IMAGE_DES_BODY ) +
5 * DES_PARTSEPARATIONY ) ;
2006-11-04 14:56:28 -08:00
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_TURRET ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_TURRET ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Vehicle Turret " ) ;
2006-11-04 14:56:28 -08:00
sButInit . pDisplay = intDisplayButtonFlash ;
2007-11-09 13:01:23 -08:00
sButInit . UserData = PACKDWORD_TRI ( 1 , IMAGE_DES_TURRETH , IMAGE_DES_TURRET ) ;
2006-11-04 14:56:28 -08:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2006-11-04 14:56:28 -08:00
}
2007-06-28 10:47:08 -07:00
/* add the delete button */
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_BIN ;
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_BIN ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_BIN ) ;
sButInit . x = DES_PARTSEPARATIONX ;
sButInit . y = ( UWORD ) ( DES_PARTFORMHEIGHT - sButInit . height - DES_PARTSEPARATIONY ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Delete Design " ) ;
2007-06-28 10:47:08 -07:00
sButInit . pDisplay = intDisplayButtonHilight ;
2013-02-02 13:47:48 -08:00
sButInit . UserData = PACKDWORD_TRI ( 0 , IMAGE_DES_BINH , IMAGE_DES_BIN ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2011-12-18 03:20:48 -08:00
// Add the store template button
sButInit . formID = IDDES_PARTFORM ;
sButInit . id = IDDES_STOREBUTTON ;
sButInit . style = WBUT_PLAIN ;
2011-12-18 13:32:09 -08:00
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_SAVE ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_SAVE ) ;
2011-12-18 03:20:48 -08:00
sButInit . x = DES_PARTSEPARATIONX ;
2013-02-02 13:47:48 -08:00
sButInit . y = DES_PARTFORMHEIGHT - 2 * sButInit . height - 2 * DES_PARTSEPARATIONY ;
2011-12-18 13:36:04 -08:00
sButInit . pTip = _ ( " Store Template " ) ;
2011-12-18 03:20:48 -08:00
sButInit . FontID = font_regular ;
sButInit . pDisplay = intDisplayButtonHilight ;
2011-12-18 13:32:09 -08:00
sButInit . UserData = PACKDWORD_TRI ( 0 , IMAGE_DES_SAVEH , IMAGE_DES_SAVE ) ;
2011-12-18 03:20:48 -08:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
return false ;
}
2007-06-28 10:47:08 -07:00
/* add central stats form */
2013-02-27 23:29:08 -08:00
IntFormAnimated * statsForm = new IntFormAnimated ( parent , false ) ;
statsForm - > id = IDDES_STATSFORM ;
statsForm - > setGeometry ( DES_STATSFORMX , DES_STATSFORMY , DES_STATSFORMWIDTH , DES_STATSFORMHEIGHT ) ;
2007-06-28 10:47:08 -07:00
/* Add the body form */
sFormInit . formID = IDDES_STATSFORM ;
sFormInit . id = IDDES_BODYFORM ;
sFormInit . style = WFORM_CLICKABLE | WFORM_NOCLICKMOVE ;
sFormInit . width = DES_BARFORMWIDTH ;
sFormInit . height = DES_BARFORMHEIGHT ;
sFormInit . x = DES_BARFORMX ;
sFormInit . y = DES_BARFORMY ;
sFormInit . pDisplay = intDisplayStatForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the graphs for the Body */
sBarInit . formID = IDDES_BODYFORM ;
sBarInit . id = IDDES_BODYARMOUR_K ;
sBarInit . x = DES_CLICKBARX ;
sBarInit . y = DES_STATBAR_Y1 ; //DES_CLICKBARY;
sBarInit . width = DES_CLICKBARWIDTH ;
sBarInit . height = DES_CLICKBARHEIGHT ;
sBarInit . size = 50 ;
2007-12-09 08:09:23 -08:00
sBarInit . sCol . byte . r = DES_CLICKBARMAJORRED ;
sBarInit . sCol . byte . g = DES_CLICKBARMAJORGREEN ;
sBarInit . sCol . byte . b = DES_CLICKBARMAJORBLUE ;
sBarInit . sMinorCol . byte . r = DES_CLICKBARMINORRED ;
sBarInit . sMinorCol . byte . g = DES_CLICKBARMINORGREEN ;
sBarInit . sMinorCol . byte . b = DES_CLICKBARMINORBLUE ;
2007-06-28 10:47:08 -07:00
sBarInit . pDisplay = intDisplayStatsBar ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Kinetic Armour " ) ;
2011-11-20 14:10:23 -08:00
sBarInit . iRange = getMaxBodyArmour ( ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_BODYARMOUR_H ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Thermal Armour " ) ;
2011-11-20 14:10:23 -08:00
sBarInit . iRange = getMaxBodyArmour ( ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_BODYPOWER ;
sBarInit . y = DES_STATBAR_Y3 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Engine Output " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxBodyPower ( ) ; //DBAR_BODYMAXPOWER;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_BODYWEIGHT ;
sBarInit . y = DES_STATBAR_Y4 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
2006-05-27 09:37:17 -07:00
2007-06-28 10:47:08 -07:00
/* Add the labels for the Body */
sLabInit . formID = IDDES_BODYFORM ;
sLabInit . id = IDDES_BODYARMOURKLAB ;
sLabInit . x = DES_CLICKBARNAMEX ;
2013-02-02 13:47:48 -08:00
sLabInit . y = DES_CLICKBARY - DES_CLICKBARHEIGHT / 3 ;
2007-06-28 10:47:08 -07:00
sLabInit . width = DES_CLICKBARNAMEWIDTH ;
sLabInit . height = DES_CLICKBARHEIGHT ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Kinetic Armour " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2007-11-30 09:01:34 -08:00
//just to confuse things even more - the graphics were named incorrectly!
2011-11-20 14:10:23 -08:00
sLabInit . UserData = IMAGE_DES_ARMOUR_EXPLOSIVE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_BODYARMOURHLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Thermal Armour " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2011-11-20 14:10:23 -08:00
sLabInit . UserData = IMAGE_DES_ARMOUR_KINETIC ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_BODYPOWERLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Engine Output " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_POWER ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_BODYWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* add power/points bar subform */
2010-12-22 06:02:14 -08:00
sFormInit = W_FORMINIT ( ) ;
2007-06-28 10:47:08 -07:00
sFormInit . formID = IDDES_FORM ;
sFormInit . id = IDDES_POWERFORM ;
sFormInit . style = WFORM_PLAIN ;
sFormInit . x = DES_POWERFORMX ;
sFormInit . y = DES_POWERFORMY ;
sFormInit . width = DES_POWERFORMWIDTH ;
sFormInit . height = DES_POWERFORMHEIGHT ;
sFormInit . pDisplay = intDisplayDesignForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the design template power bar and label*/
sLabInit . formID = IDDES_POWERFORM ;
sLabInit . id = IDDES_TEMPPOWERLAB ;
sLabInit . x = DES_POWERX ;
sLabInit . y = DES_POWERY ;
2007-12-28 13:38:27 -08:00
sLabInit . pTip = _ ( " Total Power Required " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_POWER ;
2013-02-25 15:24:53 -08:00
widgAddLabel ( psWScreen , & sLabInit ) ;
2007-06-28 10:47:08 -07:00
2010-12-22 06:02:14 -08:00
sBarInit = W_BARINIT ( ) ;
2007-06-28 10:47:08 -07:00
sBarInit . formID = IDDES_POWERFORM ;
sBarInit . id = IDDES_POWERBAR ;
sBarInit . x = ( SWORD ) ( DES_POWERX + DES_POWERSEPARATIONX +
2013-02-02 13:47:48 -08:00
iV_GetImageWidth ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
2007-06-28 10:47:08 -07:00
sBarInit . y = DES_POWERY ;
sBarInit . width = ( SWORD ) ( DES_POWERFORMWIDTH - 15 -
2013-02-02 13:47:48 -08:00
iV_GetImageWidth ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
sBarInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_POWERBACK ) ;
2007-06-28 10:47:08 -07:00
sBarInit . pDisplay = intDisplayDesignPowerBar ; //intDisplayStatsBar;
2007-12-28 13:38:27 -08:00
sBarInit . pTip = _ ( " Total Power Required " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = DBAR_TEMPLATEMAXPOWER ; //WBAR_SCALE;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the design template body points bar and label*/
sLabInit . formID = IDDES_POWERFORM ;
sLabInit . id = IDDES_TEMPBODYLAB ;
sLabInit . x = DES_POWERX ;
sLabInit . y = ( SWORD ) ( DES_POWERY + DES_POWERSEPARATIONY +
2013-02-02 13:47:48 -08:00
iV_GetImageHeight ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Total Body Points " ) ;
2007-06-28 10:47:08 -07:00
sLabInit . pDisplay = intDisplayImage ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_BODYPOINTS ;
2013-02-25 15:24:53 -08:00
widgAddLabel ( psWScreen , & sLabInit ) ;
2007-06-28 10:47:08 -07:00
2010-12-22 06:02:14 -08:00
sBarInit = W_BARINIT ( ) ;
2007-06-28 10:47:08 -07:00
sBarInit . formID = IDDES_POWERFORM ;
sBarInit . id = IDDES_BODYPOINTS ;
sBarInit . x = ( SWORD ) ( DES_POWERX + DES_POWERSEPARATIONX +
2013-02-02 13:47:48 -08:00
iV_GetImageWidth ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
2007-06-28 10:47:08 -07:00
sBarInit . y = ( SWORD ) ( DES_POWERY + DES_POWERSEPARATIONY + 4 +
2013-02-02 13:47:48 -08:00
iV_GetImageHeight ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
2007-06-28 10:47:08 -07:00
sBarInit . width = ( SWORD ) ( DES_POWERFORMWIDTH - 15 -
2013-02-02 13:47:48 -08:00
iV_GetImageWidth ( IntImages , IMAGE_DES_BODYPOINTS ) ) ;
sBarInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_POWERBACK ) ;
2007-06-28 10:47:08 -07:00
sBarInit . pDisplay = intDisplayDesignPowerBar ; //intDisplayStatsBar;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Total Body Points " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = DBAR_TEMPLATEMAXPOINTS ; //(UWORD)getMaxBodyPoints();//DBAR_BODYMAXPOINTS;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the variable bits of the design screen and set the bar graphs */
desCompMode = IDES_NOCOMPONENT ;
desSysMode = IDES_NOSYSTEM ;
desPropMode = IDES_NOPROPULSION ;
intSetDesignStats ( & sCurrDesign ) ;
intSetBodyPoints ( & sCurrDesign ) ;
intSetDesignPower ( & sCurrDesign ) ;
intSetDesignMode ( IDES_BODY ) ;
/* hide design and component forms until required */
2013-02-27 23:29:08 -08:00
desForm - > show ( bShowCentreScreen ) ;
statsForm - > hide ( ) ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_RIGHTBASE ) ;
2007-06-28 10:47:08 -07:00
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* set up droid templates before going into design screen */
2010-02-25 11:46:27 -08:00
void desSetupDesignTemplates ( void )
2007-06-28 10:47:08 -07:00
{
/* init template list */
2011-02-13 09:57:25 -08:00
apsTemplateList . clear ( ) ;
apsTemplateList . push_back ( & sDefaultDesignTemplate ) ;
for ( std : : list < DROID_TEMPLATE > : : iterator i = localTemplates . begin ( ) ; i ! = localTemplates . end ( ) ; + + i )
2007-06-28 10:47:08 -07:00
{
2011-02-13 09:57:25 -08:00
DROID_TEMPLATE * psTempl = & * i ; // &* changes iterators into pointers.
2007-06-28 10:47:08 -07:00
/* add template to list if not a transporter,
2006-11-04 14:56:28 -08:00
* cyborg , person or command droid ,
2007-06-28 10:47:08 -07:00
*/
2011-02-13 09:57:25 -08:00
if ( psTempl - > droidType ! = DROID_TRANSPORTER & &
2013-02-02 13:47:48 -08:00
psTempl - > droidType ! = DROID_SUPERTRANSPORTER & &
2011-02-13 09:57:25 -08:00
psTempl - > droidType ! = DROID_CYBORG & &
psTempl - > droidType ! = DROID_CYBORG_SUPER & &
psTempl - > droidType ! = DROID_CYBORG_CONSTRUCT & &
psTempl - > droidType ! = DROID_CYBORG_REPAIR & &
2011-12-18 03:20:48 -08:00
psTempl - > droidType ! = DROID_PERSON & &
2013-05-21 11:48:17 -07:00
researchedTemplate ( psTempl , selectedPlayer , includeRedundantDesigns ) )
2007-06-28 10:47:08 -07:00
{
2011-02-13 09:57:25 -08:00
apsTemplateList . push_back ( psTempl ) ;
2007-06-28 10:47:08 -07:00
}
}
}
/* Add the design template form */
2013-05-21 11:48:17 -07:00
static bool intAddTemplateForm ( DROID_TEMPLATE * psSelected )
2007-06-28 10:47:08 -07:00
{
2013-02-27 23:29:08 -08:00
WIDGET * parent = psWScreen - > psForm ;
2007-06-28 10:47:08 -07:00
/* add a form to place the tabbed form on */
2013-02-27 23:29:08 -08:00
IntFormAnimated * templbaseForm = new IntFormAnimated ( parent , false ) ;
templbaseForm - > id = IDDES_TEMPLBASE ;
2013-05-21 11:48:17 -07:00
templbaseForm - > setGeometry ( RET_X , DESIGN_Y , RET_FORMWIDTH , DES_LEFTFORMHEIGHT ) ;
// Add the obsolete items button.
makeObsoleteButton ( templbaseForm ) ;
2007-06-28 10:47:08 -07:00
/* Add the design templates form */
2013-03-10 06:29:28 -07:00
IntListTabWidget * templList = new IntListTabWidget ( templbaseForm ) ;
templList - > setChildSize ( DES_TABBUTWIDTH , DES_TABBUTHEIGHT ) ;
templList - > setChildSpacing ( DES_TABBUTGAP , DES_TABBUTGAP ) ;
int templListWidth = OBJ_BUTWIDTH * 2 + DES_TABBUTGAP ;
2013-05-21 11:48:17 -07:00
templList - > setGeometry ( ( RET_FORMWIDTH - templListWidth ) / 2 , 18 , templListWidth , templbaseForm - > height ( ) - 18 ) ;
2007-06-28 10:47:08 -07:00
/* Put the buttons on it */
2013-03-10 06:29:28 -07:00
return intAddTemplateButtons ( templList , psSelected ) ;
2007-06-28 10:47:08 -07:00
}
/* Add the droid template buttons to a form */
2013-03-10 06:29:28 -07:00
static bool intAddTemplateButtons ( ListTabWidget * templList , DROID_TEMPLATE * psSelected )
2007-06-28 10:47:08 -07:00
{
DROID_TEMPLATE * psTempl = NULL ;
char TempString [ 256 ] ;
/* Set up the button struct */
2013-03-10 06:29:28 -07:00
int nextButtonId = IDDES_TEMPLSTART ;
2007-06-28 10:47:08 -07:00
/* Add each button */
2010-12-22 06:02:14 -08:00
W_BARINIT sBarInit ;
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_BARSTART ;
sBarInit . x = STAT_TIMEBARX ;
sBarInit . y = STAT_TIMEBARY ;
sBarInit . width = STAT_PROGBARWIDTH ;
sBarInit . height = STAT_PROGBARHEIGHT ;
sBarInit . size = 50 ;
2010-04-04 04:46:51 -07:00
sBarInit . sCol = WZCOL_ACTION_PROGRESS_BAR_MAJOR ;
sBarInit . sMinorCol = WZCOL_ACTION_PROGRESS_BAR_MINOR ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Power Usage " ) ;
2007-06-28 10:47:08 -07:00
droidTemplID = 0 ;
2011-02-13 09:57:25 -08:00
for ( unsigned i = 0 ; i < apsTemplateList . size ( ) ; + + i )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
psTempl = apsTemplateList [ i ] ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
/* Set the tip and add the button */
2013-03-13 00:57:13 -07:00
IntStatsButton * button = new IntStatsButton ( templList ) ;
2013-03-10 06:29:28 -07:00
button - > id = nextButtonId ;
2013-03-13 00:57:13 -07:00
button - > setStatsAndTip ( psTempl ) ;
2013-03-10 06:29:28 -07:00
templList - > addWidgetToLayout ( button ) ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
sBarInit . iRange = POWERPOINTS_DROIDDIV ;
2013-05-08 09:47:58 -07:00
sBarInit . size = calcTemplatePower ( psTempl ) / POWERPOINTS_DROIDDIV ;
2013-02-02 13:47:48 -08:00
if ( sBarInit . size > WBAR_SCALE )
{
sBarInit . size = WBAR_SCALE ;
}
2007-06-28 10:47:08 -07:00
2013-05-08 09:47:58 -07:00
ssprintf ( TempString , " %s - %d " , _ ( " Power Usage " ) , calcTemplatePower ( psTempl ) ) ;
2013-03-10 06:29:28 -07:00
sBarInit . pTip = TempString ;
sBarInit . formID = nextButtonId ;
2013-02-02 13:47:48 -08:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
return false ;
}
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
/* if the current template matches psSelected lock the button */
if ( psTempl = = psSelected )
{
2013-03-10 06:29:28 -07:00
droidTemplID = nextButtonId ;
button - > setState ( WBUT_LOCK ) ;
templList - > setCurrentPage ( templList - > pages ( ) - 1 ) ;
2013-02-02 13:47:48 -08:00
}
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
/* Update the init struct for the next button */
sBarInit . id + = 1 ;
2013-03-10 06:29:28 -07:00
+ + nextButtonId ;
2013-02-02 13:47:48 -08:00
//check don't go over max templates that can fit on the form
2013-03-10 06:29:28 -07:00
if ( nextButtonId > = IDDES_TEMPLEND )
2013-02-02 13:47:48 -08:00
{
break ;
}
2007-06-28 10:47:08 -07:00
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Set the current mode of the design screen, and display the appropriate
* component lists
2009-05-21 19:41:13 -07:00
* added case IDES_TURRET_A , IDES_TURRET_B
2007-06-28 10:47:08 -07:00
*/
2013-05-21 11:48:17 -07:00
static void intSetDesignMode ( DES_COMPMODE newCompMode , bool forceRefresh )
2007-06-28 10:47:08 -07:00
{
UDWORD weaponIndex ;
2013-05-21 11:48:17 -07:00
if ( newCompMode = = desCompMode & & ! forceRefresh )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:17:27 -08:00
return ;
}
2013-02-02 13:47:48 -08:00
/* Have to change the component display - remove the old one */
if ( desCompMode ! = IDES_NOCOMPONENT )
{
widgDelete ( psWScreen , IDDES_RIGHTBASE ) ;
2010-01-16 14:17:22 -08:00
2013-02-02 13:47:48 -08:00
widgSetButtonState ( psWScreen , IDDES_BODYFORM , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_PROPFORM , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , 0 ) ;
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
2010-01-16 14:17:22 -08:00
2013-02-02 13:47:48 -08:00
widgSetButtonState ( psWScreen , IDDES_BODYBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_PROPBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPBBUTTON , 0 ) ;
}
2010-01-16 14:17:22 -08:00
2013-03-10 06:29:28 -07:00
ListTabWidget * compList ;
2013-02-02 13:47:48 -08:00
/* Set up the display for the new mode */
desCompMode = newCompMode ;
switch ( desCompMode )
{
case IDES_NOCOMPONENT :
/* Nothing to display */
break ;
case IDES_SYSTEM :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
intAddExtraSystemButtons ( compList ,
sCurrDesign . asParts [ COMP_SENSOR ] ,
2013-02-02 13:47:48 -08:00
sCurrDesign . asParts [ COMP_ECM ] ,
sCurrDesign . asParts [ COMP_CONSTRUCT ] ,
sCurrDesign . asParts [ COMP_REPAIRUNIT ] ,
sCurrDesign . asParts [ COMP_BRAIN ] ) ;
intAddSystemButtons ( IDES_SYSTEM ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMBUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
break ;
case IDES_TURRET :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
2013-02-02 13:47:48 -08:00
weaponIndex = ( sCurrDesign . numWeaps > 0 ) ? sCurrDesign . asWeaps [ 0 ] : 0 ;
2013-03-10 06:29:28 -07:00
intAddComponentButtons ( compList , asWeaponStats , sizeof ( * asWeaponStats ) , apCompLists [ selectedPlayer ] [ COMP_WEAPON ] , numWeaponStats , weaponIndex ) ;
2013-02-02 13:47:48 -08:00
intAddSystemButtons ( IDES_TURRET ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMBUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
intSetSystemForm ( ( COMPONENT_STATS * ) ( asWeaponStats + sCurrDesign . asWeaps [ 0 ] ) ) ; // in case previous was a different slot
break ;
case IDES_BODY :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
intAddComponentButtons ( compList , asBodyStats , sizeof ( * asBodyStats ) , apCompLists [ selectedPlayer ] [ COMP_BODY ] , numBodyStats , sCurrDesign . asParts [ COMP_BODY ] ) ;
2013-02-02 13:47:48 -08:00
widgSetButtonState ( psWScreen , IDDES_BODYFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_BODYBUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_BODYFORM ) ;
break ;
case IDES_PROPULSION :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
intAddComponentButtons ( compList , asPropulsionStats , sizeof ( * asPropulsionStats ) , apCompLists [ selectedPlayer ] [ COMP_PROPULSION ] , numPropulsionStats , sCurrDesign . asParts [ COMP_PROPULSION ] ) ;
2013-02-02 13:47:48 -08:00
widgSetButtonState ( psWScreen , IDDES_PROPFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_PROPBUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_PROPFORM ) ;
break ;
case IDES_TURRET_A :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
2013-02-02 13:47:48 -08:00
weaponIndex = ( sCurrDesign . numWeaps > 1 ) ? sCurrDesign . asWeaps [ 1 ] : 0 ;
2013-03-10 06:29:28 -07:00
intAddComponentButtons ( compList , asWeaponStats , sizeof ( * asWeaponStats ) , apCompLists [ selectedPlayer ] [ COMP_WEAPON ] , numWeaponStats , weaponIndex ) ;
2013-02-02 13:47:48 -08:00
intAddSystemButtons ( IDES_TURRET_A ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
intSetSystemForm ( ( COMPONENT_STATS * ) ( asWeaponStats + sCurrDesign . asWeaps [ 1 ] ) ) ; // in case previous was a different slot
// Stop the button flashing
intSetButtonFlash ( IDDES_WPABUTTON , false ) ;
break ;
case IDES_TURRET_B :
2013-03-10 06:29:28 -07:00
compList = intAddComponentForm ( ) ;
2013-02-02 13:47:48 -08:00
weaponIndex = ( sCurrDesign . numWeaps > 2 ) ? sCurrDesign . asWeaps [ 2 ] : 0 ;
2013-03-10 06:29:28 -07:00
intAddComponentButtons ( compList , asWeaponStats , sizeof ( * asWeaponStats ) , apCompLists [ selectedPlayer ] [ COMP_WEAPON ] , numWeaponStats , weaponIndex ) ;
2013-02-02 13:47:48 -08:00
intAddSystemButtons ( IDES_TURRET_B ) ;
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , WBUT_LOCK ) ;
widgSetButtonState ( psWScreen , IDDES_WPBBUTTON , WBUT_CLICKLOCK ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
intSetSystemForm ( ( COMPONENT_STATS * ) ( asWeaponStats + sCurrDesign . asWeaps [ 2 ] ) ) ; // in case previous was a different slot
// Stop the button flashing
intSetButtonFlash ( IDDES_WPBBUTTON , false ) ;
break ;
}
2007-06-28 10:47:08 -07:00
}
2008-07-11 08:37:46 -07:00
static COMPONENT_STATS *
2013-02-02 13:47:48 -08:00
intChooseSystemStats ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2008-07-11 08:37:46 -07:00
COMPONENT_STATS * psStats = NULL ;
2010-06-27 12:12:18 -07:00
int compIndex ;
2007-06-28 10:47:08 -07:00
// Choose correct system stats
switch ( droidTemplateType ( psTemplate ) )
{
case DROID_COMMAND :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_BRAIN ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numBrainStats , " Invalid range referenced for numBrainStats, %d > %d " , compIndex , numBrainStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asBrainStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_SENSOR :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_SENSOR ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numSensorStats , " Invalid range referenced for numSensorStats, %d > %d " , compIndex , numSensorStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asSensorStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_ECM :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_ECM ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numECMStats , " Invalid range referenced for numECMStats, %d > %d " , compIndex , numECMStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asECMStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_CONSTRUCT :
case DROID_CYBORG_CONSTRUCT :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_CONSTRUCT ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numConstructStats , " Invalid range referenced for numConstructStats, %d > %d " , compIndex , numConstructStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asConstructStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_REPAIR :
case DROID_CYBORG_REPAIR :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_REPAIRUNIT ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numRepairStats , " Invalid range referenced for numRepairStats, %d > %d " , compIndex , numRepairStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asRepairStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_WEAPON :
case DROID_PERSON :
case DROID_CYBORG :
case DROID_CYBORG_SUPER :
case DROID_DEFAULT :
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asWeaps [ 0 ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( NULL , compIndex < numWeaponStats , " Invalid range referenced for numWeaponStats, %d > %d " , compIndex , numWeaponStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asWeaponStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
default :
2013-02-02 13:47:48 -08:00
debug ( LOG_ERROR , " unrecognised droid type " ) ;
2007-06-28 10:47:08 -07:00
return NULL ;
}
return psStats ;
}
2008-05-10 06:20:23 -07:00
const char * GetDefaultTemplateName ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2013-02-24 01:06:51 -08:00
// NOTE: At this time, savegames can support a max of 60. We are using MAX_STR_LENGTH (currently 256) for display
2009-05-15 12:02:55 -07:00
// We are also returning a truncated string, instead of NULL if the string is too long.
2008-07-11 08:37:46 -07:00
COMPONENT_STATS * psStats = NULL ;
2010-06-27 12:12:18 -07:00
int compIndex ;
2007-06-03 06:46:50 -07:00
2007-06-28 10:47:08 -07:00
/*
First we check for the special cases of the Transporter & Cyborgs
*/
2013-02-02 13:47:48 -08:00
if ( psTemplate - > droidType = = DROID_TRANSPORTER )
2007-06-28 10:47:08 -07:00
{
2011-01-18 09:51:42 -08:00
sstrcpy ( aCurrName , _ ( " Transport " ) ) ;
return aCurrName ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
if ( psTemplate - > droidType = = DROID_SUPERTRANSPORTER )
2012-02-25 16:21:29 -08:00
{
sstrcpy ( aCurrName , _ ( " Super Transport " ) ) ;
return aCurrName ;
}
2007-06-03 06:46:50 -07:00
2007-06-28 10:47:08 -07:00
/*
Now get the normal default droid name based on its components
*/
2007-06-03 06:46:50 -07:00
aCurrName [ 0 ] = ' \0 ' ; // Reset string to null
2013-02-02 13:47:48 -08:00
psStats = intChooseSystemStats ( psTemplate ) ;
if ( psTemplate - > asWeaps [ 0 ] ! = 0 | |
psTemplate - > asParts [ COMP_CONSTRUCT ] ! = 0 | |
psTemplate - > asParts [ COMP_SENSOR ] ! = 0 | |
psTemplate - > asParts [ COMP_ECM ] ! = 0 | |
psTemplate - > asParts [ COMP_REPAIRUNIT ] ! = 0 | |
psTemplate - > asParts [ COMP_BRAIN ] ! = 0 )
{
2013-05-12 14:50:57 -07:00
sstrcpy ( aCurrName , getName ( psStats ) ) ;
2008-04-30 10:26:38 -07:00
sstrcat ( aCurrName , " " ) ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
if ( psTemplate - > numWeaps > 1 )
2006-11-04 14:56:28 -08:00
{
2009-05-01 01:47:42 -07:00
sstrcat ( aCurrName , _ ( " Hydra " ) ) ;
2006-11-04 14:56:28 -08:00
}
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_BODY ] ;
2011-01-18 09:51:42 -08:00
ASSERT_OR_RETURN ( " " , compIndex < numBodyStats , " Invalid range referenced for numBodyStats, %d > %d " , compIndex , numBodyStats ) ;
2013-02-02 13:47:48 -08:00
psStats = ( COMPONENT_STATS * ) ( asBodyStats + compIndex ) ;
if ( psTemplate - > asParts [ COMP_BODY ] ! = 0 )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
if ( strlen ( aCurrName ) + psStats - > name . size ( ) > MAX_STR_LENGTH )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
debug ( LOG_ERROR , " Name string too long %s+%s > %u " , aCurrName , getName ( psStats ) , MAX_STR_LENGTH ) ;
2009-05-15 12:02:55 -07:00
debug ( LOG_ERROR , " Please report what language you are using in the bug report! " ) ;
2007-06-28 10:47:08 -07:00
}
2013-05-12 14:50:57 -07:00
sstrcat ( aCurrName , getName ( psStats ) ) ;
2008-04-30 10:26:38 -07:00
sstrcat ( aCurrName , " " ) ;
2007-06-28 10:47:08 -07:00
}
2010-06-27 12:12:18 -07:00
compIndex = psTemplate - > asParts [ COMP_PROPULSION ] ;
2011-01-18 09:51:42 -08:00
ASSERT_OR_RETURN ( " " , compIndex < numPropulsionStats , " Invalid range referenced for numPropulsionStats, %d > %d " , compIndex , numPropulsionStats ) ;
2013-02-02 13:47:48 -08:00
psStats = ( COMPONENT_STATS * ) ( asPropulsionStats + compIndex ) ;
if ( psTemplate - > asParts [ COMP_PROPULSION ] ! = 0 )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
if ( strlen ( aCurrName ) + psStats - > name . size ( ) > MAX_STR_LENGTH )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
debug ( LOG_ERROR , " Name string too long %s+%s " , aCurrName , getName ( psStats ) ) ;
2009-05-15 12:02:55 -07:00
debug ( LOG_ERROR , " Please report what language you are using in the bug report! " ) ;
2007-06-28 10:47:08 -07:00
}
2013-05-12 14:50:57 -07:00
sstrcat ( aCurrName , getName ( psStats ) ) ;
2007-06-28 10:47:08 -07:00
}
return aCurrName ;
}
2013-02-02 13:47:48 -08:00
static void intSetEditBoxTextFromTemplate ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2008-04-30 10:26:38 -07:00
sstrcpy ( aCurrName , " " ) ;
2007-06-28 10:47:08 -07:00
/* show component names if default template else show stat name */
2013-02-02 13:47:48 -08:00
if ( psTemplate - > droidType ! = DROID_DEFAULT )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
sstrcpy ( aCurrName , getName ( psTemplate ) ) ;
2007-06-28 10:47:08 -07:00
}
else
{
2011-01-18 09:51:42 -08:00
GetDefaultTemplateName ( psTemplate ) ; // sets aCurrName
2007-06-28 10:47:08 -07:00
}
2006-05-27 09:37:17 -07:00
2007-06-28 10:47:08 -07:00
widgSetString ( psWScreen , IDDES_NAMEBOX , aCurrName ) ;
}
/* Set all the design bar graphs from a design template */
2013-02-02 13:47:48 -08:00
static void intSetDesignStats ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
COMPONENT_STATS * psStats = intChooseSystemStats ( psTemplate ) ;
2007-06-28 10:47:08 -07:00
/* Set system stats */
2013-02-02 13:47:48 -08:00
intSetSystemForm ( psStats ) ;
2007-06-28 10:47:08 -07:00
/* Set the body stats */
intSetBodyStats ( asBodyStats + psTemplate - > asParts [ COMP_BODY ] ) ;
/* Set the propulsion stats */
intSetPropulsionForm ( asPropulsionStats + psTemplate - > asParts [ COMP_PROPULSION ] ) ;
/* Set the name in the edit box */
2013-02-02 13:47:48 -08:00
intSetEditBoxTextFromTemplate ( psTemplate ) ;
2007-06-28 10:47:08 -07:00
}
/* Set up the system clickable form of the design screen given a set of stats */
2013-05-21 11:48:17 -07:00
static bool intSetSystemForm ( COMPONENT_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
DES_SYSMODE newSysMode = ( DES_SYSMODE ) 0 ;
2007-06-28 10:47:08 -07:00
/* Figure out what the new mode should be */
2013-05-13 13:20:49 -07:00
switch ( psStats - > compType )
2007-06-28 10:47:08 -07:00
{
case COMP_WEAPON :
newSysMode = IDES_WEAPON ;
break ;
case COMP_SENSOR :
newSysMode = IDES_SENSOR ;
break ;
case COMP_ECM :
newSysMode = IDES_ECM ;
break ;
case COMP_CONSTRUCT :
newSysMode = IDES_CONSTRUCT ;
break ;
case COMP_BRAIN :
newSysMode = IDES_COMMAND ;
break ;
case COMP_REPAIRUNIT :
newSysMode = IDES_REPAIR ;
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2007-06-28 10:47:08 -07:00
}
/* If the correct form is already displayed just set the stats */
if ( newSysMode = = desSysMode )
{
intSetSystemStats ( psStats ) ;
2006-05-27 09:37:17 -07:00
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Remove the old form if necessary */
if ( desSysMode ! = IDES_NOSYSTEM )
{
widgDelete ( psWScreen , IDDES_SYSTEMFORM ) ;
}
/* Set the new mode */
desSysMode = newSysMode ;
/* Add the system form */
2010-12-22 06:02:14 -08:00
W_FORMINIT sFormInit ;
2007-06-28 10:47:08 -07:00
sFormInit . formID = IDDES_STATSFORM ;
sFormInit . id = IDDES_SYSTEMFORM ;
sFormInit . style = ( WFORM_CLICKABLE | WFORM_NOCLICKMOVE ) ;
sFormInit . x = DES_BARFORMX ;
sFormInit . y = DES_BARFORMY ;
sFormInit . width = DES_BARFORMWIDTH ; //COMPBUTWIDTH;
sFormInit . height = DES_BARFORMHEIGHT ; //COMPBUTHEIGHT;
2013-05-13 14:11:34 -07:00
sFormInit . pTip = psStats - > name ; /* set form tip to stats string */
2007-06-28 10:47:08 -07:00
sFormInit . pUserData = psStats ; /* store component stats */
sFormInit . pDisplay = intDisplayStatForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Initialise the bargraph struct */
2010-12-22 06:02:14 -08:00
W_BARINIT sBarInit ;
2007-06-28 10:47:08 -07:00
sBarInit . formID = IDDES_SYSTEMFORM ;
2010-12-22 06:02:14 -08:00
//sBarInit.style = WBAR_DOUBLE;
2007-06-28 10:47:08 -07:00
sBarInit . x = DES_CLICKBARX ;
sBarInit . y = DES_STATBAR_Y1 ; //DES_CLICKBARY;
sBarInit . width = DES_CLICKBARWIDTH ;
sBarInit . height = DES_CLICKBARHEIGHT ;
2007-12-09 08:09:23 -08:00
sBarInit . sCol . byte . r = DES_CLICKBARMAJORRED ;
sBarInit . sCol . byte . g = DES_CLICKBARMAJORGREEN ;
sBarInit . sCol . byte . b = DES_CLICKBARMAJORBLUE ;
sBarInit . sMinorCol . byte . r = DES_CLICKBARMINORRED ;
sBarInit . sMinorCol . byte . g = DES_CLICKBARMINORGREEN ;
sBarInit . sMinorCol . byte . b = DES_CLICKBARMINORBLUE ;
2007-06-28 10:47:08 -07:00
sBarInit . pDisplay = intDisplayStatsBar ;
/* Initialise the label struct */
2010-12-22 06:02:14 -08:00
W_LABINIT sLabInit ;
2007-06-28 10:47:08 -07:00
sLabInit . formID = IDDES_SYSTEMFORM ;
sLabInit . x = DES_CLICKBARNAMEX ;
2013-02-02 13:47:48 -08:00
sLabInit . y = DES_CLICKBARY - DES_CLICKBARHEIGHT / 3 ;
2007-06-28 10:47:08 -07:00
sLabInit . width = DES_CLICKBARNAMEWIDTH ;
sLabInit . height = DES_CLICKBARHEIGHT ;
2010-12-22 06:02:14 -08:00
sLabInit . pDisplay = intDisplayImage ;
2007-06-28 10:47:08 -07:00
/* See what type of system stats we've got */
2013-02-02 13:17:27 -08:00
if ( psStats - > ref > = REF_SENSOR_START & & psStats - > ref < REF_SENSOR_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
2006-05-27 09:37:17 -07:00
/* Add the bar graphs*/
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_SENSORRANGE ;
sBarInit . iRange = ( UWORD ) getMaxSensorRange ( ) ; //DBAR_SENSORMAXRANGE;
2010-12-18 11:01:09 -08:00
sBarInit . pTip = _ ( " Sensor Range " ) ;
sBarInit . denominator = TILE_UNITS ;
sBarInit . precision = 1 ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2010-12-18 11:01:09 -08:00
sBarInit . denominator = 0 ;
sBarInit . precision = 0 ;
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_SENSORPOWER ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2011-01-17 12:23:17 -08:00
sBarInit . iRange = ( UDWORD ) getMaxSensorRange ( ) ; // FIXME: Remove
2010-12-18 11:01:09 -08:00
sBarInit . pTip = _ ( " Sensor Power " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_SENSORWEIGHT ;
sBarInit . y = DES_STATBAR_Y3 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
2010-12-18 11:01:09 -08:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_SENSORRANGELAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Sensor Range " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_RANGE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_SENSORPOWERLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Sensor Power " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_POWER ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_SENSORWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-02 13:17:27 -08:00
else if ( psStats - > ref > = REF_ECM_START & & psStats - > ref < REF_ECM_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
/* Add the bar graphs */
sBarInit . id = IDDES_ECMPOWER ;
2011-01-17 12:23:17 -08:00
sBarInit . iRange = ( UWORD ) getMaxECMRange ( ) ;
2010-12-18 11:01:09 -08:00
sBarInit . pTip = _ ( " ECM Power " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_ECMWEIGHT ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
2010-12-18 11:01:09 -08:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_ECMPOWERLAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " ECM Power " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_POWER ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_ECMWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-02 13:17:27 -08:00
else if ( psStats - > ref > = REF_CONSTRUCT_START & & psStats - > ref < REF_CONSTRUCT_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
/* Add the bar graphs */
sBarInit . id = IDDES_CONSTPOINTS ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Build Points " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxConstPoints ( ) ; //DBAR_CONSTMAXPOINTS;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_CONSTWEIGHT ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_CONSTPOINTSLAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Build Points " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_BUILDRATE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_CONSTWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-02 13:17:27 -08:00
else if ( psStats - > ref > = REF_REPAIR_START & & psStats - > ref < REF_REPAIR_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
/* Add the bar graphs */
sBarInit . id = IDDES_REPAIRPOINTS ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Build Points " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxRepairPoints ( ) ; //DBAR_REPAIRMAXPOINTS;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_REPAIRWEIGHT ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_REPAIRPTLAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Build Points " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_BUILDRATE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_REPAIRWGTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-02 13:17:27 -08:00
else if ( psStats - > ref > = REF_WEAPON_START & & psStats - > ref < REF_WEAPON_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
/* Add the bar graphs */
sBarInit . id = IDDES_WEAPRANGE ;
sBarInit . iRange = ( UWORD ) getMaxWeaponRange ( ) ; //DBAR_WEAPMAXRANGE;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Range " ) ;
2010-12-18 11:01:09 -08:00
sBarInit . denominator = TILE_UNITS ;
sBarInit . precision = 1 ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2010-12-22 06:02:14 -08:00
sBarInit . denominator = 1 ;
2010-12-18 11:01:09 -08:00
sBarInit . precision = 0 ;
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_WEAPDAMAGE ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit . iRange = ( UWORD ) getMaxWeaponDamage ( ) ; //DBAR_WEAPMAXDAMAGE;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Damage " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_WEAPROF ;
sBarInit . y = DES_STATBAR_Y3 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-03-17 17:07:57 -07:00
sBarInit . iRange = getMaxWeaponROF ( ) ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Rate-of-Fire " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_WEAPWEIGHT ;
sBarInit . y = DES_STATBAR_Y4 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_WEAPRANGELAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Range " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_RANGE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_WEAPDAMAGELAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Damage " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_DAMAGE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_WEAPROFLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Rate-of-Fire " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_FIRERATE ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_WEAPWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
}
// Add the correct component form
switch ( desSysMode )
{
case IDES_SENSOR :
case IDES_CONSTRUCT :
case IDES_ECM :
case IDES_REPAIR :
case IDES_COMMAND :
intSetDesignMode ( IDES_SYSTEM ) ;
break ;
case IDES_WEAPON :
intSetDesignMode ( IDES_TURRET ) ;
break ;
default :
break ;
}
/* Set the stats */
intSetSystemStats ( psStats ) ;
/* Lock the form down if necessary */
2013-02-02 13:47:48 -08:00
if ( desCompMode = = IDES_SYSTEM )
2007-06-28 10:47:08 -07:00
{
widgSetButtonState ( psWScreen , IDDES_SYSTEMFORM , WBUT_LOCK ) ;
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Set up the propulsion clickable form of the design screen given a set of stats */
2011-03-12 17:32:15 -08:00
static bool intSetPropulsionForm ( PROPULSION_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
DES_PROPMODE newPropMode = ( DES_PROPMODE ) 0 ;
2007-06-28 10:47:08 -07:00
2009-05-21 19:41:13 -07:00
ASSERT_OR_RETURN ( false , psStats ! = NULL , " Invalid propulsion stats pointer " ) ;
2007-06-28 10:47:08 -07:00
/* figure out what the new mode should be */
switch ( asPropulsionTypes [ psStats - > propulsionType ] . travel )
{
case GROUND :
newPropMode = IDES_GROUND ;
break ;
case AIR :
newPropMode = IDES_AIR ;
break ;
}
/* If the mode hasn't changed, just set the stats */
if ( desPropMode = = newPropMode )
{
intSetPropulsionStats ( psStats ) ;
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Remove the old form if necessary */
if ( desPropMode ! = IDES_NOPROPULSION )
{
widgDelete ( psWScreen , IDDES_PROPFORM ) ;
}
/* Set the new mode */
desPropMode = newPropMode ;
/* Add the propulsion form */
2010-12-22 06:02:14 -08:00
W_FORMINIT sFormInit ;
2007-06-28 10:47:08 -07:00
sFormInit . formID = IDDES_STATSFORM ;
sFormInit . id = IDDES_PROPFORM ;
sFormInit . style = WFORM_CLICKABLE | WFORM_NOCLICKMOVE ;
sFormInit . x = DES_BARFORMX ;
sFormInit . y = DES_BARFORMY ;
sFormInit . width = DES_BARFORMWIDTH ; //DES_COMPBUTWIDTH;
sFormInit . height = DES_BARFORMHEIGHT ; //DES_COMPBUTHEIGHT;
2013-05-13 14:11:34 -07:00
sFormInit . pTip = psStats - > name ; /* set form tip to stats string */
2007-06-28 10:47:08 -07:00
sFormInit . pDisplay = intDisplayStatForm ;
if ( ! widgAddForm ( psWScreen , & sFormInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Initialise the bargraph struct */
2010-12-22 06:02:14 -08:00
W_BARINIT sBarInit ;
2007-06-28 10:47:08 -07:00
sBarInit . formID = IDDES_PROPFORM ;
2010-12-22 06:02:14 -08:00
//sBarInit.style = WBAR_DOUBLE;
2007-06-28 10:47:08 -07:00
sBarInit . x = DES_CLICKBARX ;
sBarInit . y = DES_STATBAR_Y1 ; //DES_CLICKBARY;
sBarInit . width = DES_CLICKBARWIDTH ;
sBarInit . height = DES_CLICKBARHEIGHT ;
2007-12-09 08:09:23 -08:00
sBarInit . sCol . byte . r = DES_CLICKBARMAJORRED ;
sBarInit . sCol . byte . g = DES_CLICKBARMAJORGREEN ;
sBarInit . sCol . byte . b = DES_CLICKBARMAJORBLUE ;
sBarInit . sMinorCol . byte . r = DES_CLICKBARMINORRED ;
sBarInit . sMinorCol . byte . g = DES_CLICKBARMINORGREEN ;
sBarInit . sMinorCol . byte . b = DES_CLICKBARMINORBLUE ;
2007-06-28 10:47:08 -07:00
sBarInit . pDisplay = intDisplayStatsBar ;
/* Initialise the label struct */
2010-12-22 06:02:14 -08:00
W_LABINIT sLabInit ;
2007-06-28 10:47:08 -07:00
sLabInit . formID = IDDES_PROPFORM ;
sLabInit . x = DES_CLICKBARNAMEX ;
2013-02-02 13:47:48 -08:00
sLabInit . y = DES_CLICKBARY - DES_CLICKBARHEIGHT / 3 ;
2007-06-28 10:47:08 -07:00
sLabInit . width = DES_CLICKBARNAMEWIDTH ;
sLabInit . height = DES_CLICKBARNAMEHEIGHT ; //DES_CLICKBARHEIGHT;
2010-12-22 06:02:14 -08:00
sLabInit . pDisplay = intDisplayImage ;
2007-06-28 10:47:08 -07:00
/* See what type of propulsion we've got */
switch ( desPropMode )
{
case IDES_AIR :
/* Add the bar graphs */
sBarInit . id = IDDES_PROPAIR ;
sBarInit . iRange = ( UWORD ) getMaxPropulsionSpeed ( ) ; //DBAR_PROPMAXSPEED;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Air Speed " ) ;
2010-12-18 11:01:09 -08:00
sBarInit . denominator = TILE_UNITS ;
sBarInit . precision = 2 ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2010-12-22 06:02:14 -08:00
sBarInit . denominator = 1 ;
2010-12-18 11:01:09 -08:00
sBarInit . precision = 0 ;
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_PROPWEIGHT ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_PROPAIRLAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Air Speed " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_HOVER ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_PROPWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
break ;
case IDES_GROUND :
/* Add the bar graphs */
sBarInit . id = IDDES_PROPROAD ;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Road Speed " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxPropulsionSpeed ( ) ; //DBAR_PROPMAXSPEED;
2010-12-18 11:01:09 -08:00
sBarInit . denominator = TILE_UNITS ;
sBarInit . precision = 2 ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_PROPCOUNTRY ;
sBarInit . y = DES_STATBAR_Y2 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Off-Road Speed " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxPropulsionSpeed ( ) ; //DBAR_PROPMAXSPEED;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sBarInit . id = IDDES_PROPWATER ;
sBarInit . y = DES_STATBAR_Y3 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Water Speed " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxPropulsionSpeed ( ) ; //DBAR_PROPMAXSPEED;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2010-12-22 06:02:14 -08:00
sBarInit . denominator = 1 ;
2010-12-18 11:01:09 -08:00
sBarInit . precision = 0 ;
2007-06-28 10:47:08 -07:00
sBarInit . id = IDDES_PROPWEIGHT ;
sBarInit . y = DES_STATBAR_Y4 ; //+= DES_CLICKBARHEIGHT + DES_CLICKGAP;
2007-04-01 13:15:46 -07:00
sBarInit . pTip = _ ( " Weight " ) ;
2007-06-28 10:47:08 -07:00
sBarInit . iRange = ( UWORD ) getMaxComponentWeight ( ) ; //DBAR_MAXWEIGHT;
if ( ! widgAddBarGraph ( psWScreen , & sBarInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Add the labels */
sLabInit . id = IDDES_PROPROADLAB ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Road Speed " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_ROAD ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_PROPCOUNTRYLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Off-Road Speed " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_CROSSCOUNTRY ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_PROPWATERLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Water Speed " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_HOVER ; //WATER;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
sLabInit . id = IDDES_PROPWEIGHTLAB ;
sLabInit . y + = DES_CLICKBARHEIGHT + DES_CLICKGAP ;
2007-04-01 13:15:46 -07:00
sLabInit . pTip = _ ( " Weight " ) ;
2007-11-09 13:01:23 -08:00
sLabInit . UserData = IMAGE_DES_WEIGHT ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddLabel ( psWScreen , & sLabInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
break ;
default :
break ;
}
/* Set the stats */
intSetPropulsionStats ( psStats ) ;
/* Lock the form down if necessary */
if ( desCompMode = = IDES_PROPULSION )
{
widgSetButtonState ( psWScreen , IDDES_PROPFORM , WBUT_LOCK ) ;
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Add the component tab form to the design screen */
2013-03-10 06:29:28 -07:00
static ListTabWidget * intAddComponentForm ( )
2007-06-28 10:47:08 -07:00
{
2013-02-27 23:29:08 -08:00
WIDGET * parent = psWScreen - > psForm ;
2007-06-28 10:47:08 -07:00
/* add a form to place the tabbed form on */
2013-02-27 23:29:08 -08:00
IntFormAnimated * rightBase = new IntFormAnimated ( parent , false ) ;
rightBase - > id = IDDES_RIGHTBASE ;
2013-05-21 11:48:17 -07:00
rightBase - > setGeometry ( RADTLX - 2 , DESIGN_Y , RET_FORMWIDTH , DES_RIGHTFORMHEIGHT ) ;
2012-02-11 03:24:24 -08:00
2007-06-28 10:47:08 -07:00
//now a single form
2013-03-10 06:29:28 -07:00
IntListTabWidget * compList = new IntListTabWidget ( rightBase ) ;
compList - > setChildSize ( DES_TABBUTWIDTH , DES_TABBUTHEIGHT ) ;
compList - > setChildSpacing ( DES_TABBUTGAP , DES_TABBUTGAP ) ;
int objListWidth = DES_TABBUTWIDTH * 2 + DES_TABBUTGAP ;
compList - > setGeometry ( ( rightBase - > width ( ) - objListWidth ) / 2 , 40 , objListWidth , rightBase - > height ( ) - 40 ) ;
return compList ;
2007-06-28 10:47:08 -07:00
}
/* Add the system buttons (weapons, command droid, etc) to the design screen */
2011-03-12 17:32:15 -08:00
static bool intAddSystemButtons ( DES_COMPMODE mode )
2007-06-28 10:47:08 -07:00
{
// add the weapon button
2010-12-22 06:02:14 -08:00
W_BUTINIT sButInit ;
2007-06-28 10:47:08 -07:00
sButInit . formID = IDDES_RIGHTBASE ;
sButInit . id = IDDES_WEAPONS ;
sButInit . x = DES_WEAPONBUTTON_X ;
sButInit . y = DES_SYSTEMBUTTON_Y ;
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_WEAPONS ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_WEAPONS ) ;
2007-04-01 13:15:46 -07:00
sButInit . pTip = _ ( " Weapons " ) ;
2007-06-28 10:47:08 -07:00
sButInit . pDisplay = intDisplayButtonHilight ;
2013-02-02 13:47:48 -08:00
sButInit . UserData = PACKDWORD_TRI ( 0 , IMAGE_DES_EXTRAHI , IMAGE_DES_WEAPONS ) ;
2007-06-28 10:47:08 -07:00
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:17:27 -08:00
// if currently got a VTOL proplusion attached then don't add the system buttons
// dont add the system button if mode is IDES_TURRET_A or IDES_TURRET_B
if ( ! checkTemplateIsVtol ( & sCurrDesign ) & & mode ! = IDES_TURRET_A & & mode ! = IDES_TURRET_B )
{
2013-02-02 13:47:48 -08:00
// add the system button
sButInit . formID = IDDES_RIGHTBASE ;
sButInit . id = IDDES_SYSTEMS ;
sButInit . x = DES_SYSTEMBUTTON_X ;
sButInit . y = DES_SYSTEMBUTTON_Y ;
sButInit . width = iV_GetImageWidth ( IntImages , IMAGE_DES_SYSTEMS ) ;
sButInit . height = iV_GetImageHeight ( IntImages , IMAGE_DES_SYSTEMS ) ;
sButInit . pTip = _ ( " Systems " ) ;
sButInit . pDisplay = intDisplayButtonHilight ;
sButInit . UserData = PACKDWORD_TRI ( 0 , IMAGE_DES_EXTRAHI , IMAGE_DES_SYSTEMS ) ;
if ( ! widgAddButton ( psWScreen , & sButInit ) )
{
return false ;
}
if ( mode = = IDES_SYSTEM )
{
widgSetButtonState ( psWScreen , IDDES_SYSTEMS , WBUT_LOCK ) ;
}
2013-02-02 13:17:27 -08:00
}
2007-06-28 10:47:08 -07:00
// lock down the correct button
switch ( mode )
{
2013-02-02 13:47:48 -08:00
case IDES_TURRET :
case IDES_TURRET_A :
case IDES_TURRET_B :
widgSetButtonState ( psWScreen , IDDES_WEAPONS , WBUT_LOCK ) ;
break ;
case IDES_SYSTEM :
break ;
default :
ASSERT ( ! " invalid/unexpected mode " , " unexpected mode " ) ;
break ;
2007-06-28 10:47:08 -07:00
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Add the component buttons to the main tab of the component form */
2013-03-10 06:29:28 -07:00
static bool intAddComponentButtons ( ListTabWidget * compList , COMPONENT_STATS * psStats , unsigned size , UBYTE * aAvailable , unsigned numEntries , unsigned compID )
2007-06-28 10:47:08 -07:00
{
UDWORD i , maxComponents ;
2008-07-11 08:37:46 -07:00
COMPONENT_STATS * psCurrStats ;
2007-06-28 10:47:08 -07:00
PROPULSION_STATS * psPropStats ;
2011-12-28 05:37:48 -08:00
bool bVTol , bWeapon ;
int bodysize = SIZE_NUM ;
2007-06-28 10:47:08 -07:00
/* Set up the button struct */
2013-03-10 06:29:28 -07:00
int nextButtonId = IDDES_COMPSTART ;
2007-06-28 10:47:08 -07:00
//need to set max number of buttons possible
2013-02-02 13:47:48 -08:00
if ( psStats - > ref > = REF_WEAPON_START & & psStats - > ref < REF_WEAPON_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
maxComponents = MAX_SYSTEM_COMPONENTS ;
}
else
{
maxComponents = MAX_DESIGN_COMPONENTS ;
}
/*if adding weapons - need to check if the propulsion is a VTOL*/
2008-03-24 09:51:17 -07:00
bVTol = false ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:17:27 -08:00
if ( psStats - > ref > = REF_WEAPON_START & & psStats - > ref < REF_WEAPON_START + REF_RANGE )
2007-06-28 10:47:08 -07:00
{
2008-03-24 09:51:17 -07:00
bWeapon = true ;
2007-06-28 10:47:08 -07:00
}
else
{
2008-03-24 09:51:17 -07:00
bWeapon = false ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
if ( bWeapon )
2007-06-28 10:47:08 -07:00
{
//check if the current Template propulsion has been set
if ( sCurrDesign . asParts [ COMP_PROPULSION ] )
{
psPropStats = asPropulsionStats + sCurrDesign .
2013-02-02 13:47:48 -08:00
asParts [ COMP_PROPULSION ] ;
2009-05-21 19:41:13 -07:00
ASSERT_OR_RETURN ( false , psPropStats ! = NULL , " invalid propulsion stats pointer " ) ;
2007-06-28 10:47:08 -07:00
if ( asPropulsionTypes [ psPropStats - > propulsionType ] . travel = = AIR )
{
2008-03-24 09:51:17 -07:00
bVTol = true ;
2007-06-28 10:47:08 -07:00
}
}
2011-12-28 05:37:48 -08:00
if ( sCurrDesign . asParts [ COMP_BODY ] )
{
bodysize = ( asBodyStats + sCurrDesign . asParts [ COMP_BODY ] ) - > size ;
}
2007-06-28 10:47:08 -07:00
}
/* Add each button */
desCompID = 0 ;
numComponent = 0 ;
psCurrStats = psStats ;
2013-02-02 13:47:48 -08:00
for ( i = 0 ; i < numEntries ; i + + )
2007-06-28 10:47:08 -07:00
{
/* If we are out of space in the list - stop */
if ( numComponent > = maxComponents )
{
break ;
}
/* Skip unavailable entries and non-design ones*/
2013-05-21 11:48:17 -07:00
if ( ! ( aAvailable [ i ] = = AVAILABLE | | ( includeRedundantDesigns & & aAvailable [ i ] = = REDUNDANT ) ) | | ! psCurrStats - > designable )
2007-06-28 10:47:08 -07:00
{
/* Update the stats pointer for the next button */
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) ( ( ( UBYTE * ) psCurrStats ) + size ) ;
2007-06-28 10:47:08 -07:00
continue ;
}
/*skip indirect weapons if VTOL propulsion or numVTOLattackRuns for the weapon is zero*/
2013-02-02 13:47:48 -08:00
if ( bWeapon )
2007-06-28 10:47:08 -07:00
{
2011-12-28 05:37:48 -08:00
WEAPON_STATS * psWeapon = ( WEAPON_STATS * ) psCurrStats ;
if ( ( psWeapon - > vtolAttackRuns > 0 ) ! = bVTol
| | ( psWeapon - > weaponSize = = WEAPON_SIZE_LIGHT & & bodysize ! = SIZE_LIGHT )
| | ( psWeapon - > weaponSize = = WEAPON_SIZE_HEAVY & & bodysize = = SIZE_LIGHT ) )
2007-06-28 10:47:08 -07:00
{
/* Update the stats pointer for the next button */
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) ( ( ( UBYTE * ) psCurrStats ) + size ) ;
2007-06-28 10:47:08 -07:00
continue ;
}
}
/* Set the tip and add the button */
2013-03-13 00:57:13 -07:00
IntStatsButton * button = new IntStatsButton ( compList ) ;
2013-03-10 06:29:28 -07:00
button - > id = nextButtonId ;
2013-03-13 00:57:13 -07:00
button - > setStatsAndTip ( psCurrStats ) ;
2013-03-10 06:29:28 -07:00
compList - > addWidgetToLayout ( button ) ;
2007-06-28 10:47:08 -07:00
/* Store the stat pointer in the list */
apsComponentList [ numComponent + + ] = psCurrStats ;
/* If this matches the component ID lock the button */
if ( i = = compID )
{
2013-03-10 06:29:28 -07:00
desCompID = nextButtonId ;
button - > setState ( WBUT_LOCK ) ;
compList - > setCurrentPage ( compList - > pages ( ) - 1 ) ;
2007-06-28 10:47:08 -07:00
}
// if this is a command droid that is in use or dead - make it unavailable
2013-05-13 13:20:49 -07:00
if ( psCurrStats - > compType = = COMP_BRAIN )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
if ( ( ( ( COMMAND_DROID * ) psCurrStats ) - > psDroid ! = NULL ) | |
( ( COMMAND_DROID * ) psCurrStats ) - > died )
2007-06-28 10:47:08 -07:00
{
2013-03-10 06:29:28 -07:00
button - > setState ( WBUT_DISABLE ) ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-13 01:11:10 -08:00
/* Update the init struct for the next button */
2013-03-10 06:29:28 -07:00
+ + nextButtonId ;
2007-06-28 10:47:08 -07:00
/* Update the stats pointer for the next button */
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) ( ( ( UBYTE * ) psCurrStats ) + size ) ;
2007-06-28 10:47:08 -07:00
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Add the component buttons to the main tab of the component form */
2013-03-10 06:29:28 -07:00
static bool intAddExtraSystemButtons ( ListTabWidget * compList , unsigned sensorIndex , unsigned ecmIndex , unsigned constIndex , unsigned repairIndex , unsigned brainIndex )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
UDWORD i , buttonType , size = 0 ;
UDWORD compIndex = 0 , numStats = 0 ;
COMPONENT_STATS * psCurrStats = 0 ;
UBYTE * aAvailable = 0 ;
2007-06-28 10:47:08 -07:00
// Set up the button struct
2013-03-10 06:29:28 -07:00
int nextButtonId = IDDES_EXTRASYSSTART ;
2007-06-28 10:47:08 -07:00
// Add the buttons :
// buttonType == 0 - Sensor Buttons
// buttonType == 1 - ECM Buttons
// buttonType == 2 - Constructor Buttons
// buttonType == 3 - Repair Buttons
// buttonType == 4 - Brain Buttons
numExtraSys = 0 ;
2013-02-02 13:47:48 -08:00
for ( buttonType = 0 ; buttonType < 5 ; buttonType + + )
2007-06-28 10:47:08 -07:00
{
switch ( buttonType )
{
case 0 :
// Sensor Buttons
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) asSensorStats ;
2007-06-28 10:47:08 -07:00
size = sizeof ( SENSOR_STATS ) ;
aAvailable = apCompLists [ selectedPlayer ] [ COMP_SENSOR ] ;
numStats = numSensorStats ;
compIndex = sensorIndex ;
break ;
case 1 :
// ECM Buttons
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) asECMStats ;
2007-06-28 10:47:08 -07:00
size = sizeof ( ECM_STATS ) ;
aAvailable = apCompLists [ selectedPlayer ] [ COMP_ECM ] ;
numStats = numECMStats ;
compIndex = ecmIndex ;
break ;
case 2 :
// Constructor Buttons
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) asConstructStats ;
2007-06-28 10:47:08 -07:00
size = sizeof ( CONSTRUCT_STATS ) ;
aAvailable = apCompLists [ selectedPlayer ] [ COMP_CONSTRUCT ] ;
numStats = numConstructStats ;
compIndex = constIndex ;
break ;
case 3 :
// Repair Buttons
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) asRepairStats ;
2007-06-28 10:47:08 -07:00
size = sizeof ( REPAIR_STATS ) ;
aAvailable = apCompLists [ selectedPlayer ] [ COMP_REPAIRUNIT ] ;
numStats = numRepairStats ;
compIndex = repairIndex ;
break ;
case 4 :
2008-02-16 14:00:13 -08:00
// Brain Buttons
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) asBrainStats ;
2007-06-28 10:47:08 -07:00
size = sizeof ( BRAIN_STATS ) ;
aAvailable = apCompLists [ selectedPlayer ] [ COMP_BRAIN ] ;
numStats = numBrainStats ;
compIndex = brainIndex ;
break ;
}
2013-02-02 13:47:48 -08:00
for ( i = 0 ; i < numStats ; i + + )
2007-06-28 10:47:08 -07:00
{
// If we are out of space in the list - stop
if ( numExtraSys > = MAXEXTRASYS )
{
2013-02-02 13:47:48 -08:00
ASSERT ( false , " Too many components for the list " ) ;
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
// Skip unavailable entries or non-design ones
2013-05-21 11:48:17 -07:00
if ( ! ( aAvailable [ i ] = = AVAILABLE | | ( includeRedundantDesigns & & aAvailable [ i ] = = REDUNDANT ) ) | | ! psCurrStats - > designable )
2007-06-28 10:47:08 -07:00
{
// Update the stats pointer for the next button
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) ( ( ( UBYTE * ) psCurrStats ) + size ) ;
2007-06-28 10:47:08 -07:00
continue ;
}
// Set the tip and add the button
2013-03-13 00:57:13 -07:00
IntStatsButton * button = new IntStatsButton ( compList ) ;
2013-03-10 06:29:28 -07:00
button - > id = nextButtonId ;
2013-03-13 00:57:13 -07:00
button - > setStatsAndTip ( psCurrStats ) ;
2013-03-10 06:29:28 -07:00
compList - > addWidgetToLayout ( button ) ;
2007-11-30 09:01:34 -08:00
2007-06-28 10:47:08 -07:00
//just use one set of buffers for mixed system form
2013-05-13 13:20:49 -07:00
if ( psCurrStats - > compType = = COMP_BRAIN )
2007-06-28 10:47:08 -07:00
{
2013-03-13 00:57:13 -07:00
button - > setStats ( ( ( BRAIN_STATS * ) psCurrStats ) - > psWeaponStat ) ;
2007-06-28 10:47:08 -07:00
}
2006-05-27 09:37:17 -07:00
// Store the stat pointer in the list
2007-06-28 10:47:08 -07:00
apsExtraSysList [ numExtraSys + + ] = psCurrStats ;
2006-05-27 09:37:17 -07:00
// If this matches the sensorIndex note the form and button
2007-06-28 10:47:08 -07:00
if ( i = = compIndex )
{
2013-03-10 06:29:28 -07:00
desCompID = nextButtonId ;
button - > setState ( WBUT_LOCK ) ;
compList - > setCurrentPage ( compList - > pages ( ) - 1 ) ;
2007-06-28 10:47:08 -07:00
}
// Update the init struct for the next button
2013-03-10 06:29:28 -07:00
+ + nextButtonId ;
2007-06-28 10:47:08 -07:00
2006-05-27 09:37:17 -07:00
// Update the stats pointer for the next button
2008-07-11 08:37:46 -07:00
psCurrStats = ( COMPONENT_STATS * ) ( ( ( UBYTE * ) psCurrStats ) + size ) ;
2007-06-28 10:47:08 -07:00
}
}
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
/* Set the bar graphs for the system clickable */
2008-07-11 08:37:46 -07:00
static void intSetSystemStats ( COMPONENT_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
2007-06-03 06:46:50 -07:00
W_FORM * psForm ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
2007-06-28 10:47:08 -07:00
/* set form tip to stats string */
2013-05-13 14:11:34 -07:00
widgSetTip ( psWScreen , IDDES_SYSTEMFORM , psStats - > name ) ;
2007-06-28 10:47:08 -07:00
/* set form stats for later display in intDisplayStatForm */
2013-02-02 13:47:48 -08:00
psForm = ( W_FORM * ) widgGetFromID ( psWScreen , IDDES_SYSTEMFORM ) ;
if ( psForm ! = NULL )
2007-06-28 10:47:08 -07:00
{
psForm - > pUserData = psStats ;
}
/* Set the correct system stats */
2013-05-13 13:20:49 -07:00
switch ( psStats - > compType )
2007-06-28 10:47:08 -07:00
{
case COMP_SENSOR :
intSetSensorStats ( ( SENSOR_STATS * ) psStats ) ;
break ;
case COMP_ECM :
intSetECMStats ( ( ECM_STATS * ) psStats ) ;
break ;
case COMP_WEAPON :
intSetWeaponStats ( ( WEAPON_STATS * ) psStats ) ;
break ;
case COMP_CONSTRUCT :
intSetConstructStats ( ( CONSTRUCT_STATS * ) psStats ) ;
break ;
case COMP_REPAIRUNIT :
intSetRepairStats ( ( REPAIR_STATS * ) psStats ) ;
break ;
2013-05-19 11:57:12 -07:00
case COMP_BRAIN :
// ??? TBD FIXME
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2007-06-28 10:47:08 -07:00
}
}
/* Set the shadow bar graphs for the system clickable */
2008-07-11 08:37:46 -07:00
static void intSetSystemShadowStats ( COMPONENT_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
/* Set the correct system stats - psStats can be set to NULL if
* desSysMode does not match the type of the stats .
*/
if ( psStats )
{
2013-05-13 13:20:49 -07:00
switch ( psStats - > compType )
2007-06-28 10:47:08 -07:00
{
case COMP_SENSOR :
if ( desSysMode = = IDES_SENSOR )
{
intSetSensorShadowStats ( ( SENSOR_STATS * ) psStats ) ;
}
else
{
psStats = NULL ;
}
break ;
case COMP_ECM :
if ( desSysMode = = IDES_ECM )
{
intSetECMShadowStats ( ( ECM_STATS * ) psStats ) ;
}
else
{
psStats = NULL ;
}
break ;
case COMP_WEAPON :
if ( desSysMode = = IDES_WEAPON )
{
intSetWeaponShadowStats ( ( WEAPON_STATS * ) psStats ) ;
}
else
{
psStats = NULL ;
}
break ;
case COMP_CONSTRUCT :
if ( desSysMode = = IDES_CONSTRUCT )
{
intSetConstructShadowStats ( ( CONSTRUCT_STATS * ) psStats ) ;
}
else
{
psStats = NULL ;
}
break ;
case COMP_BRAIN :
psStats = NULL ;
break ;
case COMP_REPAIRUNIT :
if ( desSysMode = = IDES_REPAIR )
{
intSetRepairShadowStats ( ( REPAIR_STATS * ) psStats ) ;
}
else
{
psStats = NULL ;
}
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2007-06-28 10:47:08 -07:00
}
}
2013-02-02 13:17:27 -08:00
else // if !psStats
2007-06-28 10:47:08 -07:00
{
switch ( desSysMode )
{
case IDES_SENSOR :
intSetSensorShadowStats ( NULL ) ;
break ;
case IDES_ECM :
intSetECMShadowStats ( NULL ) ;
break ;
case IDES_WEAPON :
intSetWeaponShadowStats ( NULL ) ;
break ;
case IDES_CONSTRUCT :
intSetConstructShadowStats ( NULL ) ;
break ;
case IDES_REPAIR :
intSetRepairShadowStats ( NULL ) ;
break ;
default :
break ;
}
}
}
/* Set the bar graphs for the sensor stats */
static void intSetSensorStats ( SENSOR_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_SENSOR_START ) & &
( psStats - > ref < REF_SENSOR_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* range */
2011-01-17 12:23:17 -08:00
widgSetBarSize ( psWScreen , IDDES_SENSORRANGE , sensorRange ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* power */
2011-01-17 12:23:17 -08:00
widgSetBarSize ( psWScreen , IDDES_SENSORPOWER , 0 ) ; // FIXME: Remove
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_SENSORWEIGHT , psStats - > weight ) ;
}
/* Set the shadow bar graphs for the sensor stats */
static void intSetSensorShadowStats ( SENSOR_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_SENSOR_START ) & &
( psStats - > ref < REF_SENSOR_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* range */
2006-05-27 09:37:17 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_SENSORRANGE ,
2013-02-02 13:47:48 -08:00
sensorRange ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* power */
2011-01-17 12:23:17 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_SENSORPOWER , 0 ) ; // FIXME: Remove
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_SENSORWEIGHT , psStats - > weight ) ;
}
else
{
/* Remove the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_SENSORRANGE , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_SENSORPOWER , 0 ) ;
2006-05-27 09:37:17 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_SENSORWEIGHT , 0 ) ;
2007-06-28 10:47:08 -07:00
}
}
/* Set the bar graphs for the ECM stats */
static void intSetECMStats ( ECM_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_ECM_START ) & &
( psStats - > ref < REF_ECM_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
2011-01-17 12:23:17 -08:00
/* range */
widgSetBarSize ( psWScreen , IDDES_ECMPOWER , ecmRange ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_ECMWEIGHT , psStats - > weight ) ;
}
/* Set the shadow bar graphs for the ECM stats */
static void intSetECMShadowStats ( ECM_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_ECM_START ) & &
( psStats - > ref < REF_ECM_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* power */
2011-01-17 12:23:17 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_ECMPOWER , ecmRange ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_ECMWEIGHT , psStats - > weight ) ;
}
else
{
/* Remove the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_ECMPOWER , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_ECMWEIGHT , 0 ) ;
}
}
/* Set the bar graphs for the Constructor stats */
static void intSetConstructStats ( CONSTRUCT_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_CONSTRUCT_START ) & &
( psStats - > ref < REF_CONSTRUCT_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* power */
2006-05-27 09:37:17 -07:00
widgSetBarSize ( psWScreen , IDDES_CONSTPOINTS ,
2013-02-02 13:47:48 -08:00
constructorPoints ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_CONSTWEIGHT , psStats - > weight ) ;
}
/* Set the shadow bar graphs for the Constructor stats */
static void intSetConstructShadowStats ( CONSTRUCT_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_CONSTRUCT_START ) & &
( psStats - > ref < REF_CONSTRUCT_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* power */
2006-05-27 09:37:17 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_CONSTPOINTS ,
2013-02-02 13:47:48 -08:00
constructorPoints ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_CONSTWEIGHT , psStats - > weight ) ;
}
else
{
/* reset the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_CONSTPOINTS , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_CONSTWEIGHT , 0 ) ;
}
}
/* Set the bar graphs for the Repair stats */
static void intSetRepairStats ( REPAIR_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_REPAIR_START ) & &
( psStats - > ref < REF_REPAIR_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* power */
2006-05-27 09:37:17 -07:00
widgSetBarSize ( psWScreen , IDDES_REPAIRPOINTS ,
2013-02-02 13:47:48 -08:00
repairPoints ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_REPAIRWEIGHT , psStats - > weight ) ;
}
/* Set the shadow bar graphs for the Repair stats */
static void intSetRepairShadowStats ( REPAIR_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_REPAIR_START ) & &
( psStats - > ref < REF_REPAIR_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* power */
2006-05-27 09:37:17 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_REPAIRPOINTS ,
2013-02-02 13:47:48 -08:00
repairPoints ( psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_REPAIRWEIGHT , psStats - > weight ) ;
}
else
{
/* reset the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_REPAIRPOINTS , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_REPAIRWEIGHT , 0 ) ;
}
}
/* Set the bar graphs for the Weapon stats */
static void intSetWeaponStats ( WEAPON_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_WEAPON_START ) & &
( psStats - > ref < REF_WEAPON_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* range */
2013-05-05 04:34:59 -07:00
widgSetBarSize ( psWScreen , IDDES_WEAPRANGE , proj_GetLongRange ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* rate of fire */
2007-12-31 14:16:51 -08:00
widgSetBarSize ( psWScreen , IDDES_WEAPROF , weaponROF ( psStats , ( SBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* damage */
2006-05-27 09:37:17 -07:00
widgSetBarSize ( psWScreen , IDDES_WEAPDAMAGE , ( UWORD ) weaponDamage ( psStats ,
2013-02-02 13:47:48 -08:00
( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_WEAPWEIGHT , psStats - > weight ) ;
}
/* Set the shadow bar graphs for the Weapon stats */
static void intSetWeaponShadowStats ( WEAPON_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_WEAPON_START ) & &
( psStats - > ref < REF_WEAPON_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* range */
2013-05-05 04:34:59 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_WEAPRANGE , proj_GetLongRange ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* rate of fire */
2007-12-31 14:16:51 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_WEAPROF , weaponROF ( psStats , ( SBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* damage */
widgSetMinorBarSize ( psWScreen , IDDES_WEAPDAMAGE , ( UWORD ) weaponDamage (
2013-02-02 13:47:48 -08:00
psStats , ( UBYTE ) selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_WEAPWEIGHT , psStats - > weight ) ;
}
else
{
/* Reset the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_WEAPRANGE , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_WEAPROF , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_WEAPDAMAGE , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_WEAPWEIGHT , 0 ) ;
}
}
/* Set the bar graphs for the Body stats */
static void intSetBodyStats ( BODY_STATS * psStats )
{
W_FORM * psForm ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_BODY_START ) & &
( psStats - > ref < REF_BODY_START + REF_RANGE ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* set form tip to stats string */
2013-05-13 14:11:34 -07:00
widgSetTip ( psWScreen , IDDES_BODYFORM , psStats - > name ) ;
2007-06-28 10:47:08 -07:00
/* armour */
//do kinetic armour
2013-05-05 04:34:59 -07:00
widgSetBarSize ( psWScreen , IDDES_BODYARMOUR_K , bodyArmour ( psStats , selectedPlayer , WC_KINETIC ) ) ;
2007-06-28 10:47:08 -07:00
//do heat armour
2013-05-05 04:34:59 -07:00
widgSetBarSize ( psWScreen , IDDES_BODYARMOUR_H , bodyArmour ( psStats , selectedPlayer , WC_HEAT ) ) ;
2007-06-28 10:47:08 -07:00
/* power */
2013-05-05 04:34:59 -07:00
widgSetBarSize ( psWScreen , IDDES_BODYPOWER , bodyPower ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetBarSize ( psWScreen , IDDES_BODYWEIGHT , psStats - > weight ) ;
/* set form stats for later display in intDisplayStatForm */
2013-02-02 13:47:48 -08:00
psForm = ( W_FORM * ) widgGetFromID ( psWScreen , IDDES_BODYFORM ) ;
if ( psForm ! = NULL )
2007-06-28 10:47:08 -07:00
{
psForm - > pUserData = psStats ;
}
}
/* Set the shadow bar graphs for the Body stats */
static void intSetBodyShadowStats ( BODY_STATS * psStats )
{
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_BODY_START ) & &
( psStats - > ref < REF_BODY_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
if ( psStats )
{
/* armour - kinetic*/
2013-05-05 04:34:59 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_BODYARMOUR_K , bodyArmour ( psStats , selectedPlayer , WC_KINETIC ) ) ;
2006-05-27 09:37:17 -07:00
//armour - heat
2013-05-05 04:34:59 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_BODYARMOUR_H , bodyArmour ( psStats , selectedPlayer , WC_HEAT ) ) ;
2007-06-28 10:47:08 -07:00
/* power */
2013-05-05 04:34:59 -07:00
widgSetMinorBarSize ( psWScreen , IDDES_BODYPOWER , bodyPower ( psStats , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
/* weight */
widgSetMinorBarSize ( psWScreen , IDDES_BODYWEIGHT , psStats - > weight ) ;
}
else
{
/* Reset the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_BODYARMOUR_K , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_BODYARMOUR_H , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_BODYPOWER , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_BODYWEIGHT , 0 ) ;
}
}
/* Sets the Design Power Bar for a given Template */
static void intSetDesignPower ( DROID_TEMPLATE * psTemplate )
{
/* use the same scale as PowerBar in main window so values are relative */
widgSetBarSize ( psWScreen , IDDES_POWERBAR , calcTemplatePower ( psTemplate ) ) ;
}
2007-02-21 14:38:52 -08:00
// work out current system component
2013-05-13 13:20:49 -07:00
static COMPONENT_TYPE getSystemType ( DROID_TEMPLATE * droidTemplate )
2007-02-21 14:38:52 -08:00
{
2013-02-02 13:47:48 -08:00
if ( droidTemplate - > asParts [ COMP_ECM ] )
{
2007-02-21 14:38:52 -08:00
return COMP_ECM ;
2013-02-02 13:47:48 -08:00
}
else if ( droidTemplate - > asParts [ COMP_SENSOR ] )
{
2007-02-21 14:38:52 -08:00
return COMP_SENSOR ;
2013-02-02 13:47:48 -08:00
}
else if ( droidTemplate - > asParts [ COMP_CONSTRUCT ] )
{
2007-02-21 14:38:52 -08:00
return COMP_CONSTRUCT ;
2013-02-02 13:47:48 -08:00
}
else if ( droidTemplate - > asParts [ COMP_REPAIRUNIT ] )
{
2007-02-21 14:38:52 -08:00
return COMP_REPAIRUNIT ;
2013-02-02 13:47:48 -08:00
}
else if ( droidTemplate - > asWeaps [ 0 ] )
{
2007-02-21 14:38:52 -08:00
return COMP_WEAPON ;
2013-02-02 13:47:48 -08:00
}
else
{
2009-05-21 19:41:13 -07:00
// compare it with the current weapon
2007-02-21 14:38:52 -08:00
return COMP_WEAPON ;
}
}
2007-06-28 10:47:08 -07:00
/* Set the shadow bar graphs for the template power points - psStats is new hilited stats*/
2008-07-11 08:37:46 -07:00
static void intSetTemplatePowerShadowStats ( COMPONENT_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:17:27 -08:00
if ( ! psStats )
{
/* Reset the shadow bar */
widgSetMinorBarSize ( psWScreen , IDDES_POWERBAR , 0 ) ;
return ;
}
2007-06-28 10:47:08 -07:00
2013-05-13 13:20:49 -07:00
COMPONENT_TYPE type = psStats - > compType ;
2013-02-02 13:17:27 -08:00
UDWORD power ;
2013-02-02 13:47:48 -08:00
UDWORD bodyPower = asBodyStats [ sCurrDesign . asParts [ COMP_BODY ] ] . buildPower ;
UDWORD brainPower = asBrainStats [ sCurrDesign . asParts [ COMP_BRAIN ] ] . buildPower ;
UDWORD sensorPower = asSensorStats [ sCurrDesign . asParts [ COMP_SENSOR ] ] . buildPower ;
UDWORD ECMPower = asECMStats [ sCurrDesign . asParts [ COMP_ECM ] ] . buildPower ;
UDWORD repairPower = asRepairStats [ sCurrDesign . asParts [ COMP_REPAIRUNIT ] ] . buildPower ;
UDWORD constructPower = asConstructStats [ sCurrDesign . asParts [ COMP_CONSTRUCT ] ] . buildPower ;
UDWORD propulsionPower = asPropulsionStats [ sCurrDesign . asParts [ COMP_PROPULSION ] ] . buildPower ;
UDWORD weaponPower1 = asWeaponStats [ sCurrDesign . numWeaps ? sCurrDesign . asWeaps [ 0 ] : 0 ] . buildPower ;
UDWORD weaponPower2 = asWeaponStats [ sCurrDesign . numWeaps > = 2 ? sCurrDesign . asWeaps [ 1 ] : 0 ] . buildPower ;
UDWORD weaponPower3 = asWeaponStats [ sCurrDesign . numWeaps > = 3 ? sCurrDesign . asWeaps [ 2 ] : 0 ] . buildPower ;
UDWORD newComponentPower = psStats - > buildPower ;
// Commanders receive the stats of their associated weapon.
if ( type = = COMP_BRAIN )
{
newComponentPower + = ( ( BRAIN_STATS * ) psStats ) - > psWeaponStat - > buildPower ;
}
/*if type = BODY or PROPULSION can do a straight comparison but if the new stat is
a ' system ' stat then need to find out which ' system ' is currently in place so the
comparison is meaningful */
if ( desCompMode = = IDES_SYSTEM )
{
type = getSystemType ( & sCurrDesign ) ;
}
switch ( type )
{
case COMP_BODY :
bodyPower = newComponentPower ;
break ;
case COMP_PROPULSION :
propulsionPower = newComponentPower ;
break ;
case COMP_ECM :
ECMPower = newComponentPower ;
break ;
case COMP_SENSOR :
sensorPower = newComponentPower ;
break ;
case COMP_CONSTRUCT :
constructPower = newComponentPower ;
break ;
case COMP_REPAIRUNIT :
repairPower = newComponentPower ;
break ;
case COMP_WEAPON :
brainPower = 0 ;
if ( desCompMode = = IDES_TURRET_A )
2009-12-30 13:59:25 -08:00
{
2013-02-02 13:47:48 -08:00
weaponPower2 = newComponentPower ;
2009-12-30 13:59:25 -08:00
}
2013-02-02 13:47:48 -08:00
else if ( desCompMode = = IDES_TURRET_B )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
weaponPower3 = newComponentPower ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
else
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
weaponPower1 = newComponentPower ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2013-02-02 13:47:48 -08:00
}
2007-02-14 14:08:53 -08:00
2013-02-02 13:47:48 -08:00
// this code is from calcTemplatePower
2007-02-14 10:46:07 -08:00
2013-02-02 13:47:48 -08:00
//get the component power
power = bodyPower + brainPower + sensorPower + ECMPower + repairPower + constructPower ;
2007-02-14 10:46:07 -08:00
2013-02-02 13:47:48 -08:00
/* propulsion power points are a percentage of the bodys' power points */
power + = ( propulsionPower * bodyPower ) / 100 ;
2007-03-16 09:20:16 -07:00
2013-02-02 13:47:48 -08:00
//add weapon power
power + = weaponPower1 + weaponPower2 + weaponPower3 ;
widgSetMinorBarSize ( psWScreen , IDDES_POWERBAR , power ) ;
2007-06-28 10:47:08 -07:00
}
/* Sets the Body Points Bar for a given Template */
static void intSetBodyPoints ( DROID_TEMPLATE * psTemplate )
{
// If total greater than Body Bar size then scale values.
2013-02-02 13:47:48 -08:00
widgSetBarSize ( psWScreen , IDDES_BODYPOINTS , calcTemplateBody ( psTemplate , selectedPlayer ) ) ;
2007-06-28 10:47:08 -07:00
}
/* Set the shadow bar graphs for the template Body points - psStats is new hilited stats*/
2008-07-11 08:37:46 -07:00
static void intSetTemplateBodyShadowStats ( COMPONENT_STATS * psStats )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:17:27 -08:00
if ( ! psStats )
{
/* Reset the shadow bar */
widgSetMinorBarSize ( psWScreen , IDDES_BODYPOINTS , 0 ) ;
return ;
}
2007-06-28 10:47:08 -07:00
2013-05-13 13:20:49 -07:00
COMPONENT_TYPE type = psStats - > compType ;
2013-02-02 13:17:27 -08:00
UDWORD body ;
2013-02-02 13:47:48 -08:00
UDWORD bodyBody = asBodyStats [ sCurrDesign . asParts [ COMP_BODY ] ] . body ;
UDWORD brainBody = asBrainStats [ sCurrDesign . asParts [ COMP_BRAIN ] ] . body ;
UDWORD sensorBody = asSensorStats [ sCurrDesign . asParts [ COMP_SENSOR ] ] . body ;
UDWORD ECMBody = asECMStats [ sCurrDesign . asParts [ COMP_ECM ] ] . body ;
UDWORD repairBody = asRepairStats [ sCurrDesign . asParts [ COMP_REPAIRUNIT ] ] . body ;
UDWORD constructBody = asConstructStats [ sCurrDesign . asParts [ COMP_CONSTRUCT ] ] . body ;
UDWORD propulsionBody = asPropulsionStats [ sCurrDesign . asParts [ COMP_PROPULSION ] ] . body ;
UDWORD weaponBody1 = asWeaponStats [ sCurrDesign . numWeaps ? sCurrDesign . asWeaps [ 0 ] : 0 ] . body ;
UDWORD weaponBody2 = asWeaponStats [ sCurrDesign . numWeaps > = 2 ? sCurrDesign . asWeaps [ 1 ] : 0 ] . body ;
UDWORD weaponBody3 = asWeaponStats [ sCurrDesign . numWeaps > = 3 ? sCurrDesign . asWeaps [ 2 ] : 0 ] . body ;
UDWORD newComponentBody = psStats - > body ;
// Commanders receive the stats of their associated weapon.
if ( type = = COMP_BRAIN )
{
newComponentBody + = ( ( BRAIN_STATS * ) psStats ) - > psWeaponStat - > body ;
}
/*if type = BODY or PROPULSION can do a straight comparison but if the new stat is
a ' system ' stat then need to find out which ' system ' is currently in place so the
comparison is meaningful */
if ( desCompMode = = IDES_SYSTEM )
{
type = getSystemType ( & sCurrDesign ) ;
}
switch ( type )
{
case COMP_BODY :
bodyBody = newComponentBody ;
break ;
case COMP_PROPULSION :
propulsionBody = newComponentBody ;
break ;
case COMP_ECM :
ECMBody = newComponentBody ;
break ;
case COMP_SENSOR :
sensorBody = newComponentBody ;
break ;
case COMP_CONSTRUCT :
constructBody = newComponentBody ;
break ;
case COMP_REPAIRUNIT :
repairBody = newComponentBody ;
break ;
case COMP_WEAPON :
brainBody = 0 ;
if ( desCompMode = = IDES_TURRET_A )
2009-12-30 13:59:25 -08:00
{
2013-02-02 13:47:48 -08:00
weaponBody2 = newComponentBody ;
2009-12-30 13:59:25 -08:00
}
2013-02-02 13:47:48 -08:00
else if ( desCompMode = = IDES_TURRET_B )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
weaponBody3 = newComponentBody ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
else
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
weaponBody1 = newComponentBody ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2013-02-02 13:47:48 -08:00
}
// this code is from calcTemplateBody
2007-02-14 10:46:07 -08:00
2013-02-02 13:47:48 -08:00
//get the component HP
body = bodyBody + brainBody + sensorBody + ECMBody + repairBody + constructBody ;
2007-02-14 10:46:07 -08:00
2013-02-02 13:47:48 -08:00
/* propulsion HP are a percentage of the body's HP */
body + = ( propulsionBody * bodyBody ) / 100 ;
2007-03-16 09:20:16 -07:00
2013-02-02 13:47:48 -08:00
//add weapon HP
body + = weaponBody1 + weaponBody2 + weaponBody3 ;
2013-05-05 04:34:59 -07:00
body + = ( body * asBodyStats [ sCurrDesign . asParts [ COMP_BODY ] ] . upgrade [ selectedPlayer ] . body / 100 ) ;
2013-02-02 13:47:48 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_BODYPOINTS , body ) ;
2007-06-28 10:47:08 -07:00
}
/* Calculate the speed of a droid over a type of terrain */
static UDWORD intCalcSpeed ( TYPE_OF_TERRAIN type , PROPULSION_STATS * psProp )
{
2013-02-02 13:17:27 -08:00
UDWORD weight = calcDroidWeight ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
if ( weight = = 0 )
{
return 0 ;
}
2009-05-21 19:41:13 -07:00
//we want the design screen to show zero speed over water for all prop types except Hover and Vtol
if ( type = = TER_WATER )
{
if ( ! ( psProp - > propulsionType = = PROPULSION_TYPE_HOVER | | psProp - > propulsionType = = PROPULSION_TYPE_LIFT ) )
{
return 0 ;
}
}
2013-02-02 13:17:27 -08:00
return calcDroidSpeed ( calcDroidBaseSpeed ( & sCurrDesign , weight , selectedPlayer ) , type , psProp - asPropulsionStats , 0 ) ;
2007-06-28 10:47:08 -07:00
}
/* Set the bar graphs for the Propulsion stats */
static void intSetPropulsionStats ( PROPULSION_STATS * psStats )
{
W_FORM * psForm ;
2009-05-21 19:41:13 -07:00
UDWORD weight ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psStats ! = NULL , " Invalid stats pointer " ) ;
ASSERT_OR_RETURN ( , ( psStats - > ref > = REF_PROPULSION_START ) & &
( psStats - > ref < REF_PROPULSION_START + REF_RANGE ) , " stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* set form tip to stats string */
2013-05-13 14:11:34 -07:00
widgSetTip ( psWScreen , IDDES_PROPFORM , psStats - > name ) ;
2007-06-28 10:47:08 -07:00
/* set form stats for later display in intDisplayStatForm */
2013-02-02 13:47:48 -08:00
psForm = ( W_FORM * ) widgGetFromID ( psWScreen , IDDES_PROPFORM ) ;
if ( psForm ! = NULL )
2007-06-28 10:47:08 -07:00
{
psForm - > pUserData = psStats ;
}
switch ( desPropMode )
{
case IDES_GROUND :
/* Road speed */
widgSetBarSize ( psWScreen , IDDES_PROPROAD , intCalcSpeed ( TER_ROAD , psStats ) ) ;
/* Cross country speed - grass */
widgSetBarSize ( psWScreen , IDDES_PROPCOUNTRY , intCalcSpeed ( TER_SANDYBRUSH , psStats ) ) ;
/* Water speed */
widgSetBarSize ( psWScreen , IDDES_PROPWATER , intCalcSpeed ( TER_WATER , psStats ) ) ;
break ;
case IDES_AIR :
/* Air speed - terrain type doesn't matter, use road */
widgSetBarSize ( psWScreen , IDDES_PROPAIR , intCalcSpeed ( TER_ROAD , psStats ) ) ;
break ;
default :
break ;
}
/* weight */
//widgSetBarSize(psWScreen, IDDES_PROPWEIGHT, psStats->weight);
2009-05-21 19:41:13 -07:00
/* propulsion weight is a percentage of the body weight */
if ( sCurrDesign . asParts [ COMP_BODY ] ! = 0 )
{
weight = psStats - > weight * asBodyStats [ sCurrDesign . asParts [ COMP_BODY ] ] . weight / 100 ;
}
else
{
//if haven't got a body - can't calculate a value
weight = 0 ;
}
widgSetBarSize ( psWScreen , IDDES_PROPWEIGHT , weight ) ;
2007-06-28 10:47:08 -07:00
}
/* Set the shadow bar graphs for the Propulsion stats */
static void intSetPropulsionShadowStats ( PROPULSION_STATS * psStats )
{
2009-05-21 19:41:13 -07:00
UDWORD weight ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
ASSERT ( psStats = = NULL | |
( ( psStats - > ref > = REF_PROPULSION_START ) & &
( psStats - > ref < REF_PROPULSION_START + REF_RANGE ) ) ,
" stats ref is out of range " ) ;
2007-06-28 10:47:08 -07:00
/* Only set the shadow stats if they are the right type */
if ( psStats & &
2013-02-02 13:47:48 -08:00
( ( asPropulsionTypes [ psStats - > propulsionType ] . travel = = GROUND & &
desPropMode ! = IDES_GROUND ) | |
( asPropulsionTypes [ psStats - > propulsionType ] . travel = = AIR & &
desPropMode ! = IDES_AIR ) ) )
2007-06-28 10:47:08 -07:00
{
return ;
}
switch ( desPropMode )
{
case IDES_GROUND :
if ( psStats )
{
/* Road speed */
2013-02-02 13:47:48 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_PROPROAD ,
intCalcSpeed ( TER_ROAD , psStats ) ) ;
2007-06-28 10:47:08 -07:00
/* Cross country speed - grass */
2013-02-02 13:47:48 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_PROPCOUNTRY ,
intCalcSpeed ( TER_SANDYBRUSH , psStats ) ) ;
2007-06-28 10:47:08 -07:00
/* Water speed */
widgSetMinorBarSize ( psWScreen , IDDES_PROPWATER ,
2013-02-02 13:47:48 -08:00
intCalcSpeed ( TER_WATER , psStats ) ) ;
2007-06-28 10:47:08 -07:00
}
else
{
/* Reset the shadow bars */
widgSetMinorBarSize ( psWScreen , IDDES_PROPROAD , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_PROPCOUNTRY , 0 ) ;
widgSetMinorBarSize ( psWScreen , IDDES_PROPWATER , 0 ) ;
}
break ;
case IDES_AIR :
if ( psStats )
{
/* Air speed - terrain type doesn't matter, use ROAD */
2013-02-02 13:47:48 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_PROPAIR ,
intCalcSpeed ( TER_ROAD , psStats ) ) ;
2007-06-28 10:47:08 -07:00
}
else
{
/* Reset the shadow bar */
widgSetMinorBarSize ( psWScreen , IDDES_PROPAIR , 0 ) ;
}
break ;
default :
break ;
}
if ( psStats )
{
/* weight */
//widgSetMinorBarSize(psWScreen, IDDES_PROPWEIGHT, psStats->weight);
2009-05-21 19:41:13 -07:00
/* propulsion weight is a percentage of the body weight */
if ( sCurrDesign . asParts [ COMP_BODY ] ! = 0 )
{
weight = psStats - > weight * asBodyStats [ sCurrDesign . asParts [ COMP_BODY ] ] . weight / 100 ;
}
else
{
//if haven't got a body - can't calculate a value
weight = 0 ;
}
widgSetMinorBarSize ( psWScreen , IDDES_PROPWEIGHT , weight ) ;
2007-06-28 10:47:08 -07:00
}
else
{
/* Reset the shadow bar */
widgSetMinorBarSize ( psWScreen , IDDES_PROPWEIGHT , 0 ) ;
}
}
/* Check whether a droid template is valid */
2013-01-21 13:17:58 -08:00
bool intValidTemplate ( DROID_TEMPLATE * psTempl , const char * newName , bool complain , int player )
2007-06-28 10:47:08 -07:00
{
2011-12-29 08:13:04 -08:00
code_part level = complain ? LOG_ERROR : LOG_NEVER ;
2011-12-28 05:37:48 -08:00
int bodysize = ( asBodyStats + psTempl - > asParts [ COMP_BODY ] ) - > size ;
2007-06-28 10:47:08 -07:00
// set the weapon for a command droid
if ( psTempl - > asParts [ COMP_BRAIN ] ! = 0 )
{
psTempl - > numWeaps = 1 ;
2007-04-01 14:01:29 -07:00
psTempl - > asWeaps [ 0 ] = asBrainStats [ psTempl - > asParts [ COMP_BRAIN ] ] . psWeaponStat - asWeaponStats ;
2007-06-28 10:47:08 -07:00
}
/* Check all the components have been set */
if ( psTempl - > asParts [ COMP_BODY ] = = 0 )
{
2011-12-29 08:13:04 -08:00
debug ( level , " No body given for template " ) ;
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
else if ( psTempl - > asParts [ COMP_PROPULSION ] = = 0 )
{
2011-12-29 08:13:04 -08:00
debug ( level , " No propulsion given for template " ) ;
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
// Check a turret has been installed
if ( psTempl - > numWeaps = = 0 & &
2013-02-02 13:47:48 -08:00
psTempl - > asParts [ COMP_SENSOR ] = = 0 & &
psTempl - > asParts [ COMP_ECM ] = = 0 & &
psTempl - > asParts [ COMP_BRAIN ] = = 0 & &
psTempl - > asParts [ COMP_REPAIRUNIT ] = = 0 & &
psTempl - > asParts [ COMP_CONSTRUCT ] = = 0 )
2007-06-28 10:47:08 -07:00
{
2011-12-29 08:13:04 -08:00
debug ( level , " No turret for template " ) ;
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
/* Check the weapons */
2013-01-21 12:32:44 -08:00
for ( int i = 0 ; i < psTempl - > numWeaps ; i + + )
2007-06-28 10:47:08 -07:00
{
2011-12-28 05:37:48 -08:00
int weaponSize = ( asWeaponStats + psTempl - > asWeaps [ i ] ) - > weaponSize ;
if ( ( weaponSize = = WEAPON_SIZE_LIGHT & & bodysize ! = SIZE_LIGHT )
| | ( weaponSize = = WEAPON_SIZE_HEAVY & & bodysize = = SIZE_LIGHT )
| | psTempl - > asWeaps [ i ] = = 0 )
2007-06-28 10:47:08 -07:00
{
2011-12-29 08:13:04 -08:00
debug ( level , " No weapon given for weapon droid, or wrong weapon size " ) ;
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
2013-01-21 12:32:44 -08:00
if ( checkTemplateIsVtol ( psTempl )
& & ( asWeaponStats + psTempl - > asWeaps [ i ] ) - > vtolAttackRuns < = 0 )
{
debug ( level , " VTOL with non-VTOL turret, not possible " ) ;
return false ;
}
2007-06-28 10:47:08 -07:00
}
2011-12-18 14:42:25 -08:00
// Check number of weapon slots
if ( psTempl - > numWeaps > ( asBodyStats + psTempl - > asParts [ COMP_BODY ] ) - > weaponSlots )
{
2011-12-29 08:13:04 -08:00
debug ( level , " Too many weapon turrets " ) ;
2011-12-18 14:42:25 -08:00
return false ;
}
2009-12-30 13:59:25 -08:00
// Check no mixing of systems and weapons
if ( psTempl - > numWeaps ! = 0 & &
( psTempl - > asParts [ COMP_SENSOR ] | |
psTempl - > asParts [ COMP_ECM ] | |
2013-01-21 13:17:58 -08:00
( psTempl - > asParts [ COMP_REPAIRUNIT ] & & psTempl - > asParts [ COMP_REPAIRUNIT ] ! = aDefaultRepair [ player ] ) | |
2009-12-30 13:59:25 -08:00
psTempl - > asParts [ COMP_CONSTRUCT ] ) )
{
2011-12-29 08:13:04 -08:00
debug ( level , " Cannot mix system and weapon turrets in a template! " ) ;
2009-12-30 13:59:25 -08:00
return false ;
}
2011-12-29 08:13:04 -08:00
if ( psTempl - > numWeaps ! = 1 & & psTempl - > asParts [ COMP_BRAIN ] )
2009-12-30 13:59:25 -08:00
{
2011-12-29 08:13:04 -08:00
debug ( level , " Commander template needs 1 weapon turret " ) ;
2009-12-30 13:59:25 -08:00
return false ;
}
2013-02-02 13:47:48 -08:00
2013-01-21 12:32:44 -08:00
//can only have a VTOL weapon on a VTOL propulsion
if ( checkTemplateIsVtol ( psTempl ) & & psTempl - > numWeaps = = 0 )
2009-05-21 19:41:13 -07:00
{
2013-01-21 12:32:44 -08:00
debug ( level , " VTOL with system turret, not possible " ) ;
return false ;
2009-05-21 19:41:13 -07:00
}
2007-06-28 10:47:08 -07:00
if ( psTempl - > asParts [ COMP_SENSOR ] = = 0 )
{
/* Set the default Sensor */
2013-01-21 13:17:58 -08:00
psTempl - > asParts [ COMP_SENSOR ] = aDefaultSensor [ player ] ;
2007-06-28 10:47:08 -07:00
}
if ( psTempl - > asParts [ COMP_ECM ] = = 0 )
{
/* Set the default ECM */
2013-01-21 13:17:58 -08:00
psTempl - > asParts [ COMP_ECM ] = aDefaultECM [ player ] ;
2007-06-28 10:47:08 -07:00
}
if ( psTempl - > asParts [ COMP_REPAIRUNIT ] = = 0 )
{
/* Set the default Repair */
2013-01-21 13:17:58 -08:00
psTempl - > asParts [ COMP_REPAIRUNIT ] = aDefaultRepair [ player ] ;
2007-06-28 10:47:08 -07:00
}
psTempl - > ref = REF_TEMPLATE_START ;
//set the droidtype
psTempl - > droidType = droidTemplateType ( psTempl ) ;
2013-05-09 14:17:05 -07:00
psTempl - > enabled = true ;
2008-05-10 06:20:23 -07:00
/* copy name into template */
2013-05-12 14:50:57 -07:00
psTempl - > name = newName ;
2007-06-28 10:47:08 -07:00
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
static void desCreateDefaultTemplate ( void )
2007-06-28 10:47:08 -07:00
{
/* set current design to default */
2011-01-01 11:35:07 -08:00
sCurrDesign = sDefaultDesignTemplate ;
2011-12-18 03:20:48 -08:00
sCurrDesign . stored = false ;
2007-06-28 10:47:08 -07:00
/* reset stats */
intSetDesignStats ( & sCurrDesign ) ;
widgDelete ( psWScreen , IDDES_SYSTEMFORM ) ;
desSysMode = IDES_NOSYSTEM ;
2013-03-12 02:22:42 -07:00
haveCurrentDesign = true ;
2007-06-28 10:47:08 -07:00
}
/* Remove the design widgets from the widget screen */
void intRemoveDesign ( void )
{
//save the current design on exit if it is valid
saveTemplate ( ) ;
widgDelete ( psWScreen , IDDES_POWERFORM ) ;
widgDelete ( psWScreen , IDDES_NAMEBOX ) ;
widgDelete ( psWScreen , IDDES_TEMPLBASE ) ;
widgDelete ( psWScreen , IDDES_RIGHTBASE ) ;
widgDelete ( psWScreen , IDDES_BODYFORM ) ;
widgDelete ( psWScreen , IDDES_PROPFORM ) ;
widgDelete ( psWScreen , IDDES_SYSTEMFORM ) ;
widgDelete ( psWScreen , IDDES_FORM ) ;
2013-02-02 13:47:48 -08:00
widgDelete ( psWScreen , IDDES_STATSFORM ) ;
2007-06-28 10:47:08 -07:00
resetDesignPauseState ( ) ;
}
/* set flashing flag for button */
2013-02-02 13:47:48 -08:00
static void intSetButtonFlash ( UDWORD id , bool bFlash )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
WIDGET * psWidget = widgGetFromID ( psWScreen , id ) ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , psWidget - > type = = WIDG_BUTTON , " Not a button " ) ;
2007-06-28 10:47:08 -07:00
2013-02-16 23:42:55 -08:00
psWidget - > displayFunction = bFlash ? intDisplayButtonFlash : intDisplayButtonHilight ;
2007-06-28 10:47:08 -07:00
}
/*
* desTemplateNameCustomised
*
* Checks whether user has customised template name : template not
* customised if not complete or if generated name same as current .
*/
2013-02-02 13:47:48 -08:00
static bool desTemplateNameCustomised ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
if ( ( psTemplate - > droidType = = DROID_DEFAULT ) | |
2013-05-12 14:50:57 -07:00
( strcmp ( getName ( psTemplate ) ,
2013-02-02 13:47:48 -08:00
GetDefaultTemplateName ( psTemplate ) ) = = 0 ) )
2007-06-28 10:47:08 -07:00
{
2008-03-24 09:51:17 -07:00
return false ;
2007-06-28 10:47:08 -07:00
}
else
{
2008-03-24 09:51:17 -07:00
return true ;
2007-06-28 10:47:08 -07:00
}
}
2011-02-13 09:57:25 -08:00
static DROID_TEMPLATE * templateFromButtonId ( unsigned buttonId , bool allowBlankTemplate = false )
{
2013-02-02 13:47:48 -08:00
unsigned minIndex = allowBlankTemplate ? 0 : 1 ;
2011-02-13 09:57:25 -08:00
unsigned index = buttonId - IDDES_TEMPLSTART ;
if ( index > = minIndex & & index < apsTemplateList . size ( ) )
{
return apsTemplateList [ index ] ;
}
return NULL ;
}
2007-06-28 10:47:08 -07:00
/* Process return codes from the design screen */
void intProcessDesign ( UDWORD id )
{
2011-02-13 09:57:25 -08:00
bool bTemplateNameCustomised ;
2007-06-28 10:47:08 -07:00
/* check template button pressed */
if ( id > = IDDES_TEMPLSTART & & id < = IDDES_TEMPLEND )
{
/* if first template create blank design */
2013-02-02 13:47:48 -08:00
if ( id = = IDDES_TEMPLSTART )
2007-06-28 10:47:08 -07:00
{
desCreateDefaultTemplate ( ) ;
2013-05-09 14:17:05 -07:00
aCurrName [ 0 ] = ' \0 ' ;
2013-05-12 14:50:57 -07:00
sCurrDesign . name = aCurrName ;
2007-06-28 10:47:08 -07:00
2010-01-02 13:55:20 -08:00
/* reveal body button */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_BODYBUTTON ) ;
2010-01-02 13:55:20 -08:00
/* hide other component buttons */
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_SYSTEMBUTTON ) ;
widgHide ( psWScreen , IDDES_PROPBUTTON ) ;
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2007-06-28 10:47:08 -07:00
/* set button render routines to flash */
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_BODYBUTTON , true ) ;
intSetButtonFlash ( IDDES_SYSTEMBUTTON , true ) ;
intSetButtonFlash ( IDDES_PROPBUTTON , true ) ;
intSetButtonFlash ( IDDES_WPABUTTON , true ) ;
intSetButtonFlash ( IDDES_WPBBUTTON , true ) ;
2011-12-18 03:20:48 -08:00
widgHide ( psWScreen , IDDES_STOREBUTTON ) ;
2007-06-28 10:47:08 -07:00
}
else
{
/* Find the template for the new button */
2011-02-13 09:57:25 -08:00
DROID_TEMPLATE * psTempl = templateFromButtonId ( id , true ) ;
2007-06-28 10:47:08 -07:00
2010-01-02 13:55:20 -08:00
ASSERT_OR_RETURN ( , psTempl ! = NULL , " template not found! " ) ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
if ( psTempl ! = NULL )
2007-06-28 10:47:08 -07:00
{
/* Set the new template */
2011-01-01 11:35:07 -08:00
sCurrDesign = * psTempl ;
2013-05-12 14:50:57 -07:00
sstrcpy ( aCurrName , getName ( psTempl ) ) ;
2007-03-16 11:47:07 -07:00
2010-01-02 13:55:20 -08:00
/* reveal body/propulsion/turret component buttons */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_BODYBUTTON ) ;
widgReveal ( psWScreen , IDDES_PROPBUTTON ) ;
widgReveal ( psWScreen , IDDES_SYSTEMBUTTON ) ;
2010-01-02 13:55:20 -08:00
/* hide extra turrets */
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2007-06-28 10:47:08 -07:00
/* turn off button flashes */
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_BODYBUTTON , false ) ;
intSetButtonFlash ( IDDES_SYSTEMBUTTON , false ) ;
intSetButtonFlash ( IDDES_PROPBUTTON , false ) ;
intSetButtonFlash ( IDDES_WPABUTTON , false ) ;
intSetButtonFlash ( IDDES_WPBBUTTON , false ) ;
2009-12-30 20:45:51 -08:00
// reveal additional buttons
if ( psTempl - > numWeaps > = 2 )
{
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPABUTTON ) ;
2009-12-30 20:45:51 -08:00
}
else
{
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPABUTTON , true ) ;
2009-12-30 20:45:51 -08:00
}
if ( psTempl - > numWeaps = = 3 )
{
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPBBUTTON ) ;
2009-12-30 20:45:51 -08:00
}
else
{
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPBBUTTON , true ) ;
2009-12-30 20:45:51 -08:00
}
2011-12-18 03:20:48 -08:00
widgReveal ( psWScreen , IDDES_STOREBUTTON ) ;
updateStoreButton ( sCurrDesign . stored ) ;
2007-06-28 10:47:08 -07:00
}
}
/* reveal design form if not already on-screen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_FORM ) ;
2007-06-28 10:47:08 -07:00
/* Droid template button has been pressed - clear the old button */
if ( droidTemplID ! = 0 )
{
widgSetButtonState ( psWScreen , droidTemplID , 0 ) ;
}
intSetDesignStats ( & sCurrDesign ) ;
/* show body stats only */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgReveal ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
2007-06-28 10:47:08 -07:00
/*Update the Power bar stats as the power to build will have changed */
intSetDesignPower ( & sCurrDesign ) ;
/*Update the body points */
intSetBodyPoints ( & sCurrDesign ) ;
/* Lock the button */
widgSetButtonState ( psWScreen , id , WBUT_LOCK ) ;
droidTemplID = id ;
/* Update the component form */
widgDelete ( psWScreen , IDDES_RIGHTBASE ) ;
2010-01-02 13:55:20 -08:00
/* reset button states */
widgSetButtonState ( psWScreen , IDDES_SYSTEMBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_BODYBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_PROPBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPBBUTTON , 0 ) ;
2007-06-28 10:47:08 -07:00
desCompMode = IDES_NOCOMPONENT ;
intSetDesignMode ( IDES_BODY ) ;
}
else if ( id > = IDDES_COMPSTART & & id < = IDDES_COMPEND )
{
/* check whether can change template name */
2013-02-02 13:47:48 -08:00
bTemplateNameCustomised = desTemplateNameCustomised ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
/* Component stats button has been pressed - clear the old button */
if ( desCompID ! = 0 )
{
widgSetButtonState ( psWScreen , desCompID , 0 ) ;
}
/* Set the stats in the template */
switch ( desCompMode )
{
case IDES_SYSTEM :
2009-05-21 19:41:13 -07:00
//0 weapon for utility droid
2006-11-04 14:56:28 -08:00
sCurrDesign . numWeaps = 0 ;
2007-06-28 10:47:08 -07:00
break ;
case IDES_TURRET :
/* Calculate the index of the component */
2006-05-27 09:37:17 -07:00
sCurrDesign . asWeaps [ 0 ] =
2013-02-02 13:47:48 -08:00
( ( WEAPON_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) -
asWeaponStats ;
2009-12-30 21:03:07 -08:00
if ( sCurrDesign . numWeaps < 1 )
{
sCurrDesign . numWeaps = 1 ;
}
2007-06-28 10:47:08 -07:00
/* Reset the sensor, ECM and constructor and repair
- defaults will be set when OK is hit */
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2006-11-25 09:38:27 -08:00
//Watemelon:weaponslots >= 2
2013-02-02 13:47:48 -08:00
if ( ( asBodyStats + sCurrDesign . asParts [ COMP_BODY ] ) - > weaponSlots > = 2 )
2006-11-04 14:56:28 -08:00
{
/* reveal turret_a button if hidden */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPABUTTON ) ;
2006-11-04 14:56:28 -08:00
}
/* Set the new stats on the display */
intSetSystemForm ( apsComponentList [ id - IDDES_COMPSTART ] ) ;
2009-12-30 20:45:51 -08:00
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_SYSTEMBUTTON , false ) ;
2006-11-04 14:56:28 -08:00
// do the callback if in the tutorial
if ( bInTutorial )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_WEAPON ) ;
}
break ;
2013-02-02 13:47:48 -08:00
//Added cases for 2nd/3rd turret
2006-11-04 14:56:28 -08:00
case IDES_TURRET_A :
/* Calculate the index of the component */
sCurrDesign . asWeaps [ 1 ] =
2013-02-02 13:47:48 -08:00
( ( WEAPON_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) -
asWeaponStats ;
2009-12-30 21:03:07 -08:00
if ( sCurrDesign . numWeaps < 2 )
{
sCurrDesign . numWeaps = 2 ;
}
2006-11-04 14:56:28 -08:00
/* Reset the sensor, ECM and constructor and repair
- defaults will be set when OK is hit */
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2006-11-25 09:38:27 -08:00
//Watemelon:weaponSlots > 2
2013-02-02 13:47:48 -08:00
if ( ( asBodyStats + sCurrDesign . asParts [ COMP_BODY ] ) - > weaponSlots > 2 )
2006-11-04 14:56:28 -08:00
{
/* reveal turret_b button if hidden */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPBBUTTON ) ;
2006-11-04 14:56:28 -08:00
}
/* Set the new stats on the display */
intSetSystemForm ( apsComponentList [ id - IDDES_COMPSTART ] ) ;
2009-12-30 20:45:51 -08:00
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPABUTTON , false ) ;
2006-11-04 14:56:28 -08:00
// do the callback if in the tutorial
if ( bInTutorial )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_WEAPON ) ;
}
break ;
case IDES_TURRET_B :
/* Calculate the index of the component */
sCurrDesign . asWeaps [ 2 ] =
2013-02-02 13:47:48 -08:00
( ( WEAPON_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) -
asWeaponStats ;
2006-11-04 14:56:28 -08:00
sCurrDesign . numWeaps = 3 ;
/* Reset the sensor, ECM and constructor and repair
- defaults will be set when OK is hit */
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2007-06-28 10:47:08 -07:00
/* Set the new stats on the display */
intSetSystemForm ( apsComponentList [ id - IDDES_COMPSTART ] ) ;
2009-12-30 20:45:51 -08:00
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPBBUTTON , false ) ;
2007-06-28 10:47:08 -07:00
// do the callback if in the tutorial
if ( bInTutorial )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_WEAPON ) ;
}
break ;
case IDES_BODY :
/* reveal propulsion button if hidden */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_PROPBUTTON ) ;
2007-06-28 10:47:08 -07:00
/* Calculate the index of the component */
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_BODY ] =
2013-02-02 13:47:48 -08:00
( ( BODY_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) -
asBodyStats ;
2007-06-28 10:47:08 -07:00
/* Set the new stats on the display */
intSetBodyStats ( ( BODY_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) ;
2006-11-25 09:38:27 -08:00
2009-12-30 20:45:51 -08:00
if ( ( sCurrDesign . asParts [ COMP_BODY ] + asBodyStats ) - > weaponSlots = = 1 )
2006-11-25 09:38:27 -08:00
{
2009-12-30 20:45:51 -08:00
if ( sCurrDesign . numWeaps > 1 )
2006-11-25 09:38:27 -08:00
{
2009-12-30 20:45:51 -08:00
sCurrDesign . numWeaps = 1 ;
2006-11-25 09:38:27 -08:00
sCurrDesign . asWeaps [ 1 ] = 0 ;
sCurrDesign . asWeaps [ 2 ] = 0 ;
}
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2009-12-30 20:45:51 -08:00
}
else if ( ( sCurrDesign . asParts [ COMP_BODY ] + asBodyStats ) - > weaponSlots > = 2 )
{
if ( sCurrDesign . numWeaps > 2 )
2006-11-25 09:38:27 -08:00
{
2009-12-30 20:45:51 -08:00
sCurrDesign . numWeaps = 2 ;
2006-11-25 09:38:27 -08:00
sCurrDesign . asWeaps [ 2 ] = 0 ;
2009-12-30 20:45:51 -08:00
}
else if ( sCurrDesign . numWeaps = = 1 & & sCurrDesign . asWeaps [ 0 ] & & sCurrDesign . asParts [ COMP_BRAIN ] = = 0 )
{
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPABUTTON ) ;
2009-12-30 20:45:51 -08:00
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , 0 ) ;
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPABUTTON , false ) ;
2009-12-30 20:45:51 -08:00
}
else
{
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2006-12-02 06:38:09 -08:00
}
2006-11-25 09:38:27 -08:00
}
2009-12-30 20:45:51 -08:00
if ( ( sCurrDesign . asParts [ COMP_BODY ] + asBodyStats ) - > weaponSlots = = 3 )
{
if ( sCurrDesign . numWeaps = = 2 )
{
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPBBUTTON ) ;
2009-12-30 20:45:51 -08:00
widgSetButtonState ( psWScreen , IDDES_WPBBUTTON , 0 ) ;
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_WPABUTTON , false ) ;
2009-12-30 20:45:51 -08:00
}
else if ( sCurrDesign . numWeaps = = 1 & & sCurrDesign . asParts [ COMP_BRAIN ] = = 0 )
{
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_WPABUTTON ) ;
2009-12-30 20:45:51 -08:00
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , 0 ) ;
}
}
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_BODYBUTTON , false ) ;
2007-06-28 10:47:08 -07:00
// do the callback if in the tutorial
if ( bInTutorial )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_BODY ) ;
}
break ;
case IDES_PROPULSION :
/* Calculate the index of the component */
2008-10-12 02:26:40 -07:00
sCurrDesign . asParts [ COMP_PROPULSION ] = ( ( PROPULSION_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) - asPropulsionStats ;
2007-06-28 10:47:08 -07:00
/* Set the new stats on the display */
2012-02-10 05:15:33 -08:00
intSetPropulsionForm ( ( PROPULSION_STATS * ) apsComponentList [ id - IDDES_COMPSTART ] ) ;
2006-05-27 09:37:17 -07:00
2008-10-12 02:26:40 -07:00
// Check that the weapon (if any) is valid for this propulsion
2008-10-12 11:04:26 -07:00
if ( ! intCheckValidWeaponForProp ( ) )
2007-06-28 10:47:08 -07:00
{
2008-10-12 02:26:40 -07:00
// Not valid weapon so initialise the weapon stat
2007-06-28 10:47:08 -07:00
sCurrDesign . asWeaps [ 0 ] = 0 ;
2009-12-30 20:45:51 -08:00
sCurrDesign . asWeaps [ 1 ] = 0 ;
sCurrDesign . asWeaps [ 2 ] = 0 ;
sCurrDesign . numWeaps = 0 ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2008-10-12 02:26:40 -07:00
// Init all other stats as well!
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
2009-12-30 20:45:51 -08:00
// We need a turret again
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_SYSTEMBUTTON , true ) ;
2007-06-28 10:47:08 -07:00
}
2008-10-12 02:26:40 -07:00
2009-12-30 20:45:51 -08:00
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_PROPBUTTON , false ) ;
2007-06-28 10:47:08 -07:00
// do the callback if in the tutorial
if ( bInTutorial )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_PROPULSION ) ;
}
break ;
default :
break ;
}
/* Lock the new button */
widgSetButtonState ( psWScreen , id , WBUT_LOCK ) ;
desCompID = id ;
/* Update the propulsion stats as the droid weight will have changed */
intSetPropulsionStats ( asPropulsionStats + sCurrDesign . asParts [ COMP_PROPULSION ] ) ;
/*Update the Power bar stats as the power to build will have changed */
intSetDesignPower ( & sCurrDesign ) ;
/*Update the body points */
intSetBodyPoints ( & sCurrDesign ) ;
/* update name if not customised */
2013-02-02 13:47:48 -08:00
if ( bTemplateNameCustomised = = false )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
sCurrDesign . name = GetDefaultTemplateName ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
}
/* Update the name in the edit box */
2013-02-02 13:47:48 -08:00
intSetEditBoxTextFromTemplate ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
}
else if ( id > = IDDES_EXTRASYSSTART & & id < = IDDES_EXTRASYSEND )
{
/* check whether can change template name */
2013-02-02 13:47:48 -08:00
bTemplateNameCustomised = desTemplateNameCustomised ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
// Extra component stats button has been pressed - clear the old button
if ( desCompID ! = 0 )
{
widgSetButtonState ( psWScreen , desCompID , 0 ) ;
}
// Now store the new stats
2013-05-13 13:20:49 -07:00
switch ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] - > compType )
2007-06-28 10:47:08 -07:00
{
case COMP_SENSOR :
// Calculate the index of the component
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_SENSOR ] =
2013-02-02 13:47:48 -08:00
( ( SENSOR_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) -
asSensorStats ;
2007-06-28 10:47:08 -07:00
// Reset the ECM, constructor and weapon and repair
// - defaults will be set when OK is hit
sCurrDesign . numWeaps = 0 ;
sCurrDesign . asWeaps [ 0 ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2007-06-28 10:47:08 -07:00
// Set the new stats on the display
intSetSystemForm ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) ;
break ;
case COMP_ECM :
// Calculate the index of the component
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_ECM ] =
2013-02-02 13:47:48 -08:00
( ( ECM_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) -
asECMStats ;
2007-06-28 10:47:08 -07:00
// Reset the Sensor, constructor and weapon and repair
// - defaults will be set when OK is hit
sCurrDesign . numWeaps = 0 ;
sCurrDesign . asWeaps [ 0 ] = 0 ;
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2007-06-28 10:47:08 -07:00
// Set the new stats on the display
intSetSystemForm ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) ;
break ;
case COMP_CONSTRUCT :
// Calculate the index of the component and repair
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_CONSTRUCT ] =
2013-02-02 13:47:48 -08:00
( ( CONSTRUCT_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) -
asConstructStats ;
2007-06-28 10:47:08 -07:00
// Reset the Sensor, ECM and weapon
2006-05-27 09:37:17 -07:00
// - defaults will be set when OK is hit
2007-06-28 10:47:08 -07:00
sCurrDesign . numWeaps = 0 ;
sCurrDesign . asWeaps [ 0 ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2006-05-27 09:37:17 -07:00
// Set the new stats on the display
2007-06-28 10:47:08 -07:00
intSetSystemForm ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) ;
break ;
case COMP_REPAIRUNIT :
// Calculate the index of the component
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_REPAIRUNIT ] =
2013-02-02 13:47:48 -08:00
( ( REPAIR_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) -
asRepairStats ;
2007-06-28 10:47:08 -07:00
// Reset the Sensor, ECM and weapon and construct
2006-05-27 09:37:17 -07:00
// - defaults will be set when OK is hit
2007-06-28 10:47:08 -07:00
sCurrDesign . numWeaps = 0 ;
sCurrDesign . asWeaps [ 0 ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_BRAIN ] = 0 ;
2013-02-02 13:47:48 -08:00
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2006-05-27 09:37:17 -07:00
// Set the new stats on the display
2007-06-28 10:47:08 -07:00
intSetSystemForm ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) ;
break ;
case COMP_BRAIN :
/* Calculate the index of the brain */
2006-05-27 09:37:17 -07:00
sCurrDesign . asParts [ COMP_BRAIN ] =
2013-02-02 13:47:48 -08:00
( ( BRAIN_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) -
asBrainStats ;
2007-06-28 10:47:08 -07:00
/* Reset the sensor, ECM and constructor and repair
- defaults will be set when OK is hit */
sCurrDesign . asParts [ COMP_SENSOR ] = 0 ;
sCurrDesign . asParts [ COMP_ECM ] = 0 ;
sCurrDesign . asParts [ COMP_CONSTRUCT ] = 0 ;
sCurrDesign . asParts [ COMP_REPAIRUNIT ] = 0 ;
2009-12-30 13:59:25 -08:00
sCurrDesign . numWeaps = 1 ;
sCurrDesign . asWeaps [ 0 ] =
2013-02-02 13:47:48 -08:00
( ( ( BRAIN_STATS * ) apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) - > psWeaponStat ) -
asWeaponStats ;
widgHide ( psWScreen , IDDES_WPABUTTON ) ;
widgHide ( psWScreen , IDDES_WPBBUTTON ) ;
2007-06-28 10:47:08 -07:00
/* Set the new stats on the display */
intSetSystemForm ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] ) ;
break ;
2013-05-13 13:20:49 -07:00
default :
ASSERT ( false , " Bad choice " ) ;
2007-06-28 10:47:08 -07:00
}
2009-12-30 20:45:51 -08:00
// Stop the button flashing
2013-02-02 13:47:48 -08:00
intSetButtonFlash ( IDDES_SYSTEMBUTTON , false ) ;
2007-06-28 10:47:08 -07:00
// Lock the new button
widgSetButtonState ( psWScreen , id , WBUT_LOCK ) ;
desCompID = id ;
// Update the propulsion stats as the droid weight will have changed
intSetPropulsionStats ( asPropulsionStats + sCurrDesign . asParts [ COMP_PROPULSION ] ) ;
// Update the Power bar stats as the power to build will have changed
intSetDesignPower ( & sCurrDesign ) ;
// Update the body points
intSetBodyPoints ( & sCurrDesign ) ;
/* update name if not customised */
2013-02-02 13:47:48 -08:00
if ( bTemplateNameCustomised = = false )
2007-06-28 10:47:08 -07:00
{
2013-05-12 14:50:57 -07:00
sCurrDesign . name = GetDefaultTemplateName ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
}
2007-03-16 11:47:07 -07:00
2007-06-28 10:47:08 -07:00
/* Update the name in the edit box */
2013-02-02 13:47:48 -08:00
intSetEditBoxTextFromTemplate ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
// do the callback if in the tutorial
if ( bInTutorial )
{
2013-05-13 13:20:49 -07:00
if ( apsExtraSysList [ id - IDDES_EXTRASYSSTART ] - > compType = = COMP_BRAIN )
2007-06-28 10:47:08 -07:00
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_COMMAND ) ;
}
else
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DESIGN_SYSTEM ) ;
}
}
}
else
{
switch ( id )
{
/* The four component clickable forms */
2010-06-27 12:12:18 -07:00
/* the six component clickable forms... */
2007-06-28 10:47:08 -07:00
case IDDES_WEAPONS :
desCompID = 0 ;
intSetDesignMode ( IDES_TURRET ) ;
break ;
2006-11-04 14:56:28 -08:00
case IDDES_WEAPONS_A :
desCompID = 0 ;
intSetDesignMode ( IDES_TURRET_A ) ;
break ;
case IDDES_WEAPONS_B :
desCompID = 0 ;
intSetDesignMode ( IDES_TURRET_B ) ;
break ;
2007-06-28 10:47:08 -07:00
case IDDES_COMMAND :
desCompID = 0 ;
break ;
case IDDES_SYSTEMS :
desCompID = 0 ;
intSetDesignMode ( IDES_SYSTEM ) ;
break ;
/* The name edit box */
case IDDES_NAMEBOX :
2013-05-12 14:50:57 -07:00
sCurrDesign . name = widgGetString ( psWScreen , IDDES_NAMEBOX ) ;
sstrcpy ( aCurrName , getName ( & sCurrDesign ) ) ;
2007-06-28 10:47:08 -07:00
break ;
case IDDES_BIN :
{
2013-02-02 13:47:48 -08:00
/* Find the template for the current button */
DROID_TEMPLATE * psTempl = templateFromButtonId ( droidTemplID ) ; // Does not return the first template, which is the empty template.
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
/* remove template if found */
if ( psTempl ! = NULL )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
SendDestroyTemplate ( psTempl , selectedPlayer ) ;
//update player template list.
for ( std : : list < DROID_TEMPLATE > : : iterator i = localTemplates . begin ( ) ; i ! = localTemplates . end ( ) ; + + i )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
if ( & * i = = psTempl )
{
//before deleting the template, need to make sure not being used in production
deleteTemplateFromProduction ( psTempl , selectedPlayer , ModeQueue ) ;
// Delete the template.
localTemplates . erase ( i ) ;
break ;
}
2007-06-28 10:47:08 -07:00
}
2006-05-27 09:37:17 -07:00
2013-02-02 13:47:48 -08:00
/* get previous template and set as current */
psTempl = templateFromButtonId ( droidTemplID - 1 , true ) ; // droidTemplID - 1 always valid (might be the first template), since droidTemplID is not the first template.
/* update local list */
desSetupDesignTemplates ( ) ;
/* Now update the droid template form */
widgDelete ( psWScreen , IDDES_TEMPLBASE ) ;
intAddTemplateForm ( psTempl ) ;
/* Set the new template */
sCurrDesign = * psTempl ;
2013-05-12 14:50:57 -07:00
sstrcpy ( aCurrName , getName ( psTempl ) ) ;
2013-02-02 13:47:48 -08:00
intSetEditBoxTextFromTemplate ( psTempl ) ;
intSetDesignStats ( & sCurrDesign ) ;
/* show body stats only */
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgReveal ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
/*Update the Power bar stats as the power to build will have changed */
intSetDesignPower ( & sCurrDesign ) ;
/*Update the body points */
intSetBodyPoints ( & sCurrDesign ) ;
/* show correct body component highlight */
widgDelete ( psWScreen , IDDES_RIGHTBASE ) ;
/* reset button states */
widgSetButtonState ( psWScreen , IDDES_SYSTEMBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_BODYBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_PROPBUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPABUTTON , 0 ) ;
widgSetButtonState ( psWScreen , IDDES_WPBBUTTON , 0 ) ;
desCompMode = IDES_NOCOMPONENT ;
intSetDesignMode ( IDES_BODY ) ;
}
break ;
2007-06-28 10:47:08 -07:00
}
2011-12-18 03:20:48 -08:00
case IDDES_STOREBUTTON :
sCurrDesign . stored = ! sCurrDesign . stored ; // Invert the current status
saveTemplate ( ) ;
break ;
2007-06-28 10:47:08 -07:00
case IDDES_SYSTEMBUTTON :
// Add the correct component form
switch ( droidTemplateType ( & sCurrDesign ) )
{
case DROID_COMMAND :
case DROID_SENSOR :
case DROID_CONSTRUCT :
case DROID_ECM :
case DROID_REPAIR :
intSetDesignMode ( IDES_SYSTEM ) ;
break ;
default :
intSetDesignMode ( IDES_TURRET ) ;
break ;
}
/* reveal components if not already onscreen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgReveal ( psWScreen , IDDES_RIGHTBASE ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
2007-06-28 10:47:08 -07:00
2006-11-04 14:56:28 -08:00
break ;
2013-02-02 13:47:48 -08:00
// WPABUTTON
2006-11-04 14:56:28 -08:00
case IDDES_WPABUTTON :
// Add the correct component form
switch ( droidTemplateType ( & sCurrDesign ) )
{
case DROID_COMMAND :
case DROID_SENSOR :
case DROID_CONSTRUCT :
case DROID_ECM :
case DROID_REPAIR :
break ;
default :
intSetDesignMode ( IDES_TURRET_A ) ;
break ;
}
/* reveal components if not already onscreen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgReveal ( psWScreen , IDDES_RIGHTBASE ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
2006-11-04 14:56:28 -08:00
break ;
2013-02-02 13:47:48 -08:00
// WPBBUTTON
2006-11-04 14:56:28 -08:00
case IDDES_WPBBUTTON :
// Add the correct component form
switch ( droidTemplateType ( & sCurrDesign ) )
{
case DROID_COMMAND :
case DROID_SENSOR :
case DROID_CONSTRUCT :
case DROID_ECM :
case DROID_REPAIR :
break ;
default :
intSetDesignMode ( IDES_TURRET_B ) ;
break ;
}
/* reveal components if not already onscreen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgReveal ( psWScreen , IDDES_RIGHTBASE ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
2006-11-04 14:56:28 -08:00
2007-06-28 10:47:08 -07:00
break ;
case IDDES_BODYBUTTON :
/* reveal components if not already onscreen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_RIGHTBASE ) ;
2007-06-28 10:47:08 -07:00
intSetDesignMode ( IDES_BODY ) ;
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
widgReveal ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
2007-06-28 10:47:08 -07:00
break ;
case IDDES_PROPBUTTON :
/* reveal components if not already onscreen */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_RIGHTBASE ) ;
2007-06-28 10:47:08 -07:00
intSetDesignMode ( IDES_PROPULSION ) ;
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgReveal ( psWScreen , IDDES_PROPFORM ) ;
2007-06-28 10:47:08 -07:00
2013-05-21 11:48:17 -07:00
break ;
case IDSTAT_OBSOLETE_BUTTON :
includeRedundantDesigns = ! includeRedundantDesigns ;
StateButton * obsoleteButton = ( StateButton * ) widgGetFromID ( psWScreen , IDSTAT_OBSOLETE_BUTTON ) ;
obsoleteButton - > setState ( includeRedundantDesigns ) ;
// Refresh lists.
if ( droidTemplID ! = IDDES_TEMPLSTART )
{
intRemoveDesign ( ) ;
intAddDesign ( false ) ;
}
else
{
desSetupDesignTemplates ( ) ;
widgDelete ( psWScreen , IDDES_TEMPLBASE ) ;
intAddTemplateForm ( templateFromButtonId ( droidTemplID ) ) ;
intSetDesignMode ( desCompMode , true ) ;
droidTemplID = IDDES_TEMPLSTART ;
widgSetButtonState ( psWScreen , droidTemplID , WBUT_LOCK ) ;
}
2007-06-28 10:47:08 -07:00
break ;
}
}
/* show body button if component button pressed and
* save template if valid
*/
2013-02-02 13:17:27 -08:00
if ( ( id > = IDDES_COMPSTART & & id < = IDDES_COMPEND ) | | ( id > = IDDES_EXTRASYSSTART & & id < = IDDES_EXTRASYSEND ) )
2007-06-28 10:47:08 -07:00
{
/* reveal body button if hidden */
2013-02-02 13:47:48 -08:00
widgReveal ( psWScreen , IDDES_BODYBUTTON ) ;
2007-06-28 10:47:08 -07:00
/* save template if valid */
if ( saveTemplate ( ) )
{
eventFireCallbackTrigger ( ( TRIGGER_TYPE ) CALL_DROIDDESIGNED ) ;
2013-01-16 13:49:17 -08:00
triggerEventDesignCreated ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:47:48 -08:00
switch ( desCompMode )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
case IDES_BODY :
widgReveal ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
break ;
case IDES_PROPULSION :
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgReveal ( psWScreen , IDDES_PROPFORM ) ;
widgHide ( psWScreen , IDDES_SYSTEMFORM ) ;
break ;
case IDES_SYSTEM :
case IDES_TURRET :
// reveals SYSTEMFORM
case IDES_TURRET_A :
case IDES_TURRET_B :
widgHide ( psWScreen , IDDES_BODYFORM ) ;
widgHide ( psWScreen , IDDES_PROPFORM ) ;
widgReveal ( psWScreen , IDDES_SYSTEMFORM ) ;
break ;
default :
break ;
}
widgReveal ( psWScreen , IDDES_STATSFORM ) ;
/* switch automatically to next component type if initial design */
if ( ! intValidTemplate ( & sCurrDesign , aCurrName , false , selectedPlayer ) )
{
/* show next component design screen */
switch ( desCompMode )
{
2007-06-28 10:47:08 -07:00
case IDES_BODY :
2013-02-02 13:47:48 -08:00
intSetDesignMode ( IDES_PROPULSION ) ;
widgReveal ( psWScreen , IDDES_PROPBUTTON ) ;
2007-06-28 10:47:08 -07:00
break ;
case IDES_PROPULSION :
2013-02-02 13:47:48 -08:00
intSetDesignMode ( IDES_TURRET ) ;
widgReveal ( psWScreen , IDDES_SYSTEMBUTTON ) ;
2007-06-28 10:47:08 -07:00
break ;
case IDES_SYSTEM :
case IDES_TURRET :
2013-02-02 13:47:48 -08:00
if ( ( asBodyStats + sCurrDesign . asParts [ COMP_BODY ] ) - > weaponSlots > 1 & &
sCurrDesign . numWeaps = = 1 & & sCurrDesign . asParts [ COMP_BRAIN ] = = 0 )
{
debug ( LOG_GUI , " intProcessDesign: First weapon selected, doing next. " ) ;
intSetDesignMode ( IDES_TURRET_A ) ;
widgReveal ( psWScreen , IDDES_WPABUTTON ) ;
}
else
{
debug ( LOG_GUI , " intProcessDesign: First weapon selected, is final. " ) ;
}
break ;
2006-11-04 14:56:28 -08:00
case IDES_TURRET_A :
2013-02-02 13:47:48 -08:00
if ( ( asBodyStats + sCurrDesign . asParts [ COMP_BODY ] ) - > weaponSlots > 2 )
{
debug ( LOG_GUI , " intProcessDesign: Second weapon selected, doing next. " ) ;
intSetDesignMode ( IDES_TURRET_B ) ;
widgReveal ( psWScreen , IDDES_WPBBUTTON ) ;
}
else
{
debug ( LOG_GUI , " intProcessDesign: Second weapon selected, is final. " ) ;
}
break ;
2006-11-04 14:56:28 -08:00
case IDES_TURRET_B :
2013-02-02 13:47:48 -08:00
debug ( LOG_GUI , " intProcessDesign: Third weapon selected, is final. " ) ;
2007-06-28 10:47:08 -07:00
break ;
default :
break ;
}
}
}
//save the template if the name gets edited
if ( id = = IDDES_NAMEBOX )
{
saveTemplate ( ) ;
}
}
/* Set the shadow bar graphs for the design screen */
void intRunDesign ( void )
{
UDWORD statID ;
2008-07-11 08:37:46 -07:00
COMPONENT_STATS * psStats ;
2011-03-12 17:32:15 -08:00
bool templateButton ;
2010-06-27 12:12:18 -07:00
int compIndex ;
2007-06-28 10:47:08 -07:00
/* Find out which button was hilited */
2008-03-24 09:51:17 -07:00
templateButton = false ;
2007-06-28 10:47:08 -07:00
statID = widgGetMouseOver ( psWScreen ) ;
2007-08-03 11:12:13 -07:00
// Somut around here is casuing a nasty crash.....
2007-06-28 10:47:08 -07:00
/* If a component button is hilited get the stats for it */
if ( statID = = desCompID )
{
/* The mouse is over the selected component - no shadow stats */
psStats = NULL ;
}
else if ( statID > = IDDES_COMPSTART & & statID < = IDDES_COMPEND )
{
2010-06-27 12:12:18 -07:00
compIndex = statID - IDDES_COMPSTART ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numComponent , " Invalid range referenced for numComponent, %d > %d " , compIndex , numComponent ) ;
2010-06-27 12:12:18 -07:00
psStats = apsComponentList [ compIndex ] ;
2007-06-28 10:47:08 -07:00
}
else if ( statID > = IDDES_EXTRASYSSTART & & statID < = IDDES_EXTRASYSEND )
{
2010-06-27 12:12:18 -07:00
compIndex = statID - IDDES_EXTRASYSSTART ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numExtraSys , " Invalid range referenced for numExtraSys, %d > %d " , compIndex , numExtraSys ) ;
2010-06-27 12:12:18 -07:00
psStats = apsExtraSysList [ compIndex ] ;
2007-06-28 10:47:08 -07:00
}
else if ( statID > = IDDES_TEMPLSTART & & statID < = IDDES_TEMPLEND )
{
runTemplateShadowStats ( statID ) ;
2008-03-24 09:51:17 -07:00
templateButton = true ;
2007-06-28 10:47:08 -07:00
psStats = NULL ;
}
else
{
/* No component button so reset the stats to nothing */
psStats = NULL ;
}
2006-05-27 09:37:17 -07:00
/* Now set the bar graphs for the stats - don't bother if over template
2007-06-28 10:47:08 -07:00
since setting them all ! */
if ( ! templateButton )
{
switch ( desCompMode )
{
case IDES_SYSTEM :
case IDES_TURRET :
intSetSystemShadowStats ( psStats ) ;
intSetBodyShadowStats ( NULL ) ;
intSetPropulsionShadowStats ( NULL ) ;
break ;
case IDES_BODY :
intSetSystemShadowStats ( NULL ) ;
intSetBodyShadowStats ( ( BODY_STATS * ) psStats ) ;
intSetPropulsionShadowStats ( NULL ) ;
break ;
case IDES_PROPULSION :
intSetSystemShadowStats ( NULL ) ;
intSetBodyShadowStats ( NULL ) ;
intSetPropulsionShadowStats ( ( PROPULSION_STATS * ) psStats ) ;
break ;
default :
break ;
}
//set the template shadow stats
intSetTemplateBodyShadowStats ( psStats ) ;
intSetTemplatePowerShadowStats ( psStats ) ;
}
}
2013-02-26 01:45:50 -08:00
static void intDisplayStatForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset )
2007-06-28 10:47:08 -07:00
{
static UDWORD iRY = 45 ;
2013-02-02 13:47:48 -08:00
W_CLICKFORM * Form = ( W_CLICKFORM * ) psWidget ;
2013-02-18 00:05:01 -08:00
UWORD x0 = xOffset + Form - > x ( ) , y0 = yOffset + Form - > y ( ) ;
2007-06-28 10:47:08 -07:00
/* get stats from userdata pointer in widget stored in
* intSetSystemStats , intSetBodyStats , intSetPropulsionStats
*/
2008-01-27 16:02:28 -08:00
BASE_STATS * psStats = ( BASE_STATS * ) Form - > pUserData ;
SWORD templateRadius = getComponentRadius ( psStats ) ;
2007-06-28 10:47:08 -07:00
2010-12-21 12:51:29 -08:00
Vector3i Rotation ( - 30 , iRY , 0 ) , Position ( 0 , - templateRadius / 4 , BUTTON_DEPTH /* templateRadius * 12 */ ) ;
2008-01-27 16:02:28 -08:00
//scale the object around the BUTTON_RADIUS so that half size objects are draw are draw 75% the size of normal objects
SDWORD falseScale = ( DESIGN_COMPONENT_SCALE * COMPONENT_RADIUS ) / templateRadius / 2 + ( DESIGN_COMPONENT_SCALE / 2 ) ;
2007-06-28 10:47:08 -07:00
2013-02-02 13:47:48 -08:00
iV_DrawImage ( IntImages , ( UWORD ) ( IMAGE_DES_STATBACKLEFT ) , x0 , y0 ) ;
2013-02-02 11:34:39 -08:00
iV_DrawImageRepeatX ( IntImages , IMAGE_DES_STATBACKMID , x0 + iV_GetImageWidth ( IntImages , IMAGE_DES_STATBACKLEFT ) , y0 ,
2013-02-18 00:05:01 -08:00
Form - > width ( ) - iV_GetImageWidth ( IntImages , IMAGE_DES_STATBACKLEFT ) - iV_GetImageWidth ( IntImages , IMAGE_DES_STATBACKRIGHT ) ) ;
iV_DrawImage ( IntImages , IMAGE_DES_STATBACKRIGHT , x0 + Form - > width ( ) - iV_GetImageWidth ( IntImages , IMAGE_DES_STATBACKRIGHT ) , y0 ) ;
2007-06-28 10:47:08 -07:00
/* display current component */
2013-02-18 00:05:01 -08:00
pie_SetGeometricOffset ( xOffset + psWidget - > width ( ) / 4 , yOffset + psWidget - > height ( ) / 2 ) ;
2007-06-28 10:47:08 -07:00
/* inc rotation if highlighted */
2013-02-18 11:50:37 -08:00
if ( ( Form - > getState ( ) & WBUT_HIGHLIGHT ) ! = 0 )
2007-06-28 10:47:08 -07:00
{
2012-01-28 23:55:22 -08:00
iRY + = realTimeAdjustedAverage ( BUTTONOBJ_ROTSPEED ) ;
2007-06-28 10:47:08 -07:00
iRY % = 360 ;
}
//display component in bottom design screen window
2013-10-19 15:24:15 -07:00
displayComponentButton ( psStats , & Rotation , & Position , falseScale ) ;
2007-06-28 10:47:08 -07:00
}
/* Displays the 3D view of the droid in a window on the design form */
2013-02-26 01:45:50 -08:00
static void intDisplayViewForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset )
2007-06-28 10:47:08 -07:00
{
2013-02-02 13:47:48 -08:00
W_FORM * Form = ( W_FORM * ) psWidget ;
UDWORD x0 , y0 , x1 , y1 ;
2007-06-28 10:47:08 -07:00
static UDWORD iRY = 45 ;
2007-03-16 09:20:16 -07:00
Vector3i Rotation , Position ;
2007-06-28 10:47:08 -07:00
SWORD templateRadius ;
SDWORD falseScale ;
2013-02-18 00:05:01 -08:00
x0 = xOffset + Form - > x ( ) ;
y0 = yOffset + Form - > y ( ) ;
x1 = x0 + Form - > width ( ) ;
y1 = y0 + Form - > height ( ) ;
2007-06-28 10:47:08 -07:00
2008-01-21 08:57:00 -08:00
RenderWindowFrame ( FRAME_NORMAL , x0 , y0 , x1 - x0 , y1 - y0 ) ;
2007-06-28 10:47:08 -07:00
2013-03-12 02:22:42 -07:00
if ( haveCurrentDesign )
2013-02-02 13:17:27 -08:00
{
2013-02-02 13:47:48 -08:00
pie_SetGeometricOffset ( ( DES_CENTERFORMX + DES_3DVIEWX ) + ( DES_3DVIEWWIDTH / 2 ) ,
( DES_CENTERFORMY + DES_3DVIEWY ) + ( DES_3DVIEWHEIGHT / 4 ) + 32 ) ;
2007-06-28 10:47:08 -07:00
Rotation . x = - 30 ;
Rotation . y = iRY ;
Rotation . z = 0 ;
/* inc rotation */
2012-01-28 23:55:22 -08:00
iRY + = realTimeAdjustedAverage ( BUTTONOBJ_ROTSPEED ) ;
2007-06-28 10:47:08 -07:00
iRY % = 360 ;
//fixed depth scale the pie
Position . x = 0 ;
Position . y = - 100 ;
Position . z = BUTTON_DEPTH ;
2013-03-12 02:22:42 -07:00
templateRadius = getComponentDroidTemplateRadius ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
//scale the object around the OBJECT_RADIUS so that half size objects are draw are draw 75% the size of normal objects
falseScale = ( DESIGN_DROID_SCALE * OBJECT_RADIUS ) / templateRadius ;
//display large droid view in the design screen
2013-10-19 15:24:15 -07:00
displayComponentButtonTemplate ( & sCurrDesign , & Rotation , & Position , falseScale ) ;
2007-06-28 10:47:08 -07:00
}
}
/* General display window for the design form SOLID BACKGROUND - NOT TRANSPARENT*/
2013-02-26 01:45:50 -08:00
static void intDisplayDesignForm ( WIDGET * psWidget , UDWORD xOffset , UDWORD yOffset )
2007-06-28 10:47:08 -07:00
{
2013-03-12 01:32:55 -07:00
int x0 = xOffset + psWidget - > x ( ) ;
int y0 = yOffset + psWidget - > y ( ) ;
int x1 = x0 + psWidget - > width ( ) ;
int y1 = y0 + psWidget - > height ( ) ;
2007-06-28 10:47:08 -07:00
2008-01-21 08:57:00 -08:00
RenderWindowFrame ( FRAME_NORMAL , x0 , y0 , x1 - x0 , y1 - y0 ) ;
2007-06-28 10:47:08 -07:00
}
2008-03-24 09:51:17 -07:00
/* save the current Template if valid. Return true if stored */
2011-02-13 09:57:25 -08:00
static bool saveTemplate ( void )
2007-06-28 10:47:08 -07:00
{
2013-01-21 13:17:58 -08:00
if ( ! intValidTemplate ( & sCurrDesign , aCurrName , false , selectedPlayer ) )
2011-02-13 09:57:25 -08:00
{
2011-12-18 03:20:48 -08:00
widgHide ( psWScreen , IDDES_STOREBUTTON ) ;
2011-02-13 09:57:25 -08:00
return false ;
}
2011-12-18 03:20:48 -08:00
widgReveal ( psWScreen , IDDES_STOREBUTTON ) ;
updateStoreButton ( sCurrDesign . stored ) ; // Change the buttons icon
2007-06-28 10:47:08 -07:00
/* if first (New Design) button selected find empty template
* else find current button template
*/
2011-02-13 09:57:25 -08:00
DROID_TEMPLATE * psTempl ;
if ( droidTemplID = = IDDES_TEMPLSTART )
2007-06-28 10:47:08 -07:00
{
2011-02-13 09:57:25 -08:00
/* create empty template and point to that */
localTemplates . push_back ( DROID_TEMPLATE ( ) ) ;
psTempl = & localTemplates . back ( ) ;
apsTemplateList . push_back ( psTempl ) ;
2007-06-28 10:47:08 -07:00
2011-02-13 09:57:25 -08:00
psTempl - > ref = REF_TEMPLATE_START ;
/* set button render routines to highlight, not flash */
intSetButtonFlash ( IDDES_SYSTEMBUTTON , false ) ;
intSetButtonFlash ( IDDES_BODYBUTTON , false ) ;
intSetButtonFlash ( IDDES_PROPBUTTON , false ) ;
2007-06-28 10:47:08 -07:00
}
else
{
/* Find the template for the current button */
2011-02-13 09:57:25 -08:00
psTempl = templateFromButtonId ( droidTemplID ) ;
if ( psTempl = = NULL )
2007-06-28 10:47:08 -07:00
{
2011-12-18 03:20:48 -08:00
debug ( LOG_ERROR , " Template not found for button " ) ;
2011-02-13 09:57:25 -08:00
return false ;
2007-06-28 10:47:08 -07:00
}
2011-02-13 09:57:25 -08:00
// ANY change to the template affect the production - even if the template is changed and then changed back again!
deleteTemplateFromProduction ( psTempl , selectedPlayer , ModeQueue ) ;
2011-12-27 06:02:42 -08:00
SendDestroyTemplate ( psTempl , selectedPlayer ) ;
2011-02-13 09:57:25 -08:00
}
2007-06-28 10:47:08 -07:00
2011-02-13 09:57:25 -08:00
/* Copy the template */
* psTempl = sCurrDesign ;
2007-06-28 10:47:08 -07:00
2011-02-13 09:57:25 -08:00
/* Now update the droid template form */
widgDelete ( psWScreen , IDDES_TEMPLBASE ) ;
intAddTemplateForm ( psTempl ) ;
2007-06-28 10:47:08 -07:00
2011-02-13 09:57:25 -08:00
// Send template to in-game template list, since localTemplates/apsDroidTemplates is for UI use only.
psTempl - > multiPlayerID = generateNewObjectId ( ) ;
sendTemplate ( selectedPlayer , psTempl ) ;
2007-06-28 10:47:08 -07:00
2011-02-13 09:57:25 -08:00
return true ;
2007-06-28 10:47:08 -07:00
}
2013-02-02 13:17:27 -08:00
/* Function to set the shadow bars for all the stats when the mouse is over the Template buttons */
2007-06-28 10:47:08 -07:00
void runTemplateShadowStats ( UDWORD id )
{
DROID_TEMPLATE * psTempl = NULL ;
2008-07-11 08:37:46 -07:00
COMPONENT_STATS * psStats ;
2007-06-28 10:47:08 -07:00
DROID_TYPE templType ;
2010-06-27 12:12:18 -07:00
int compIndex ;
2007-06-28 10:47:08 -07:00
/* Find the template for the new button */
2009-05-21 19:41:13 -07:00
//we're ignoring the Blank Design so start at the second button
2011-02-13 09:57:25 -08:00
psTempl = templateFromButtonId ( id ) ;
2007-06-28 10:47:08 -07:00
//if we're over a different template
2007-02-10 08:39:39 -08:00
if ( psTempl & & psTempl ! = & sCurrDesign )
2007-06-28 10:47:08 -07:00
{
/* Now set the bar graphs for the stats */
intSetBodyShadowStats ( asBodyStats + psTempl - > asParts [ COMP_BODY ] ) ;
intSetPropulsionShadowStats ( asPropulsionStats + psTempl - > asParts [ COMP_PROPULSION ] ) ;
//only set the system shadow bar if the same type of droid
psStats = NULL ;
templType = droidTemplateType ( psTempl ) ;
if ( templType = = droidTemplateType ( & sCurrDesign ) )
{
switch ( templType )
{
case DROID_WEAPON :
2010-06-27 12:12:18 -07:00
compIndex = psTempl - > asWeaps [ 0 ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numWeaponStats , " Invalid range referenced for numWeaponStats, %d > %d " , compIndex , numWeaponStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asWeaponStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_SENSOR :
2010-06-27 12:12:18 -07:00
compIndex = psTempl - > asParts [ COMP_SENSOR ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numSensorStats , " Invalid range referenced for numSensorStats, %d > %d " , compIndex , numSensorStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asSensorStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_ECM :
2010-06-27 12:12:18 -07:00
compIndex = psTempl - > asParts [ COMP_ECM ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numECMStats , " Invalid range referenced for numECMStats, %d > %d " , compIndex , numECMStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asECMStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_CONSTRUCT :
2010-06-27 12:12:18 -07:00
compIndex = psTempl - > asParts [ COMP_CONSTRUCT ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numConstructStats , " Invalid range referenced for numConstructStats, %d > %d " , compIndex , numConstructStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asConstructStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
case DROID_REPAIR :
2010-06-27 12:12:18 -07:00
compIndex = psTempl - > asParts [ COMP_REPAIRUNIT ] ;
2013-02-02 13:47:48 -08:00
ASSERT_OR_RETURN ( , compIndex < numRepairStats , " Invalid range referenced for numRepairStats, %d > %d " , compIndex , numRepairStats ) ;
2010-06-27 12:12:18 -07:00
psStats = ( COMPONENT_STATS * ) ( asRepairStats + compIndex ) ;
2007-06-28 10:47:08 -07:00
break ;
default :
break ;
}
}
if ( psStats )
{
intSetSystemShadowStats ( psStats ) ;
}
//haven't got a stat so just do the code required here...
2013-02-02 13:17:27 -08:00
widgSetMinorBarSize ( psWScreen , IDDES_BODYPOINTS , calcTemplateBody ( psTempl , selectedPlayer ) ) ;
widgSetMinorBarSize ( psWScreen , IDDES_POWERBAR , calcTemplatePower ( psTempl ) ) ;
2007-06-28 10:47:08 -07:00
}
}
/*sets which states need to be paused when the design screen is up*/
2011-12-29 08:13:04 -08:00
static void setDesignPauseState ( void )
2007-06-28 10:47:08 -07:00
{
if ( ! bMultiPlayer )
{
2007-11-12 11:08:55 -08:00
//need to clear mission widgets from being shown on design screen
clearMissionWidgets ( ) ;
2007-06-28 10:47:08 -07:00
gameTimeStop ( ) ;
2008-03-24 09:51:17 -07:00
setGameUpdatePause ( true ) ;
setScrollPause ( true ) ;
2009-03-08 05:40:42 -07:00
screen_RestartBackDrop ( ) ;
2007-06-28 10:47:08 -07:00
}
}
/*resets the pause states */
2011-12-29 08:13:04 -08:00
static void resetDesignPauseState ( void )
2007-06-28 10:47:08 -07:00
{
if ( ! bMultiPlayer )
{
2007-11-12 11:08:55 -08:00
//put any widgets back on for the missions
resetMissionWidgets ( ) ;
2008-03-24 09:51:17 -07:00
setGameUpdatePause ( false ) ;
setScrollPause ( false ) ;
2007-06-28 10:47:08 -07:00
gameTimeStart ( ) ;
2009-03-08 05:40:42 -07:00
screen_StopBackDrop ( ) ;
pie_ScreenFlip ( CLEAR_BLACK ) ;
2007-06-28 10:47:08 -07:00
}
}
/*this is called when a new propulsion type is added to the current design
2006-05-27 09:37:17 -07:00
to check the weapon is ' allowed ' . Check if VTOL , the weapon is direct fire .
2008-03-24 09:51:17 -07:00
Also check numVTOLattackRuns for the weapon is not zero - return true if valid weapon */
2011-03-12 17:32:15 -08:00
static bool intCheckValidWeaponForProp ( void )
2007-06-28 10:47:08 -07:00
{
2009-12-30 20:45:51 -08:00
if ( asPropulsionTypes [ ( ( PROPULSION_STATS * ) ( asPropulsionStats + sCurrDesign . asParts [ COMP_PROPULSION ] ) ) - > propulsionType ] . travel ! = AIR )
{
if ( sCurrDesign . numWeaps = = 0 & &
( sCurrDesign . asParts [ COMP_SENSOR ] | |
sCurrDesign . asParts [ COMP_REPAIRUNIT ] | |
sCurrDesign . asParts [ COMP_CONSTRUCT ] | |
sCurrDesign . asParts [ COMP_ECM ] ) )
{
// non-AIR propulsions can have systems, too.
return true ;
}
}
2009-05-21 19:41:13 -07:00
return checkValidWeaponForProp ( & sCurrDesign ) ;
2007-06-28 10:47:08 -07:00
}
2008-07-10 10:59:35 -07:00
//checks if the template has PROPULSION_TYPE_LIFT propulsion attached - returns true if it does
2011-03-12 17:32:15 -08:00
bool checkTemplateIsVtol ( DROID_TEMPLATE * psTemplate )
2007-06-28 10:47:08 -07:00
{
2009-05-21 19:41:13 -07:00
if ( asPropulsionStats [ psTemplate - > asParts [ COMP_PROPULSION ] ] .
2013-02-02 13:47:48 -08:00
propulsionType = = PROPULSION_TYPE_LIFT )
2009-05-21 19:41:13 -07:00
{
return true ;
}
else
{
return false ;
}
2007-06-28 10:47:08 -07:00
}
2011-12-18 03:20:48 -08:00
void updateStoreButton ( bool isStored )
{
UDWORD imageset ;
if ( isStored )
{
2011-12-18 13:32:09 -08:00
imageset = PACKDWORD_TRI ( 0 , IMAGE_DES_DELETEH , IMAGE_DES_DELETE ) ;
2013-02-12 00:31:49 -08:00
widgGetFromID ( psWScreen , IDDES_STOREBUTTON ) - > setTip ( _ ( " Delete Template " ) ) ;
2011-12-18 03:20:48 -08:00
}
else
{
2011-12-18 13:32:09 -08:00
imageset = PACKDWORD_TRI ( 0 , IMAGE_DES_SAVEH , IMAGE_DES_SAVE ) ;
2013-02-12 00:31:49 -08:00
widgGetFromID ( psWScreen , IDDES_STOREBUTTON ) - > setTip ( _ ( " Store Template " ) ) ;
2011-12-18 03:20:48 -08:00
}
widgSetUserData2 ( psWScreen , IDDES_STOREBUTTON , imageset ) ;
}