317
316
PROXIMITY_DISPLAY *psToAdd;
319
ASSERT(player < MAX_PLAYERS, "addProximityDisplay: Bad player");
318
ASSERT_OR_RETURN( , player < MAX_PLAYERS, "Bad player");
320
319
debug(LOG_MSG, "Added prox display for player %u (proxPos=%d)", player, (int)proxPos);
322
321
//create the proximity display
323
322
psToAdd = (PROXIMITY_DISPLAY*)malloc(sizeof(PROXIMITY_DISPLAY));
324
323
if (psToAdd == NULL)
326
ASSERT(false, "addProximityDisplay: out of memory");
325
ASSERT(false, "out of memory");
356
353
currentNumProxDisplays++;
359
/*remove a message */
356
/*remove a message */
360
357
void removeMessage(MESSAGE *psDel, UDWORD player)
362
ASSERT(player < MAX_PLAYERS, "removeMessage: Bad player");
363
ASSERT(psDel != NULL, "removeMessage: Bad message");
364
debug(LOG_MSG, "removeMessage: removing message for player %d", player);
359
ASSERT_OR_RETURN( , player < MAX_PLAYERS, "Bad player");
360
ASSERT_OR_RETURN( , psDel != NULL, "Bad message");
361
debug(LOG_MSG, "removing message for player %d", player);
366
363
if (psDel->type == MSG_PROXIMITY)
469
466
/*load the view data for the messages from the file */
470
467
VIEWDATA *loadViewData(const char *pViewMsgData, UDWORD bufferSize)
472
UDWORD i, id, dataInc, seqInc, numFrames, numData, count, count2;
469
UDWORD i, dataInc, seqInc, dummy, numData, count, count2;
473
470
VIEWDATA *psViewData, *pData;
474
471
VIEW_RESEARCH *psViewRes;
475
472
VIEW_REPLAY *psViewReplay;
546
542
sscanf(pViewMsgData,",%[^',']%n",name,&cnt);
549
//get the ID for the string
550
if (!strresGetIDNum(psStringRes, name, &id))
545
// Get the string from the ID string
546
psViewData->ppTextMsg[dataInc] = strresGetString(psStringRes, name);
547
if (!psViewData->ppTextMsg[dataInc])
552
ASSERT(false, "Cannot find the view data string id %s ", name);
549
ASSERT(!"Cannot find string resource", "Cannot find the view data string with id \"%s\"", name);
555
//get the string from the id
556
psViewData->ppTextMsg[dataInc] = strresGetString(psStringRes, id);
559
554
sscanf(pViewMsgData, ",%d%n", &readint, &cnt);
560
555
psViewData->type = readint;
563
558
//allocate data according to type
564
559
switch (psViewData->type)
575
570
string[0] = '\0';
576
571
audioName[0] = '\0';
577
572
sscanf(pViewMsgData,",%[^','],%[^','],%[^','],%[^','],%d%n",
578
imdName, imdName2, string, audioName, &numFrames,&cnt);
573
imdName, imdName2, string, audioName, &dummy, &cnt);
580
575
psViewRes = (VIEW_RESEARCH *)psViewData->pData;
581
576
psViewRes->pIMD = (iIMDShape *) resGetData("IMD", imdName);
582
577
if (psViewRes->pIMD == NULL)
584
ASSERT(LOG_ERROR, "Cannot find the PIE for message %s", name);
579
ASSERT(false, "Cannot find the PIE for message %s", name);
587
582
if (strcmp(imdName2, "0"))
598
593
psViewRes->pIMD2 = NULL;
600
strcpy(psViewRes->sequenceName, string);
595
sstrcpy(psViewRes->sequenceName, string);
601
596
//get the audio text string
602
597
if (strcmp(audioName, "0"))
605
psViewRes->pAudio = (char *) malloc(strlen(audioName) + 1);
600
psViewRes->pAudio = strdup(audioName);
606
601
if (psViewRes->pAudio == NULL)
608
603
ASSERT(false, "loadViewData - Out of memory");
611
strcpy(psViewRes->pAudio, audioName);
615
609
psViewRes->pAudio = NULL;
617
//this is for the PSX only
618
psViewRes->numFrames = (UWORD)numFrames;
667
659
else //extended type
669
661
sscanf(pViewMsgData, ",%[^','],%d,%d%n", name, &count, &count2,&cnt);
671
663
if (count > MAX_DATA)
673
ASSERT(false, "loadViewData: invalid video playback flag %s", psViewData->pName);
665
ASSERT(false, "invalid video playback flag %s", psViewData->pName);
676
668
psViewReplay->pSeqList[dataInc].flag = (UBYTE)count;
677
669
//check not loading up too many text strings
678
670
if (count2 > MAX_DATA)
680
ASSERT(false, "loadViewData: too many text strings for seq for %s", psViewData->pName);
672
ASSERT(false, "too many text strings for seq for %s", psViewData->pName);
683
675
psViewReplay->pSeqList[dataInc].numText = (UBYTE)count2;
699
691
sscanf(pViewMsgData,",%[^',']%n", name,&cnt);
701
//get the ID for the string
702
if (!strresGetIDNum(psStringRes, name, &id))
694
// Get the string from the ID string
695
psViewReplay->pSeqList[dataInc].ppTextMsg[seqInc] = strresGetString(psStringRes, name);
696
if (!psViewReplay->pSeqList[dataInc].ppTextMsg[seqInc])
704
ASSERT(false, "Cannot find the view data string id %s ", name);
698
ASSERT(!"Cannot find string resource", "Cannot find the view data string with id \"%s\"", name);
708
//get the string from the id
709
psViewReplay->pSeqList[dataInc].ppTextMsg[seqInc] = strresGetString(psStringRes, id);
711
702
//get the audio text string
712
sscanf(pViewMsgData,",%[^','],%d%n", audioName, &count,&cnt);
715
ASSERT( count < UWORD_MAX, "loadViewData: numFrames too high for %s", name );
717
psViewReplay->pSeqList[dataInc].numFrames = (UWORD)count;
703
sscanf(pViewMsgData,",%[^','],%d%n", audioName, &dummy, &cnt);
719
706
if (strcmp(audioName, "0"))
722
psViewReplay->pSeqList[dataInc].pAudio = (char *) malloc(
723
strlen(audioName) + 1);
709
psViewReplay->pSeqList[dataInc].pAudio = strdup(audioName);
724
710
if (psViewReplay->pSeqList[dataInc].pAudio == NULL)
726
712
ASSERT(LOG_ERROR, "loadViewData - Out of memory");
729
strcpy(psViewReplay->pSeqList[dataInc].pAudio, audioName);
782
ASSERT(false, "loadViewData: Negative X coord for prox message - %s",name);
769
ASSERT(false, "Negative X coord for prox message - %s",name);
785
772
((VIEW_PROXIMITY *)psViewData->pData)->x = (UDWORD)LocX;
788
ASSERT(false, "loadViewData: Negative Y coord for prox message - %s",name);
775
ASSERT(false, "Negative Y coord for prox message - %s",name);
791
778
((VIEW_PROXIMITY *)psViewData->pData)->y = (UDWORD)LocY;
794
ASSERT(false, "loadViewData: Negative Z coord for prox message - %s",name);
781
ASSERT(false, "Negative Z coord for prox message - %s",name);
797
784
((VIEW_PROXIMITY *)psViewData->pData)->z = (UDWORD)LocZ;
806
VIEWDATA* loadResearchViewData(const char* fileName)
810
VIEWDATA* psViewData;
812
input.type = LEXINPUT_PHYSFS;
813
input.input.physfsfile = PHYSFS_openRead(fileName);
814
debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName);
815
if (!input.input.physfsfile)
817
debug(LOG_ERROR, "PHYSFS_openRead(\"%s\") failed with error: %s\n", fileName, PHYSFS_getLastError());
821
message_set_extra(&input);
822
retval = (message_parse(&psViewData) == 0);
824
message_lex_destroy();
825
PHYSFS_close(input.input.physfsfile);
827
return retval ? psViewData : NULL;
819
830
/*get the view data identified by the name */
820
831
VIEWDATA * getViewData(const char *pName)
849
860
/* Release the viewdata memory */
850
861
void viewDataShutDown(VIEWDATA *psViewData)
852
VIEWDATA_LIST *psList, *psPrev;
854
VIEW_REPLAY *psViewReplay;
855
VIEW_RESEARCH *psViewRes;
858
psPrev = apsViewData;
860
for (psList = apsViewData; psList != NULL; psList = psList->psNext)
863
VIEWDATA_LIST *psList, **psPrev;
865
for (psList = apsViewData, psPrev = &apsViewData; psList != NULL; psPrev = &psList->psNext, psList = psList->psNext)
862
if (psList->psViewData == psViewData)
864
for (i = 0; i < psList->numViewData; i++)
866
psViewData = &psList->psViewData[i];
868
//check for any messages using this viewdata
869
checkMessages((MSG_VIEWDATA *)psViewData);
871
free(psViewData->pName);
872
psViewData->pName = NULL;
874
//free the space allocated for the text messages
875
if (psViewData->numText)
877
free(psViewData->ppTextMsg);
878
psViewData->ppTextMsg = NULL;
881
//free the space allocated for multiple sequences
882
if (psViewData->type == VIEW_RPL)
884
psViewReplay = (VIEW_REPLAY *)psViewData->pData;
885
if (psViewReplay->numSeq)
887
for (seqInc = 0; seqInc < psViewReplay->numSeq; seqInc++)
889
//free the space allocated for the text messages
890
if (psViewReplay->pSeqList[seqInc].numText)
892
free(psViewReplay->pSeqList[seqInc].ppTextMsg);
893
psViewReplay->pSeqList[seqInc].ppTextMsg = NULL;
895
if (psViewReplay->pSeqList[seqInc].pAudio)
897
free(psViewReplay->pSeqList[seqInc].pAudio);
898
psViewReplay->pSeqList[seqInc].pAudio = NULL;
901
free(psViewReplay->pSeqList);
902
psViewReplay->pSeqList = NULL;
905
else if (psViewData->type == VIEW_RES)
907
psViewRes = (VIEW_RESEARCH *)psViewData->pData;
908
if (psViewRes->pAudio)
910
free(psViewRes->pAudio);
911
psViewRes->pAudio = NULL;
914
free(psViewData->pData);
915
psViewData->pData = NULL;
917
free(psList->psViewData);
918
psList->psViewData = NULL;
920
//remove viewData list from the heap
921
if (psList == apsViewData)
923
apsViewData = psList->psNext;
928
psPrev->psNext = psList->psNext;
869
// Skip non-matching etnries
870
if (psList->psViewData != psViewData)
875
for (i = 0; i < psList->numViewData; ++i)
877
psViewData = &psList->psViewData[i];
879
//check for any messages using this viewdata
880
checkMessages((MSG_VIEWDATA *)psViewData);
882
free(psViewData->pName);
884
//free the space allocated for the text messages
885
if (psViewData->numText)
887
free(psViewData->ppTextMsg);
890
//free the space allocated for multiple sequences
891
if (psViewData->type == VIEW_RPL)
893
VIEW_REPLAY* const psViewReplay = (VIEW_REPLAY *)psViewData->pData;
894
if (psViewReplay->numSeq)
897
for (seqInc = 0; seqInc < psViewReplay->numSeq; ++seqInc)
899
//free the space allocated for the text messages
900
if (psViewReplay->pSeqList[seqInc].numText)
902
free(psViewReplay->pSeqList[seqInc].ppTextMsg);
904
if (psViewReplay->pSeqList[seqInc].pAudio)
906
free(psViewReplay->pSeqList[seqInc].pAudio);
909
free(psViewReplay->pSeqList);
912
else if (psViewData->type == VIEW_RES)
914
VIEW_RESEARCH* const psViewRes = (VIEW_RESEARCH *)psViewData->pData;
915
if (psViewRes->pAudio)
917
free(psViewRes->pAudio);
920
free(psViewData->pData);
922
free(psList->psViewData);
924
// remove viewData list from the list
925
*psPrev = psList->psNext;
928
/* Although we're a O(n) algorithm, lets not go for fullblown
929
* O(n) behaviour if not required.
937
935
/* Looks through the players list of messages to find one with the same viewData
1046
1044
//add proximity messages for all untapped VISIBLE oil resources
1047
1045
void addOilResourceProximities(void)
1052
//look thru the features to find oil resources
1053
for (psFeat = apsFeatureLists[0]; psFeat != NULL; psFeat = psFeat->psNext)
1055
if (psFeat->psStats->subType == FEAT_OIL_RESOURCE)
1057
//check to see if the feature is visible to the selected player
1058
if (psFeat->visible[selectedPlayer])
1060
//if there isn't an oil derrick built on it
1050
//look thru the features to find oil resources
1051
for (psFeat = apsFeatureLists[0]; psFeat != NULL; psFeat = psFeat->psNext)
1053
if (psFeat->psStats->subType == FEAT_OIL_RESOURCE)
1055
//check to see if the feature is visible to the selected player
1056
if (psFeat->visible[selectedPlayer])
1058
//if there isn't an oil derrick built on it
1061
1059
if (!TileHasStructure(mapTile(map_coord(psFeat->pos.x),
1062
1060
map_coord(psFeat->pos.y))))
1064
//add a proximity message
1062
//add a proximity message
1065
1063
psMessage = addMessage(MSG_PROXIMITY, true, selectedPlayer);
1068
1066
psMessage->pViewData = (MSG_VIEWDATA *)psFeat;