Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 471 lines (399 sloc) 11.568 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project

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
*/
/*
* multilimit.c
*
* interface for setting limits to the game, bots, structlimits etc...
*/
#include "lib/framework/frame.h"
#include "lib/framework/frameresource.h"
#include "lib/framework/strres.h"
#include "lib/widget/slider.h"
#include "lib/widget/widget.h"
#include "hci.h"
#include "intimage.h"
#include "intdisplay.h"
#include "init.h" // for gameheap
#include "frend.h"
#include "stats.h"
#include "frontend.h"
#include "component.h"
#include "loadsave.h"
#include "wrappers.h" // for loading screen
#include "lib/gamelib/gtime.h"
#include "console.h"
#include "lib/ivis_opengl/bitimage.h" // GFX incs
#include "lib/ivis_opengl/textdraw.h"
// FIXME Direct iVis implementation include!
#include "lib/ivis_opengl/piematrix.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/netplay/netplay.h"
#include "multiplay.h"
#include "multirecv.h"
#include "multiint.h"
#include "multilimit.h"
#include "lib/ivis_opengl/piemode.h"
#include "lib/script/script.h"
#include "challenge.h"

// ////////////////////////////////////////////////////////////////////////////
// defines
#define IDLIMITS 22000
#define IDLIMITS_RETURN (IDLIMITS+1)
#define IDLIMITS_OK (IDLIMITS+2)
#define IDLIMITS_TABS (IDLIMITS+3)
#define IDLIMITS_ENTRIES_START (IDLIMITS+4)
#define IDLIMITS_ENTRIES_END (IDLIMITS+99)

#define LIMITSX 25
#define LIMITSY 30
#define LIMITSW 580
#define LIMITSH 430

#define LIMITS_OKX (LIMITSW-90)
#define LIMITS_OKY (LIMITSH-42)

#define BARWIDTH 480
#define BARHEIGHT 40
#define BUTPERFORM 8

// ////////////////////////////////////////////////////////////////////////////
// protos.

static void displayStructureBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);

// ////////////////////////////////////////////////////////////////////////////

static bool useStruct(UDWORD count,UDWORD i)
{
ASSERT(i < numStructureStats, "Bad structure for structure limit: %d", (int)i);

if(count >= (4*BUTPERFORM))
{
return false;
}

// now see if we loaded that stat..
if(asStructLimits[0][i].globalLimit ==LOTS_OF)
{
return false;
}

return true;
}

// ////////////////////////////////////////////////////////////////////////////
static inline void freeLimitSet(void)
{
// Free the old set if required
if (ingame.numStructureLimits)
{
free(ingame.pStructureLimits);
ingame.numStructureLimits = 0;
ingame.pStructureLimits = NULL;
}
}

