Ejemplo n.º 1
0
// ResolveAppends and ResolveIncludes must be called both
// for each script. ResolveAppends has to be called first!
BOOL C4AulScript::ResolveAppends(C4DefList *rDefs) {
  // resolve children appends
  for (C4AulScript *s = Child0; s; s = s->Next) s->ResolveAppends(rDefs);
  // resolve local appends
  if (State != ASS_PREPARSED) return FALSE;
  for (C4AListEntry *a = Appends; a; a = a->next()) {
    if ((long)a->Var != -1) {
      C4Def *Def = rDefs->ID2Def(C4ID(a->Var));
      if (Def)
        AppendTo(Def->Script, true);
      else {
        // save id in buffer because AulWarn will use the buffer of C4IdText
        // to get the id of the object in which the error occurs...
        // (stupid static buffers...)
        char strID[5];
        *strID = 0;
        strcpy(strID, C4IdText(C4ID(a->Var)));
        Warn("script to #appendto not found: ", strID);
      }
    } else {
      // append to all defs
      for (int i = 0; i < rDefs->GetDefCount(); i++) {
        C4Def *pDef = rDefs->GetDef(i);
        if (!pDef) break;
        if (pDef == Def) continue;
        // append
        AppendTo(pDef->Script, true);
      }
    }
  }
  return TRUE;
}
Ejemplo n.º 2
0
BOOL C4AulScript::ResolveIncludes(C4DefList *rDefs) {
  // resolve children includes
  for (C4AulScript *s = Child0; s; s = s->Next) s->ResolveIncludes(rDefs);
  // Had been preparsed?
  if (State != ASS_PREPARSED) return FALSE;
  // has already been resolved?
  if (IncludesResolved) return TRUE;
  // catch circular includes
  if (Resolving) {
    C4AulParseError(this,
                    "Circular include chain detected - ignoring all includes!")
        .show();
    IncludesResolved = true;
    State = ASS_LINKED;
    return FALSE;
  }
  Resolving = true;
  // append all includes to local script
  for (C4AListEntry *i = Includes; i; i = i->next()) {
    C4Def *Def = rDefs->ID2Def(C4ID(i->Var));
    if (Def) {
      // resolve #includes in included script first (#include-chains :( )
      if (!((C4AulScript &)Def->Script).IncludesResolved)
        if (!Def->Script.ResolveIncludes(rDefs))
          continue;  // skip this #include

      Def->Script.AppendTo(*this, false);
    } else {
      // save id in buffer because AulWarn will use the buffer of C4IdText
      // to get the id of the object in which the error occurs...
      // (stupid static buffers...)
      char strID[5];
      *strID = 0;
      strcpy(strID, C4IdText(C4ID(i->Var)));
      Warn("script to #include not found: ", strID);
    }
  }
  IncludesResolved = true;
  // includes/appends are resolved now (for this script)
  Resolving = false;
  State = ASS_LINKED;
  return TRUE;
}
Ejemplo n.º 3
0
void C4ID::CompileFunc(StdCompiler *pComp)
{
	if (pComp->isDecompiler())
	{
		assert(v < names.size());
		pComp->String(&names[v][0], names[v].size(), StdCompiler::RCT_ID);
	}
	else
	{
		char *data;
		pComp->String(&data, StdCompiler::RCT_ID);
		v = C4ID(data).v;
		StdBuf::DeletePointer(data);
	}
}
Ejemplo n.º 4
0
void c4_mapgen_handle_set_map_library(C4GroupHandle* group_handle)
{
	::Definitions.Clear();

	C4Def* libmap = new C4Def;
	libmap->id = C4ID(std::string("Library_Map"));
	libmap->SetName(libmap->id.ToString());
	libmap->Category = C4D_StaticBack;
	FakeSkeletonLoader loader;
	if(!libmap->Load(*HANDLE_TO_GROUP(group_handle), loader, C4D_Load_Script, NULL, NULL))
	{
		fprintf(stderr, "Failed to load Library_Map script\n");
		delete libmap;
	}
	else
	{
		::Definitions.Add(libmap, false);
	}
}
Ejemplo n.º 5
0
bool C4MainMenu::DoRefillInternal(bool &rfRefilled)
{
	// Variables
	C4FacetSurface fctSymbol;
	C4Player *pPlayer;
	C4IDList ListItems;
	C4Facet fctTarget;
	bool fWasEmpty = !GetItemCount();

	// Refill
	switch (Identification)
	{
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	case C4MN_Hostility:
	{
		// Clear items
		ClearItems();
		// Refill player
		if (!(pPlayer = ::Players.Get(Player))) return false;
		// Refill items
		C4Player *pPlr; int32_t iIndex;
		for (iIndex=0; (pPlr = ::Players.GetByIndex(iIndex)); iIndex++)
			// Ignore player self and invisible
			if (pPlr != pPlayer) if (!pPlr->IsInvisible())
				{
					// Symbol
					fctSymbol.Create(C4SymbolSize,C4SymbolSize);
					pPlayer->DrawHostility(fctSymbol,iIndex);
					// Message
					StdStrBuf sMsg;
					bool isFriendly = pPlayer->Hostility.find(pPlr) == pPlayer->Hostility.end();
					if (isFriendly)
						sMsg.Format(LoadResStr("IDS_MENU_ATTACK"),pPlr->GetName());
					else
						sMsg.Format(LoadResStr("IDS_MENU_NOATTACK"),pPlr->GetName());
					// Command
					char szCommand[1000];
					sprintf(szCommand,"SetHostility:%i",pPlr->Number);
					// Info caption
					char szInfoCaption[C4MaxTitle+1],szFriendly[50],szNot[30]="";
					SCopy(LoadResStr(isFriendly ? "IDS_MENU_ATTACKHOSTILE" : "IDS_MENU_ATTACKFRIENDLY"),szFriendly);
					if (!isFriendly) SCopy(LoadResStr("IDS_MENU_ATTACKNOT"),szNot);
					sprintf(szInfoCaption,LoadResStr("IDS_MENU_ATTACKINFO"),pPlr->GetName(),szFriendly,szNot);
					if (iIndex==pPlayer->Number) SCopy(LoadResStr("IDS_MENU_ATTACKSELF"),szInfoCaption);
					// Add item
					Add(sMsg.getData(),fctSymbol,szCommand,C4MN_Item_NoCount,NULL,szInfoCaption);
					fctSymbol.Default();
				}
		break;
	}
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	case C4MN_TeamSelection:
	case C4MN_TeamSwitch:
	{
		// Clear items
		ClearItems();
		// add all teams as menu items
		// 2do: Icon
		C4Team *pTeam; int32_t i=0; bool fAddNewTeam=Game.Teams.IsAutoGenerateTeams();
		for (;;)
		{
			pTeam = Game.Teams.GetTeamByIndex(i);
			if (pTeam)
			{
				// next regular team
				++i;
				// do not add a new team if an empty team exists
				if (!pTeam->GetPlayerCount()) fAddNewTeam = false;
			}
			else if (fAddNewTeam)
			{
				// join new team
				fAddNewTeam = false;
			}
			else
			{
				// all teams done
				break;
			}
			// create team symbol: Icon spec if specified; otherwise flag for empty and crew for nonempty team
			fctSymbol.Create(C4SymbolSize,C4SymbolSize);
			const char *szIconSpec = pTeam ? pTeam->GetIconSpec() : NULL;
			bool fHasIcon = false;
			if (szIconSpec && *szIconSpec)
			{
				fHasIcon = Game.DrawTextSpecImage(fctSymbol, szIconSpec, NULL, pTeam->GetColor());
			}
			if (!fHasIcon)
			{
				if (pTeam && pTeam->GetPlayerCount())
					::GraphicsResource.fctCrewClr.DrawClr(fctSymbol, true, pTeam->GetColor());
				else
					C4GUI::Icon::GetIconFacet(C4GUI::Ico_Team).Draw(fctSymbol, true);
			}
			StdStrBuf sTeamName;
			if (pTeam)
			{
				sTeamName.Take(pTeam->GetNameWithParticipants());
			}
			else
				sTeamName.Ref(LoadResStr("IDS_PRC_NEWTEAM"));
			const char *szOperation = (Identification == C4MN_TeamSwitch) ? "TeamSwitch" : "TeamSel";
			Add(sTeamName.getData(), fctSymbol,FormatString("%s:%d", szOperation, pTeam ? pTeam->GetID() : TEAMID_New).getData(),
			    C4MN_Item_NoCount,NULL,FormatString(LoadResStr("IDS_MSG_JOINTEAM"), sTeamName.getData()).getData(), C4ID(pTeam ? pTeam->GetID() : 0));
			fctSymbol.Default();
		}
		break;
	}
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	case C4MN_Observer: // observer menu
	{
		// Clear items
		ClearItems();
		// Check validity
		C4Viewport *pVP = ::Viewports.GetViewport(NO_OWNER);
		if (!pVP) return false;
		int32_t iInitialSelection = 0;
		// Add free view
		AddRefSym(LoadResStr("IDS_MSG_FREEVIEW"), C4GUI::Icon::GetIconFacet(C4GUI::Ico_Star), "Observe:Free", C4MN_Item_NoCount, NULL, LoadResStr("IDS_MSG_FREELYSCROLLAROUNDTHEMAP"));
		// Add players
		C4Player *pPlr; int32_t iIndex;
		for (iIndex=0; (pPlr = ::Players.GetByIndex(iIndex)); iIndex++)
		{
			// Ignore invisible
			if (!pPlr->IsInvisible())
			{
				// Symbol
				fctSymbol.Create(C4SymbolSize,C4SymbolSize);
				::GraphicsResource.fctPlayerClr.DrawClr(fctSymbol, true, pPlr->ColorDw);
				// Message
				StdStrBuf sMsg;
				DWORD dwClr = pPlr->ColorDw;
				sMsg.Format("<c %x>%s</c>", (unsigned int)C4GUI::MakeColorReadableOnBlack(dwClr), pPlr->GetName());
				// Command
				StdStrBuf sCommand;
				sCommand.Format("Observe:%d", (int)pPlr->Number);
				// Info caption
				StdStrBuf sInfo;
				sInfo.Format(LoadResStr("IDS_TEXT_FOLLOWVIEWOFPLAYER"), pPlr->GetName());
				// Add item
				Add(sMsg.getData(),fctSymbol,sCommand.getData(),C4MN_Item_NoCount,NULL,sInfo.getData());
				fctSymbol.Default();
				// check if this is the currently selected player
				if (pVP->GetPlayer() == pPlr->Number) iInitialSelection = GetItemCount()-1;
			}
			// Initial selection on followed player
			if (fWasEmpty) SetSelection(iInitialSelection, false, true);
		}
	}
	break;
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	default:
		// No internal refill needed
		return true;
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	}

	// Successfull internal refill
	rfRefilled = true;
	return true;
}