Permalink
Browse files

Do away with apsStaticTemplates completely, it caused multiple issues…

…. There is no difference in accessing the templates for the AI or Humans now. Only write templates out for active players. Make each template's group unique to each player. Fix clone wars templates. Remove hacky functions GetHumanDroidTemplate & GetAIDroidTemplate fixes ticket:3146 close ticket:3369

refs b99e845
refs 0cc7c31
  • Loading branch information...
1 parent d878966 commit 28c10b00a8f3bf6d87176e3aba8fba65993cedba @vexed vexed committed Apr 2, 2012
Showing with 133 additions and 240 deletions.
  1. +16 −28 src/droid.cpp
  2. +23 −20 src/game.cpp
  3. +34 −47 src/keybind.cpp
  4. +22 −11 src/multiplay.cpp
  5. +2 −1 src/scriptobj.cpp
  6. +36 −129 src/template.cpp
  7. +0 −4 src/template.h
View
@@ -1488,37 +1488,11 @@ bool loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
for (unsigned i = 0; i < table.size(); ++i)
{
LineView line(table, i);
-
- DROID_TEMPLATE *pTemplate;
std::string templateName = line.s(0);
- for (int player = 0; player < MAX_PLAYERS + 2; ++player)
+ for (int player = 0; player < MAX_PLAYERS ; ++player)
{
- if (player < MAX_PLAYERS) // a player
- {
- if (!isHumanPlayer(player))
- {
- continue; // no need to add to AIs, they use the static list
- }
- pTemplate = getTemplateFromUniqueName(templateName.c_str(), player);
- }
- else if (player == MAX_PLAYERS) // special exception - the static list
- {
- // Add weapons to static list
- pTemplate = getTemplateFromTranslatedNameNoPlayer(templateName.c_str());
- }
- else // Special exception - the local UI list.
- {
- pTemplate = NULL;
- for (std::list<DROID_TEMPLATE>::iterator j = localTemplates.begin(); j != localTemplates.end(); ++j)
- {
- if (j->pName == templateName)
- {
- pTemplate = &*j;
- break;
- }
- }
- }
+ DROID_TEMPLATE *pTemplate = getTemplateFromUniqueName(templateName.c_str(), player);
/* if Template not found - try default design */
if (!pTemplate)
@@ -1547,6 +1521,20 @@ bool loadDroidWeapons(const char *pWeaponData, UDWORD bufferSize)
//check valid weapon/propulsion
ASSERT_OR_RETURN(false, pTemplate->storeCount <= pTemplate->numWeaps, "Allocating more weapons than allowed for Template %s", templateName.c_str());
ASSERT_OR_RETURN(false, checkValidWeaponForProp(pTemplate), "Weapon is invalid for air propulsion for template %s", templateName.c_str());
+ if (player == selectedPlayer) // FIXME: can you say hack? Why don't we make a list on demmand ? This *will* break on player change!
+ {
+ DROID_TEMPLATE *pUITemplate = NULL;
+ for (std::list<DROID_TEMPLATE>::iterator j = localTemplates.begin(); j != localTemplates.end(); ++j)
+ {
+ if (j->pName == templateName)
+ {
+ pUITemplate = &*j;
+ // update UI template as well (it already passed the checks above)
+ pUITemplate->asWeaps[pTemplate->storeCount] = incWpn;
+ break;
+ }
+ }
+ }
pTemplate->storeCount++;
}
}
View
@@ -5519,28 +5519,31 @@ bool writeTemplateFile(const char *pFileName)
}
for (int player = 0; player < MAX_PLAYERS; player++)
{
- for (DROID_TEMPLATE *psCurr = apsDroidTemplates[player]; psCurr != NULL; psCurr = psCurr->psNext)
- {
- ini.beginGroup("template_" + QString::number(psCurr->multiPlayerID));
- ini.setValue("name", psCurr->aName);
- ini.setValue("ref", psCurr->ref);
- ini.setValue("droidType", psCurr->droidType);
- ini.setValue("multiPlayerID", psCurr->multiPlayerID);
- setPlayer(ini, player);
- ini.setValue("body", (asBodyStats + psCurr->asParts[COMP_BODY])->pName);
- ini.setValue("propulsion", (asPropulsionStats + psCurr->asParts[COMP_PROPULSION])->pName);
- ini.setValue("brain", (asBrainStats + psCurr->asParts[COMP_BRAIN])->pName);
- ini.setValue("repair", (asRepairStats + psCurr->asParts[COMP_REPAIRUNIT])->pName);
- ini.setValue("ecm", (asECMStats + psCurr->asParts[COMP_ECM])->pName);
- ini.setValue("sensor", (asSensorStats + psCurr->asParts[COMP_SENSOR])->pName);
- ini.setValue("construct", (asConstructStats + psCurr->asParts[COMP_CONSTRUCT])->pName);
- ini.setValue("weapons", psCurr->numWeaps);
- ini.setValue("enabled", psCurr->enabled);
- for (int j = 0; j < psCurr->numWeaps; j++)
+ if (apsDroidLists[player] || apsStructLists[player]) // only write out templates of players that are still 'alive'
+ {
+ for (DROID_TEMPLATE *psCurr = apsDroidTemplates[player]; psCurr != NULL; psCurr = psCurr->psNext)
{
- ini.setValue("weapon/" + QString::number(j + 1), (asWeaponStats + psCurr->asWeaps[j])->pName);
+ ini.beginGroup("template_" + QString::number(psCurr->multiPlayerID) + "_player" + QString::number(player));
+ ini.setValue("name", psCurr->aName);
+ ini.setValue("ref", psCurr->ref);
+ ini.setValue("droidType", psCurr->droidType);
+ ini.setValue("multiPlayerID", psCurr->multiPlayerID);
+ setPlayer(ini, player);
+ ini.setValue("body", (asBodyStats + psCurr->asParts[COMP_BODY])->pName);
+ ini.setValue("propulsion", (asPropulsionStats + psCurr->asParts[COMP_PROPULSION])->pName);
+ ini.setValue("brain", (asBrainStats + psCurr->asParts[COMP_BRAIN])->pName);
+ ini.setValue("repair", (asRepairStats + psCurr->asParts[COMP_REPAIRUNIT])->pName);
+ ini.setValue("ecm", (asECMStats + psCurr->asParts[COMP_ECM])->pName);
+ ini.setValue("sensor", (asSensorStats + psCurr->asParts[COMP_SENSOR])->pName);
+ ini.setValue("construct", (asConstructStats + psCurr->asParts[COMP_CONSTRUCT])->pName);
+ ini.setValue("weapons", psCurr->numWeaps);
+ ini.setValue("enabled", psCurr->enabled);
+ for (int j = 0; j < psCurr->numWeaps; j++)
+ {
+ ini.setValue("weapon/" + QString::number(j + 1), (asWeaponStats + psCurr->asWeaps[j])->pName);
+ }
+ ini.endGroup();
}
- ini.endGroup();
}
}
return true;
View
@@ -92,7 +92,7 @@
#include "clparse.h"
#include "research.h"
#include "template.h"
-
+#include "qtscript.h"
/*
KeyBind.c
Holds all the functions that can be mapped to a key.
@@ -342,13 +342,9 @@ DROID *psDroid;
void kf_CloneSelected( void )
{
- DROID *psDroid;
- DROID_TEMPLATE sTemplate;
- DROID_TEMPLATE *sTemplate2 = NULL;
+ DROID_TEMPLATE *sTemplate = NULL;
const int limit = 10; // make 10 clones
- int i;//, impact_side;
- //const char * msg;
-
+ const char *msg;
#ifndef DEBUG
// Bail out if we're running a _true_ multiplayer game (to prevent MP cheating)
if (runningMultiplayer())
@@ -358,61 +354,52 @@ void kf_CloneSelected( void )
}
#endif
- for (psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid=psDroid->psNext)
+ for (DROID *psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid=psDroid->psNext)
{
- for (i = 0; psDroid->selected && i < limit; i++)
+ if (psDroid->selected)
{
- // create a template based on the droid
- if (!sTemplate2)
+ for (DROID_TEMPLATE *psTempl = apsDroidTemplates[selectedPlayer]; psTempl; psTempl = psTempl->psNext)
{
- sTemplate2 = GetHumanDroidTemplate(psDroid->aName);
- if (!sTemplate2)
- { // we now search the AI template list (apsStaticTemplates)
- sTemplate2 = GetAIDroidTemplate(psDroid->aName);
+ if (!strcmp(psTempl->aName, psDroid->aName))
+ {
+ sTemplate = psTempl;
+ break;
}
}
- if (!sTemplate2)
+
+ if (!sTemplate)
{
- debug(LOG_ERROR, "We can't find the template for this droid: %s, id:%u, type:%d!", psDroid->aName, psDroid->id, psDroid->droidType);
+ debug(LOG_ERROR, "Cloning vat has been destoryed. We can't find the template for this droid: %s, id:%u, type:%d!", psDroid->aName, psDroid->id, psDroid->droidType);
return;
}
- sTemplate = *sTemplate2;
- templateSetParts(psDroid, &sTemplate);
-
- // create a new droid
- buildDroid(&sTemplate, psDroid->pos.x, psDroid->pos.y, psDroid->player, false, NULL);
- /* // TODO psNewDroid is null, since we just sent a message, but haven't actually created the droid locally yet.
- ASSERT_OR_RETURN(, psNewDroid != NULL, "Unable to build a unit");
- addDroid(psNewDroid, apsDroidLists);
- psNewDroid->body = psDroid->body;
- for (impact_side = 0; impact_side < NUM_HIT_SIDES; impact_side=impact_side+1)
- {
- psNewDroid->armour[impact_side][WC_KINETIC] = psDroid->armour[impact_side][WC_KINETIC];
- psNewDroid->armour[impact_side][WC_HEAT] = psDroid->armour[impact_side][WC_HEAT];
- }
- psNewDroid->experience = psDroid->experience;
- psNewDroid->rot.direction = psDroid->rot.direction;
- if (!(psNewDroid->droidType == DROID_PERSON || cyborgDroid(psNewDroid) || psNewDroid->droidType == DROID_TRANSPORTER || psNewDroid->droidType == DROID_SUPERTRANSPORTER))
+
+ // create a new droid army
+ for (int i = 0; i < limit; i++)
{
- updateDroidOrientation(psNewDroid);
+ DROID *psNewDroid = buildDroid(sTemplate, psDroid->pos.x + (i*12), psDroid->pos.y + (i*14), psDroid->player, false, NULL);
+ if (psNewDroid)
+ {
+ addDroid(psNewDroid, apsDroidLists);
+ psScrCBNewDroid = psNewDroid;
+ psScrCBNewDroidFact = NULL;
+ eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NEWDROID); // notify scripts so it will get assigned jobs
+ psScrCBNewDroid = NULL;
+ triggerEventDroidBuilt(psNewDroid, NULL);
+ }
+ else
+ {
+ debug(LOG_ERROR, "Cloning has failed for template:%s id:%d", sTemplate->pName, sTemplate->multiPlayerID);
+ }
}
- }
- if (psNewDroid)
- {
- // Send a text message to all players, notifying them of
- // the fact that we're cheating ourselves a new droid army
- sasprintf((char**)&msg, _("Player %u is cheating him/herself a new droid army of %s(s)."), selectedPlayer, psNewDroid->aName);
+ sasprintf((char**)&msg, _("Player %u is cheating a new droid army of: %s."), selectedPlayer, psDroid->aName);
sendTextMessage(msg, true);
- audio_PlayTrack(ID_SOUND_NEXUS_LAUGH1);
- sTemplate2 = NULL;
- psNewDroid->selected = true;
- psNewDroid = NULL;
Cheated = true;
- */
+ audio_PlayTrack(ID_SOUND_NEXUS_LAUGH1);
+ return;
}
+ debug(LOG_INFO, "Nothing was selected?");
}
}
-
// --------------------------------------------------------------------------
//
///* Prints out the date and time of the build of the game */
View
@@ -366,25 +366,36 @@ DROID_TEMPLATE *IdToTemplate(UDWORD tempId, UDWORD player)
DROID_TEMPLATE *psTempl = NULL;
UDWORD i;
- // First try static templates from scripts (could potentially also happen for currently human controlled players)
- for (psTempl = apsStaticTemplates; psTempl && psTempl->multiPlayerID != tempId; psTempl = psTempl->psNext) ;
- if (psTempl) return psTempl;
-
// Check if we know which player this is from, in that case, assume it is a player template
- if (player != ANYPLAYER && player < MAX_PLAYERS)
+ // FIXME: nuke the ANYPLAYER hack
+ if (player != ANYPLAYER && player < MAX_PLAYERS )
{
- for (psTempl = apsDroidTemplates[player]; psTempl && (psTempl->multiPlayerID != tempId); psTempl = psTempl->psNext) {} // follow templates
+ for (psTempl = apsDroidTemplates[player]; psTempl && (psTempl->multiPlayerID != tempId); psTempl = psTempl->psNext)
+ {} // follow templates
- return psTempl;
+ if (psTempl)
+ {
+ return psTempl;
+ }
+ else
+ {
+ return NULL;
+ }
}
- // We have no idea, so search through every player template
+ // It could be a AI template...or that of another player
for (i = 0; i < MAX_PLAYERS; i++)
{
- for (psTempl = apsDroidTemplates[i]; psTempl && psTempl->multiPlayerID != tempId; psTempl = psTempl->psNext) ;
- if (psTempl) return psTempl;
- }
+ for (psTempl = apsDroidTemplates[i]; psTempl && psTempl->multiPlayerID != tempId; psTempl = psTempl->psNext)
+ {} // follow templates
+ if (psTempl)
+ {
+ debug(LOG_NEVER, "Found template ID %d, for player %d, but found it in player's %d list?",tempId, player, i);
+ return psTempl;
+ }
+ }
+ // no error, since it is possible that we don't have this template defined yet.
return NULL;
}
View
@@ -976,10 +976,11 @@ bool scrValDefLoad(INTERP_VAL *psVal, WzConfig &ini)
psVal->v.oval = NULL;
if (ini.contains("data"))
{
+ // FIXME: Ugh. Find a better way to show full template info
psVal->v.oval = (void*)IdToTemplate(ini.value("data").toInt(), ANYPLAYER);
if ((DROID_TEMPLATE*)(psVal->v.oval) == NULL)
{
- debug(LOG_FATAL, "Could not find template");
+ debug(LOG_FATAL, "Could not find template %d", ini.value("data").toInt());
}
}
break;
Oops, something went wrong.

0 comments on commit 28c10b0

Please sign in to comment.