// ////////////////////////////////////////////////////////////////////////////
bool startLimitScreen(void)
{
UDWORD numButtons = 0;
UDWORD i;

addBackdrop();//background

// load stats...
if(!bLimiterLoaded)
{
initLoadingScreen(true);

if (!resLoad("wrf/limiter_tex.wrf", 501))
{
return false;
}

if (!resLoad("wrf/piestats.wrf", 502))
{
return false;
}

if (!resLoad("wrf/limiter_data.wrf", 503))
{
return false;
}

bLimiterLoaded = true;

closeLoadingScreen();
}

if (challengeActive)
{
// reset the sliders..
// it's a HACK since the actual limiter structure was cleared in the startMultiOptions function
for (i = 0; i < numStructureStats ; ++i)
{
asStructLimits[0][i].limit = asStructLimits[0][i].globalLimit;
}

// turn off the sliders
sliderEnableDrag(false);
}
else
{
//enable the sliders
sliderEnableDrag(true);
}

addSideText(FRONTEND_SIDETEXT1,LIMITSX-2,LIMITSY,"LIMITS"); // draw sidetext...

W_FORMINIT sFormInit;
sFormInit.formID = FRONTEND_BACKDROP;
sFormInit.id = IDLIMITS;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = LIMITSX;
sFormInit.y = LIMITSY;
sFormInit.width = LIMITSW;
sFormInit.height = LIMITSH;
sFormInit.pDisplay = intDisplayPlainForm;
widgAddForm(psWScreen, &sFormInit);

// return button.
addMultiBut(psWScreen,IDLIMITS,IDLIMITS_RETURN,
LIMITS_OKX-40,LIMITS_OKY,
iV_GetImageWidth(FrontImages,IMAGE_RETURN),
iV_GetImageHeight(FrontImages,IMAGE_RETURN),
_("Apply Defaults and Return To Previous Screen"),IMAGE_NO,IMAGE_NO,true);

// ok button
addMultiBut(psWScreen,IDLIMITS,IDLIMITS_OK,
LIMITS_OKX,LIMITS_OKY,
iV_GetImageWidth(FrontImages,IMAGE_OK),
iV_GetImageHeight(FrontImages,IMAGE_OK),
_("Accept Settings"),IMAGE_OK,IMAGE_OK,true);

// Count the number of minor tabs needed
numButtons = 0;

for(i=0;i<numStructureStats;i++ )
{
if(useStruct(numButtons,i))
{
numButtons++;
}
}

if(numButtons >(4*BUTPERFORM)) numButtons =(4*BUTPERFORM);

// add tab form..
sFormInit = W_FORMINIT();
sFormInit.formID = IDLIMITS;
sFormInit.id = IDLIMITS_TABS;
sFormInit.style = WFORM_TABBED;
sFormInit.x = 50;
sFormInit.y = 10;
sFormInit.width = LIMITSW - 100;
sFormInit.height =LIMITSH - 4;
sFormInit.numMajor = numForms(numButtons, BUTPERFORM);
sFormInit.majorPos = WFORM_TABTOP;
sFormInit.minorPos = WFORM_TABNONE;
sFormInit.majorSize = OBJ_TABWIDTH+3; //!!
sFormInit.majorOffset = OBJ_TABOFFSET;
sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2); //(DES_TAB_HEIGHT/2)+2;
sFormInit.tabMajorThickness = OBJ_TABHEIGHT;
sFormInit.pUserData = &StandardTab;
sFormInit.pTabDisplay = intDisplayTab;

// TABFIXME --unsure if needs fixing yet.
for (i=0; i< sFormInit.numMajor; i++)
{
sFormInit.aNumMinors[i] = 1;
}
widgAddForm(psWScreen, &sFormInit);

//Put the buttons on it
W_FORMINIT sButInit;
sButInit.formID = IDLIMITS_TABS;//IDLIMITS;
sButInit.style = WFORM_PLAIN;
sButInit.width = BARWIDTH;
sButInit.height = BARHEIGHT;
sButInit.pDisplay = displayStructureBar;
sButInit.x = 2;
sButInit.y = 5;
sButInit.id = IDLIMITS_ENTRIES_START;

numButtons =0;
for(i=0; i<numStructureStats ;i++)
{
if(useStruct(numButtons,i))
{
numButtons++;
sButInit.UserData= i;

widgAddForm(psWScreen, &sButInit);
sButInit.id ++;

addFESlider(sButInit.id,sButInit.id-1, 290,11,
asStructLimits[0][i].globalLimit,
asStructLimits[0][i].limit);
sButInit.id ++;

if (sButInit.y + BARHEIGHT + 2 > (BUTPERFORM*(BARHEIGHT+2) - 4) )
{
sButInit.y = 5;
sButInit.majorID += 1;
}
else
{
sButInit.y += BARHEIGHT +5;
}
}
}

return true;
}

// ////////////////////////////////////////////////////////////////////////////

