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 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
|
/*
* XFrisk - The classic board game for X
* Copyright (C) 1993-1999 Elan Feingold (elan@aetherworks.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: addPlayer.c,v 1.12 2000/01/23 18:37:44 tony Exp $
*
* $Log: addPlayer.c,v $
* Revision 1.12 2000/01/23 18:37:44 tony
* removed a debug printf
*
* Revision 1.11 2000/01/15 17:34:12 morphy
* Fixes to update color indicator to initial color and after editing color
*
* Revision 1.10 2000/01/10 22:47:39 tony
* made colorstuff more private to colormap.c, only scrollbars get set wrong, rest seems to work ok now
*
*
*
\file "Add player" dialog
*/
#include <X11/X.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Scrollbar.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Viewport.h>
#include <X11/Xaw/List.h>
#include <stdlib.h>
#include "addPlayer.h"
#include "colorEdit.h"
#include "client.h"
#include "utils.h"
#include "types.h"
#include "gui-vars.h"
#include "riskgame.h"
#include "callbacks.h"
#include "debug.h"
/* Private functions */
void PLAYER_EditColor(void);
void PLAYER_SetSpecies(Int32 iSpecies);
void PLAYER_SpeciesCreated(Int32 iSpecies);
void PLAYER_SpeciesDestroyed(Int32 iSpecies);
void PLAYER_RenderSpecies(void);
void PLAYER_Ok(void);
void PLAYER_Cancel(void);
void PLAYER_SelectSpecies(Widget w, XtPointer pData, XtPointer call_data);
Int32 PLAYER_SlotToSpecies(Int32 iSlot);
Int32 PLAYER_SpeciesToSlot(Int32 iSpecies);
/* Globals */
static Flag fPoppedUp = FALSE;
static String *ppstrStrings = NULL;
static Int32 *piSlotToSpecies = NULL;
static Int32 iCurrentSpecies = SPECIES_HUMAN;
static Int32 iNumSlots = 1;
Int32 r, g, b; /* really static? at least keep global */
/* Action tables */
static XtActionsRec actionTable[] =
{
{ "playerEditColor", (XtActionProc)PLAYER_EditColor },
{ "playerOk", (XtActionProc)PLAYER_Ok },
{ "playerCancel", (XtActionProc)PLAYER_Cancel },
{ NULL, NULL }
};
/* Widgets */
static Widget wAddPlayerShell;
static Widget wPlayerNameText;
static Widget wPlayerSpeciesListbox;
static Widget wPlayerDescText;
static Widget wPlayerVersionText;
static Widget wPlayerAuthorText;
static Widget wPlayerDummy1;
static Widget wPlayerDummy2;
static Widget wPlayerDummy3;
static Widget wPlayerDummy4;
static Widget wAddPlayerForm;
static Widget wPlayerNameLabel;
static Widget wPlayerSpeciesLabel;
static Widget wPlayerSpeciesViewport;
static Widget wPlayerAuthorLabel;
static Widget wPlayerVersionLabel;
static Widget wPlayerDescLabel;
static Widget wPlayerColorLabel;
static Widget wPlayerColorDisplay;
static Widget wPlayerOk;
static Widget wPlayerCancel;
/**
* Pick a color for this player
\par store in map
*/
void PLAYER_InitColor() {
r = rand() % 65536;
g = rand() % 65536;
b = rand() % 65536;
while ((r+g+b) < 120000)
{
r = r + (rand() % 30000);
g = g + (rand() % 30000);
b = b + (rand() % 30000);
}
if (r>=65536)
r = 65535;
if (g>=65536)
g = 65535;
if (b>=65536)
b = 65535;
COLOR_StoreColor(COLOR_DieToColor(0), r, g, b);
}
/************************************************************************
* FUNCTION: PLAYER_BuildDialog
* HISTORY:
* 01.29.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_BuildDialog(void)
{
wAddPlayerShell = XtCreatePopupShell("wAddPlayerShell",
transientShellWidgetClass,
wToplevel, pVisualArgs, iVisualCount);
/* The form */
wAddPlayerForm = XtCreateManagedWidget("wAddPlayerForm",
formWidgetClass, wAddPlayerShell,
NULL, 0);
/* Player name */
wPlayerNameLabel = XtCreateManagedWidget("wPlayerNameLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerNameText = XtVaCreateManagedWidget("wPlayerNameText",
asciiTextWidgetClass,
wAddPlayerForm,
XtNeditType, XawtextEdit,
NULL);
/* Player species */
wPlayerSpeciesLabel = XtCreateManagedWidget("wPlayerSpeciesLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerSpeciesViewport = XtCreateManagedWidget("wPlayerSpeciesViewport",
viewportWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerSpeciesListbox = XtVaCreateManagedWidget("wPlayerSpeciesListbox",
listWidgetClass,
wPlayerSpeciesViewport,
NULL);
XtAddCallback(wPlayerSpeciesListbox, XtNcallback, PLAYER_SelectSpecies,
NULL);
/* Player description */
wPlayerDummy1 = XtCreateManagedWidget("wPlayerDummy1",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerDescLabel = XtCreateManagedWidget("wPlayerDescLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerDescText = XtVaCreateManagedWidget("wPlayerDescText",
asciiTextWidgetClass,
wAddPlayerForm,
XtNwrap, XawtextWrapWord,
XtNautoFill, True,
NULL);
/* Player version */
wPlayerDummy2 = XtCreateManagedWidget("wPlayerDummy2",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerVersionLabel = XtCreateManagedWidget("wPlayerVersionLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerVersionText = XtCreateManagedWidget("wPlayerVersionText",
asciiTextWidgetClass,
wAddPlayerForm, NULL, 0);
/* Player author */
wPlayerAuthorLabel = XtCreateManagedWidget("wPlayerAuthorLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerAuthorText = XtCreateManagedWidget("wPlayerAuthorText",
asciiTextWidgetClass,
wAddPlayerForm, NULL, 0);
/* Player color */
wPlayerColorLabel = XtCreateManagedWidget("wPlayerColorLabel",
labelWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerColorDisplay = XtVaCreateManagedWidget("wPlayerColorDisplay",
labelWidgetClass,
wAddPlayerForm,
XtNbackground,
COLOR_QueryColor(COLOR_DieToColor(0)),
NULL);
/* Space */
wPlayerDummy3 = XtCreateManagedWidget("wPlayerDummy3", formWidgetClass,
wAddPlayerForm, NULL, 0);
/* OK and Cancel buttons */
wPlayerDummy4 = XtCreateManagedWidget("wPlayerDummy4", formWidgetClass,
wAddPlayerForm, NULL, 0);
wPlayerOk = XtCreateManagedWidget("wPlayerOk", commandWidgetClass,
wAddPlayerForm, NULL, 0);
XtAddCallback(wPlayerOk, XtNcallback, (XtCallbackProc)PLAYER_Ok, NULL);
wPlayerCancel = XtCreateManagedWidget("wPlayerCancel", commandWidgetClass,
wAddPlayerForm, NULL, 0);
XtAddCallback(wPlayerCancel, XtNcallback,
(XtCallbackProc)PLAYER_Cancel, NULL);
/* Add Actions */
XtAppAddActions(appContext, actionTable, XtNumber(actionTable));
/* Init the string table and mapping function */
ppstrStrings = (String *)MEM_Alloc(sizeof(String)*2);
ppstrStrings[0] = (String)MEM_Alloc(strlen(
RISK_GetNameOfSpecies(SPECIES_HUMAN))+1);
strcpy(ppstrStrings[0], RISK_GetNameOfSpecies(SPECIES_HUMAN));
ppstrStrings[1] = (String)NULL;
piSlotToSpecies = (Int32 *)MEM_Alloc(sizeof(Int32)*1);
piSlotToSpecies[0] = SPECIES_HUMAN;
}
/************************************************************************
* FUNCTION: PLAYER_PopupDialog
* HISTORY:
* 01.29.95 ESF Created.
* 02.26.95 ESF Fixed to generate brighter random colors.
* 04.30.95 ESF Fixed to generate even brighter random colors.
* 05.06.95 ESF Fixed a bug whereas the wrong species was highlighted.
* 15.01.00 MSH Fixed to update color indicator to initial color.
* PURPOSE:
* NOTES: called from "Register players"
************************************************************************/
void PLAYER_PopupDialog(void)
{
Int32 x, y;
/* Center the new shell */
UTIL_CenterShell(wAddPlayerShell, wToplevel, &x, &y);
XtVaSetValues(wAddPlayerShell,
XtNallowShellResize, False,
XtNx, x,
XtNy, y,
XtNborderWidth, 1,
XtNtitle, "Add Player",
NULL);
/* TBD: Could make sure here that COLOR_DieToColor(0) had a
* reasonable color for the new player, i.e. unique, nice...
* for now pick a random color...but not too dim!!
*/
PLAYER_InitColor();
/* Update the color indicator */
XtVaSetValues(wPlayerColorDisplay, XtNbackground,
COLOR_QueryColor(COLOR_DieToColor(0)), NULL);
/* Do the species stuff */
PLAYER_RenderSpecies();
PLAYER_SetSpecies(iCurrentSpecies);
XawListHighlight(wPlayerSpeciesListbox,
PLAYER_SpeciesToSlot(iCurrentSpecies));
/* Pop the dialog up, set the keyboard focus */
XtPopup(wAddPlayerShell, XtGrabExclusive);
fPoppedUp = TRUE;
XtSetKeyboardFocus(wToplevel, wPlayerNameText);
XtSetKeyboardFocus(wAddPlayerShell, wPlayerNameText);
}
/************************************************************************
* FUNCTION: PLAYER_Ok
* HISTORY:
* 01.29.94 ESF Created.
* 01.31.94 ESF Delete the strings after registering.
* 02.05.94 ESF Remove local registration from here.
* 02.05.94 ESF Adding color validity checking.
* 03.07.94 ESF Switched to varargs Xt calls.
* 03.08.94 ESF Fixed lack of NULL termination in XtVa calls.
* 05.04.94 ESF Fixed DistObj changes, added SetNumLivePlayers()
* 05.07.94 ESF Fixed to not let too many players register.
* 11.16.94 ESF Fixed to not send info to the server re. new player.
* 01.15.95 ESF Fixed to not allocate memory for the empty strings.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_Ok(void)
{
CString strPlayerName;
Int32 iNewPlayer;
XColor xColor;
char buf[256];
/* Get the name */
XtVaGetValues(wPlayerNameText, XtNstring, &strPlayerName, NULL);
/* Don't bother doing anything if something's not filled out */
if (!strlen(strPlayerName))
return;
/* See if there are too many players */
if ((iNewPlayer=CLNT_AllocPlayer(CBK_IncomingMessage)) == -1)
{
(void)UTIL_PopupDialog("Error", "Maximum number of players exceeded!",
1, "Ok", NULL, NULL);
return;
}
/* Get the XColor from the color index */
COLOR_GetColor(COLOR_DieToColor(0),
&xColor.red, &xColor.green, &xColor.blue);
snprintf(buf, sizeof(buf), "#%02x%02x%02x",
xColor.red/256, xColor.green/256, xColor.blue/256);
/* Init. the player */
RISK_SetColorCStringOfPlayer(iNewPlayer, buf);
RISK_SetSpeciesOfPlayer(iNewPlayer, iCurrentSpecies);
RISK_SetNameOfPlayer(iNewPlayer, strPlayerName);
/* If the client is human, then the client is this one, otherwise
* it's the AI client that registered it.
*/
if (iCurrentSpecies == SPECIES_HUMAN)
RISK_SetClientOfPlayer(iNewPlayer, CLNT_GetThisClientID());
else
RISK_SetClientOfPlayer(iNewPlayer,
RISK_GetClientOfSpecies(iCurrentSpecies));
/* This player is now finished. Note this */
RISK_SetAllocationStateOfPlayer(iNewPlayer, ALLOC_COMPLETE);
/* Make sure the name's erased */
XtVaSetValues(wPlayerNameText, XtNstring, "", NULL);
XtPopdown(wAddPlayerShell);
fPoppedUp = FALSE;
/* Reset keyboard focus */
XtSetKeyboardFocus(wToplevel, wToplevel);
}
/************************************************************************
* FUNCTION: PLAYER_Cancel
* HISTORY:
* 01.29.95 ESF Created.
* 02.12.95 ESF Finished.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_Cancel(void)
{
CString strName;
/* Make sure the player name widget
* is empty, popup warning if not.
*/
XtVaGetValues(wPlayerNameText, XtNstring, &strName, NULL);
if (strlen(strName))
if (UTIL_PopupDialog("Warning", "Discard current registration data?",
2, "Yes", "No", NULL) == QUERY_NO)
return;
XtPopdown(wAddPlayerShell);
/* Reset keyboard focus */
XtSetKeyboardFocus(wToplevel, wToplevel);
}
/************************************************************************
* FUNCTION: PLAYER_EditColor
* HISTORY:
* 01.29.95 ESF Created.
* 15.01.00 MSH Fixed to update color indicator widget after edit.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_EditColor(void)
{
/* Relinquish the keyboard focus */
XtUngrabKeyboard(wPlayerNameText, CurrentTime);
/* Popup the color editing dialog */
COLEDIT_EditColor(COLOR_DieToColor(0), FALSE);
/* Update the color indicator */
XtVaSetValues(wPlayerColorDisplay, XtNbackground,
COLOR_QueryColor(COLOR_DieToColor(0)), NULL);
/* Regain the keyboard focus */
while(XtGrabKeyboard(wPlayerNameText, True, GrabModeAsync, GrabModeAsync,
CurrentTime) == GrabNotViewable)
; /* TwiddleThumbs() */
}
/************************************************************************
* FUNCTION: PLAYER_SetSpecies
* HISTORY:
* 02.12.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_SetSpecies(Int32 iSpecies)
{
if ((RISK_GetNameOfSpecies(iSpecies)) == NULL)
{
printf("Warning: Illegal species (%d)\n", iSpecies);
return;
}
XtVaSetValues(wPlayerDescText, XtNstring,
RISK_GetDescriptionOfSpecies(iSpecies), NULL);
XtVaSetValues(wPlayerAuthorText, XtNstring,
RISK_GetAuthorOfSpecies(iSpecies), NULL);
XtVaSetValues(wPlayerVersionText, XtNstring,
RISK_GetVersionOfSpecies(iSpecies), NULL);
}
/************************************************************************
* FUNCTION: PLAYER_Callback
* HISTORY:
* 02.23.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_Callback(Int32 iMessType, void *pvMess)
{
/*
* SpeciesCreated --> Add species to species list
* SpeciesDestroyed --> Delete species from species list
*/
if (iMessType == MSG_OBJINTUPDATE &&
((MsgObjIntUpdate *)pvMess)->iField == SPE_ALLOCATION &&
((MsgObjIntUpdate *)pvMess)->iNewValue == ALLOC_COMPLETE)
{
/* SpeciesCreated */
PLAYER_SpeciesCreated(((MsgObjStrUpdate *)pvMess)->iIndex1);
}
else if (iMessType == MSG_OBJINTUPDATE &&
((MsgObjIntUpdate *)pvMess)->iField == SPE_ALLOCATION &&
((MsgObjIntUpdate *)pvMess)->iNewValue == ALLOC_NONE)
{
/* SpeciesDestroyed */
PLAYER_SpeciesDestroyed(((MsgObjIntUpdate *)pvMess)->iIndex1);
}
}
#define PAD_LENGTH 34
/************************************************************************
* FUNCTION: PLAYER_RenderSpecies
* HISTORY:
* 02.23.95 ESF Created.
* 03.03.95 ESF Finished.
* 04.01.95 ESF Fixed a bug, needed parens around iNumSpecies+1.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_RenderSpecies(void)
{
/* This is just a first approximation of a future, perhaps much
* faster or smarter version. This one does its job, though...
*/
XawListReturnStruct *pItem;
Int32 i, j, k, iLastSelection, iLastSpecies;
Int32 iNumSpecies = RISK_GetNumSpecies();
CString *ppstr = (CString *)MEM_Alloc(sizeof(CString)*(iNumSpecies+1));
Int32 *piMap = (Int32 *)MEM_Alloc(sizeof(Int32)*iNumSpecies);
CString str;
for (i=j=0; i<RISK_GetNumSpecies(); i++, j++)
{
/* Find the next live species */
while(RISK_GetAllocationStateOfSpecies(j) == FALSE)
j++;
str = RISK_GetNameOfSpecies(j);
D_Assert(str, "Null species.");
/* Add it to the list, with a padding of spaces */
ppstr[i] = MEM_Alloc(sizeof(Char)*PAD_LENGTH);
strcpy(ppstr[i], str);
for(k=strlen(str); k<PAD_LENGTH-1; k++)
ppstr[i][k] = ' ';
ppstr[i][k] = '\0';
/* Add the mapping from slot to species */
piMap[i] = j;
}
ppstr[i] = (String)NULL;
/* Find out the last selection */
pItem = XawListShowCurrent(wPlayerSpeciesListbox);
iLastSelection = pItem->list_index;
iLastSpecies = PLAYER_SlotToSpecies(iLastSelection);
XtFree((void *)pItem);
/* Display the list! */
XtVaSetValues(wPlayerSpeciesListbox,
XtNlist, ppstr,
XtNnumberStrings, iNumSpecies,
NULL);
/* If there were old strings, free all of the memory */
if (ppstrStrings)
{
for (i=0; i!=iNumSlots; i++)
MEM_Free(ppstrStrings[i]);
MEM_Free(ppstrStrings);
}
if (piSlotToSpecies)
MEM_Free(piSlotToSpecies);
/* Keep the new list of strings and the new mapping */
ppstrStrings = ppstr;
piSlotToSpecies = piMap;
iNumSlots = iNumSpecies;
/* Select the last species if it's still around */
if ((iLastSpecies = PLAYER_SpeciesToSlot(iLastSpecies)) != -1)
XawListHighlight(wPlayerSpeciesListbox, iLastSpecies);
else
XawListHighlight(wPlayerSpeciesListbox,
MIN(iLastSelection, iNumSpecies-1));
}
/************************************************************************
* FUNCTION: PLAYER_SpeciesDestroyed
* HISTORY:
* 02.23.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_SpeciesDestroyed(Int32 iSpecies)
{
UNUSED(iSpecies);
if (fPoppedUp == TRUE)
PLAYER_RenderSpecies();
}
/************************************************************************
* FUNCTION: PLAYER_SpeciesCreated
* HISTORY:
* 02.23.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_SpeciesCreated(Int32 iSpecies)
{
UNUSED(iSpecies);
if (fPoppedUp == TRUE)
PLAYER_RenderSpecies();
}
/************************************************************************
* FUNCTION: PLAYER_SelectSpecies
* HISTORY:
* 03.03.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
void PLAYER_SelectSpecies(Widget w, XtPointer pData, XtPointer call_data)
{
const XawListReturnStruct *pItem =
XawListShowCurrent(wPlayerSpeciesListbox);
const Int32 iIndex = pItem->list_index;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
/* Free up memory */
XtFree((void *)pItem);
/* If it's off any of the species, then set the one that was set */
if (iIndex == -1)
{
PLAYER_SetSpecies(iCurrentSpecies);
XawListHighlight(wPlayerSpeciesListbox,
PLAYER_SpeciesToSlot(iCurrentSpecies));
return;
}
/* Find out what species it is */
iCurrentSpecies = PLAYER_SlotToSpecies(iIndex);
/* Put in the description, author, etc. */
PLAYER_SetSpecies(iCurrentSpecies);
}
/************************************************************************
* FUNCTION: PLAYER_SlotToSpecies
* HISTORY:
* 03.03.95 ESF Created.
* PURPOSE:
* NOTES:
************************************************************************/
Int32 PLAYER_SlotToSpecies(Int32 iSlot)
{
D_Assert(iSlot>=-1, "Wierd slot!");
D_Assert(piSlotToSpecies, "No mapping!");
/* This means that the user has clicked off of any slot */
if (iSlot == -1)
return iCurrentSpecies;
return piSlotToSpecies[iSlot];
}
/************************************************************************
* FUNCTION: PLAYER_SpeciesToSlot
* HISTORY:
* 03.03.95 ESF Created.
* 05.13.95 ESF Fixed to not return error.
* PURPOSE:
* NOTES:
************************************************************************/
Int32 PLAYER_SpeciesToSlot(Int32 iSpecies)
{
Int32 i;
for (i=0;
ppstrStrings[i]!=NULL;
i++)
{
if (piSlotToSpecies[i] == iSpecies)
return i;
}
/* The species doesn't exist, return SPECIES_HUMAN */
iCurrentSpecies = SPECIES_HUMAN;
return iCurrentSpecies;
}
|