void runLimitScreen(void)
{
UDWORD i, id, statid;

frontendMultiMessages(); // network stuff.

id = widgRunScreen(psWScreen); // Run the current set of widgets

// sliders
if((id > IDLIMITS_ENTRIES_START) && (id< IDLIMITS_ENTRIES_END))
{
statid = widgGetFromID(psWScreen,id-1)->UserData ;
if(statid)
{
asStructLimits[0][statid].limit = (UBYTE) ((W_SLIDER*)(widgGetFromID(psWScreen,id)))->pos;
}
}
else
{
// icons that are always about.
switch(id)
{
case IDLIMITS_RETURN:
// reset the sliders..
for (i = 0; i < numStructureStats ; ++i)
{
asStructLimits[0][i].limit = asStructLimits[0][i].globalLimit;
}
// free limiter structure
freeLimitSet();
//inform others
if (bHosted)
{
sendOptions();
}

eventReset();
changeTitleMode(MULTIOPTION);

// make some noize.
if(!ingame.localOptionsReceived)
{
addConsoleMessage(_("Limits reset to default values"),DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
}
else
{
sendTextMessage("Limits Reset To Default Values",true);
}

break;
case IDLIMITS_OK:
resetReadyStatus(false);
createLimitSet();
changeTitleMode(MULTIOPTION);
break;
default:
break;
}
}

widgDisplayScreen(psWScreen); // show the widgets currently running
}

// ////////////////////////////////////////////////////////////////////////////
void createLimitSet(void)
{
UDWORD i, numchanges = 0, bufSize, idx = 0;
MULTISTRUCTLIMITS *pEntry;

debug(LOG_NET, "LimitSet created");
// free old limiter structure
freeLimitSet();

// don't bother creating if a challenge mode is active
// there are no settings loaded from the .ini file for now...
if (challengeActive)
{
return;
}

// Count the number of changes
for (i = 0; i < numStructureStats; i++)
{
// If the limit differs from the default
if (asStructLimits[0][i].limit != LOTS_OF)
{
numchanges++;
}
}

// Allocate some memory for the changes
bufSize = numchanges * sizeof(MULTISTRUCTLIMITS);
pEntry = (MULTISTRUCTLIMITS *)malloc(bufSize);
memset(pEntry, 255, bufSize);

// Prepare chunk
ASSERT(numStructureStats < UBYTE_MAX, "Too many structure stats");
for (i = 0; i < numStructureStats; i++)
{
if (asStructLimits[0][i].limit != LOTS_OF)
{
ASSERT(idx < numchanges, "Bad number of changed limits");
pEntry[idx].id = i;
pEntry[idx].limit = asStructLimits[0][i].limit;
idx++;
}
}

ingame.numStructureLimits = numchanges;
ingame.pStructureLimits = pEntry;

if (bHosted)
{
sendOptions();
}
}

// ////////////////////////////////////////////////////////////////////////////
void applyLimitSet(void)
{
MULTISTRUCTLIMITS *pEntry = ingame.pStructureLimits;
unsigned int i;

if (ingame.numStructureLimits == 0)
{
return;
}

// Get the limits and decode
for (i = 0; i < ingame.numStructureLimits; ++i)
  {
UBYTE id = pEntry[i].id;

// So long as the ID is valid
if (id < numStructureStats)
{
unsigned int j;
for (j = 0; j < MAX_PLAYERS; ++j)
{
asStructLimits[j][id].limit = pEntry[i].limit;
}
}
}

freeLimitSet();
}

// ////////////////////////////////////////////////////////////////////////////

static void displayStructureBar(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{
UDWORD x = xOffset+psWidget->x;
UDWORD y = yOffset+psWidget->y;
UDWORD w = psWidget->width;
UDWORD h = psWidget->height;
STRUCTURE_STATS *stat = asStructureStats + psWidget->UserData;
Position position;
Vector3i rotation;
char str[20];

UDWORD scale,Radius;

drawBlueBox(x,y,w,h);

// draw image
pie_SetGeometricOffset( x+35 ,y+(psWidget->height/2)+9);
rotation.x = -15;
rotation.y = ((realTime/45)%360) ; //45
rotation.z = 0;
position.x = 0;
position.y = 0;
position.z = BUTTON_DEPTH*2;//getStructureStatSize(stat) * 38 * OBJECT_RADIUS;

Radius = getStructureStatSizeMax(stat);
if(Radius <= 128) {
scale = SMALL_STRUCT_SCALE;
} else if(Radius <= 256) {
scale = MED_STRUCT_SCALE;
} else {
scale = LARGE_STRUCT_SCALE;
}

pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
displayStructureStatButton(stat, &rotation, &position, true, scale);
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);

// draw name
iV_SetFont(font_regular); // font
iV_SetTextColour(WZCOL_TEXT_BRIGHT);
iV_DrawText(_(getName(stat->pName)), x + 80, y + (psWidget->height / 2) + 3);

// draw limit
ssprintf(str, "%d", ((W_SLIDER *)widgGetFromID(psWScreen, psWidget->id + 1))->pos);
iV_DrawText(str, x+270, y+(psWidget->height/2)+3);

return;
}
Something went wrong with that request. Please try again.