92 if (!tobj)
return false;
94 if (cobj==tobj)
return true;
121 if (!pInfo)
return false;
140 if (pPrevTeam != pTeam && idTeam)
147 if (!pTeam && idTeam)
154 if (pTeam) pTeam->
AddPlayer(*pInfo,
true);
169 int32_t idSelectedTeam;
187 int32_t idSelectedTeam = atoi(pSelectedTeamItem->
GetCommand()+8);
194 if (iPlrStartIndex && Inside<int32_t>(iPlrStartIndex, 1,
C4S_MaxPlayer))
257 bool C4Player::Init(int32_t iNumber, int32_t iAtClient,
const char *szAtClientName,
263 LogF(
"ERROR: Init player %s failed: No info!", szFilename);
280 if (!
Load(szFilename, !fScenarioInit))
return false;
345 if (idCallback && (pDefCallback =
C4Id2Def(idCallback)))
402 if ((pObj->lightRange || pObj->lightFadeoutRange) && pObj->Owner ==
NO_OWNER)
444 if (!hGroup.
Open(szPath,
true))
448 { hGroup.
Close();
return false; }
450 if (!hGroup.
Close())
return false;
454 bool fOfficial = pRes &&
::Control.isCtrlHost();
455 if (pRes) pDRes = pRes->
Derive();
460 if (pDRes && fOfficial) pDRes->FinishDerive();
473 { hGroup.
Close();
return false; }
492 iCount = std::max<int32_t>(iCount,1);
494 for (int32_t cnt2=0; cnt2<iCount; cnt2++)
501 if (!pInfo || !(pDef=
C4Id2Def(pInfo->
id)))
continue;
503 ctx=tx1+
Random(tx2-tx1); cty=ty;
512 nobj->
SetLightRange(C4FOW_DefLightRangeX, C4FOW_DefLightFadeoutRangeX);
529 int32_t cnt,cnt2,ctx,cty;
546 { *pFirstBase=cbase; tx=(*pFirstBase)->
GetX(); ty=(*pFirstBase)->GetY(); }
554 int32_t cnt,cnt2,ctx,cty;
561 ctx=tx1+
Random(tx2-tx1); cty=ty;
575 int32_t cnt,cnt2,ctx,cty;
592 ctx=tx1+
Random(tx2-tx1); cty=ty;
611 if (!pInfo) { assert(
false);
LogF(
"Internal error: ScenarioInit for ghost player %s!",
GetName());
return false; }
643 int PrefPosition = 0;
652 int32_t iPosition=iStartPos;
657 iPosition %= iMaxPos;
658 if (iPosition == iStartPos)
743 if (iVal ==
Wealth)
return true;
745 Wealth=Clamp<int32_t>(iVal,0,1000000000);
757 if (iIndex<0)
return false;
772 if (immediate_position)
792 const int32_t SuccessBonus=100;
840 assert(hostile == 0 || hostile == 1);
843 if (!opponent || opponent ==
this)
863 if (!plr)
return false;
870 int32_t iHighestExp=-2, iExp;
873 if (!cobj->CrewDisabled)
876 if (!hiexp || (iExp>iHighestExp))
889 int32_t iHighestRank=-2, iRank;
892 if (!cobj->CrewDisabled)
894 if (cobj->Info) iRank = cobj->
Info->
Rank;
else iRank=-1;
895 if (!hirank || (iRank>iHighestRank))
923 bool fHostile = (pPlr->Team !=
Team);
925 pPlr->SetHostility(
Number, fHostile,
true);
931 if (!szMsg)
return false;
941 if (!
Reloc.
Open(hGroup, szFilename))
return false;
946 { hGroup.
Close();
return false; }
961 if (!Grp.
Open(szFilename))
967 size_t iBigIconSize=0;
985 !Grp.
Open(szFilename,
true))
1014 if (!pObj->
Info && fForceInfo)
1037 pObj->
SetLightRange(C4FOW_DefLightRangeX, C4FOW_DefLightFadeoutRangeX);
1134 const char *pSource;
1142 if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(
1155 const int32_t MaxBaseProduction = 25;
1268 pCheck->CallbackObj.DenumeratePointers();
1288 if (iPlrID && iPlrID !=
ID)
1291 if (pPlrInfo)
if (pPlrInfo->
IsJoined())
1304 if (pOtherPlr !=
this)
if (!pOtherPlr->Eliminated)
1306 iNewOwner = pOtherPlr->Number;
1319 if (cobj->Status && cobj->Owner ==
Number)
1325 pFn->
Exec(cobj, &pars);
1335 cobj->SetOwner(iNewOwner);
1352 bool fChanged = pObj !=
Cursor;
1357 if (pPrev && fChanged) pPrev->
UnSelect();
1420 LogF(
"No gamepad available for %s, please plug one in!",
Name.
getData());
1436 bool C4Player::FindGamepad()
1439 if (!newPad)
return false;
1440 newPad->SetPlayer(
ID);
1453 int st = std::max(1, std::max(
Abs(sx - cx),
Abs(sy - cy)));
1454 for (
int i = 0; i <= st; i++)
1456 int x = (sx * (st - i) + cx * i) / st, y = (sy * (st - i) + cy * i) / st;
1459 if ((iVis -= 2) <= 0)
1502 if (!cObj->CrewDisabled)
1542 pInf->TotalPlayingTime+=(
Game.
Time-pInf->InActionTime);
1581 pCrew->
Info =
nullptr;
1652 void C4Player::ExecMsgBoardQueries()
1658 while (pCheck)
if (!pCheck->
fAnswered)
break;
else pCheck = pCheck->
pNext;
1659 if (!pCheck)
return;
1670 while (*ppTarget) ppTarget = &((*ppTarget)->pNext);
1678 while (*ppCheck)
if ((*ppCheck)->CallbackObj == pForObj)
break;
else ppCheck = &((*ppCheck)->pNext);
1680 if (!pFound)
return false;
1682 *ppCheck = (*ppCheck)->
pNext;
1692 if (!pCheck)
return false;
1714 if (dwNewClr ==
ColorDw)
return;
1720 if (pObj && pObj->Status && pObj->Owner ==
Number)
1722 if ((pObj->Color & 0xffffff) == (dwOldClr & 0xffffff))
1723 pObj->Color = (pObj->Color & 0xff000000u) | (dwNewClr & 0xffffff);
1731 if (pInfo)
return pInfo->
GetType();
else { assert(
false);
return C4PT_User; }
1738 if (pInfo)
return pInfo->
IsInvisible();
else { assert(
false);
return false; }
1771 int entries = size();
1775 pComp->
Value(entries);
1779 pComp->
Value(number);
1788 pComp->
Value(entries);
1789 for (
auto it : *
this)
1791 int32_t num = it->Number;
1799 AdjustZoomParameter(&
ZoomWdt, range_wdt, no_increase, no_decrease);
1800 AdjustZoomParameter(&
ZoomHgt, range_hgt, no_increase, no_decrease);
1806 AdjustZoomParameter(&
ZoomLimitMinWdt, range_wdt, no_increase, no_decrease);
1807 AdjustZoomParameter(&
ZoomLimitMinHgt, range_hgt, no_increase, no_decrease);
1813 AdjustZoomParameter(&
ZoomLimitMaxWdt, range_wdt, no_increase, no_decrease);
1814 AdjustZoomParameter(&
ZoomLimitMaxHgt, range_hgt, no_increase, no_decrease);
1820 AdjustZoomParameter(&
ZoomVal, zoom, no_increase, no_decrease);
1826 AdjustZoomParameter(&
ZoomLimitMinVal, zoom, no_increase, no_decrease);
1832 AdjustZoomParameter(&
ZoomLimitMaxVal, zoom, no_increase, no_decrease);
1847 if (new_zoom > old_zoom && no_increase)
return;
1848 if (new_zoom < old_zoom && no_decrease)
return;
1849 vp->
SetZoom(new_zoom, direct);
1866 bool C4Player::AdjustZoomParameter(int32_t *range_par, int32_t new_val,
bool no_increase,
bool no_decrease)
1869 if (new_val < *range_par)
1871 if (!no_decrease) *range_par = new_val;
1872 return !no_decrease;
1874 else if(new_val > *range_par)
1876 if (!no_increase) *range_par = new_val;
1877 return !no_increase;
1882 bool C4Player::AdjustZoomParameter(
C4Real *zoom_par,
C4Real new_val,
bool no_increase,
bool no_decrease)
1885 if (new_val < *zoom_par)
1887 if (!no_decrease) *zoom_par = new_val;
1888 return !no_decrease;
1890 else if(new_val > *zoom_par)
1892 if (!no_increase) *zoom_par = new_val;
1893 return !no_increase;
1910 if (!scen_name_override)
const int32_t C4ClientIDHost
const int32_t C4ClientIDUnknown
const int C4ViewportScrollBorder
const int C4P_MaxPosition
const int32_t C4D_StaticBack
C4Def * C4Id2Def(C4ID id)
#define PSF_InitializePlayer
#define PSF_InitializeScriptPlayer
#define PSF_PreInitializePlayer
#define PSF_OnOwnerRemoved
#define PSF_OnWealthChanged
C4Application Application
C4GraphicsSystem GraphicsSystem
C4GraphicsResource GraphicsResource
bool C4Group_CopyItem(const char *source, const char *target, bool no_sorting, bool reset_attributes)
bool C4Group_MoveItem(const char *source, const char *target, bool no_sorting)
constexpr bool DEBUGREC_RECRUITMENT
bool FindConSiteSpot(int32_t &rx, int32_t &ry, int32_t wdt, int32_t hgt, int32_t hrange)
bool FindSolidGround(int32_t &rx, int32_t &ry, int32_t width)
bool FindLevelGround(int32_t &rx, int32_t &ry, int32_t width, int32_t hrange)
bool GBackSolid(int32_t x, int32_t y)
const char * LoadResStr(const char *id)
bool Log(const char *szMessage)
bool LogF(const char *strMessage,...)
const int32_t C4NetResMaxBigicon
int VisibilityCheck(int iVis, int sx, int sy, int cx, int cy)
const int32_t C4PVM_Scrolling
const int32_t C4PVM_Cursor
const int32_t C4P_Number_None
const int32_t C4PVM_Target
void CompileFunc(C4Real &rValue, StdCompiler *pComp)
float fixtof(const C4Fixed &x)
C4SoundInstance * StartSoundEffect(const char *szSndName, bool fLoop, int32_t iVolume, C4Object *pObj, int32_t iCustomFalloffDistance, int32_t iPitch, C4SoundModifier *modifier)
const char * SSearch(const char *szString, const char *szIndex)
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
T Clamp(T bval, T lbound, T rbound)
size_t SLen(const char *sptr)
StdPtrAdapt< T > mkNamingPtrAdapt(T *&rpObj, const char *szNaming)
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
#define toC4CStr(szString)
StdStrBuf FormatString(const char *szFmt,...)
bool EraseItem(const char *szItemName)
void MakeTempFilename(char *szFilename)
bool ItemExists(const char *szItemName)
C4GamePadControl * pGamePadControl
C4SoundSystem SoundSystem
C4Value Exec(C4PropList *p=nullptr, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
const char * GetData() const
const char * GetFilePath() const
const char * AtRelativePath(const char *filename)
const char * AtTempPath(const char *filename)
const char * AtUserDataPath(const char *filename)
static C4ControlPlayerAction * InitScenarioPlayer(const C4Player *source, int32_t team)
static C4ControlPlayerAction * InitPlayerControl(const C4Player *source, const C4PlayerControlAssignmentSet *ctrl_set=nullptr)
C4Facet GetPhase(int iPhaseX=0, int iPhaseY=0)
void DrawClr(C4Facet &cgo, bool fAspect=true, DWORD dwClr=0)
void Draw(C4Facet &cgo, bool fAspect=true, int32_t iPhaseX=0, int32_t iPhaseY=0, bool fTransparent=true)
bool Load(C4Group &hGroup, const char *szName, int iWdt, int iHgt, bool fNoErrIfNotFound, int iFlags)
static C4Facet GetIconFacet(Icons icoIconIndex)
C4RoundResults & RoundResults
std::unique_ptr< C4Network2Stats > pNetworkStatistics
C4Object * CreateInfoObject(C4ObjectInfo *info, int32_t owner, int32_t x=50, int32_t y=50)
void OnPlayerJoinFinished()
C4PlayerControlAssignmentSets PlayerControlUserAssignmentSets
char ScenarioFilename[_MAX_PATH_LEN]
C4PlayerInfoList & PlayerInfos
int32_t StartupPlayerCount
C4GameParameters & Parameters
StdCopyStrBuf ScenarioTitle
C4Object * CreateObjectConstruction(C4PropList *type, C4Object *creator, int32_t owner, int32_t center_x=0, int32_t bottom_y=0, int32_t con=1, bool adjust_terrain=false)
C4Value GRBroadcast(const char *function, C4AulParSet *pars=nullptr, bool pass_error=false, bool reject_test=false)
C4Object * CreateObject(C4PropList *type, C4Object *creator, int32_t owner=NO_OWNER, int32_t x=50, int32_t y=50, int32_t r=0, bool grow_from_center=false, C4Real xdir=Fix0, C4Real ydir=Fix0, C4Real rdir=Fix0, int32_t controller=NO_OWNER)
C4ObjectList InactiveObjects
std::shared_ptr< C4GamePadOpener > GetAvailableGamePad()
void SetTitle(const char *szNewTitle)
void SetColorDw(DWORD dwClr)
std::unique_ptr< C4MessageBoard > MessageBoard
StdStrBuf GetFullName() const
bool Sort(const char *list)
bool Delete(const char *files, bool recursive=false)
bool FindEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr)
bool Open(const char *group_name, bool do_create=false)
int32_t GetCount(size_t index) const
int32_t GetIndex(C4ID c_id) const
bool ConsolidateValids(C4DefList &rDefs, int32_t dwCategory=0)
bool SetIDCount(C4ID c_id, int32_t iCount, bool fAddNewID=false)
C4ID GetID(size_t index, int32_t *ipCount=nullptr) const
bool IncreaseIDCount(C4ID c_id, bool fAddNewID=true, int32_t IncreaseBy=1, bool fRemoveEmpty=false)
bool DeleteItem(size_t iIndex)
int32_t GetIDCount(C4ID c_id, int32_t iZeroDefVal=0) const
int32_t GetHeight() const
int32_t GetMapZoom() const
bool ActivateMain(int32_t iPlayer)
bool InitRefSym(const C4Facet &fctSymbol, const char *szEmpty, int32_t iPlayer, int32_t iExtra=C4MN_Extra_None, int32_t iExtraData=0, int32_t iId=0, int32_t iStyle=C4MN_Style_Normal)
C4MessageBoardQuery * pNext
C4Network2ResList ResList
C4Network2Res::Ref Derive()
C4Network2Res::Ref getRefRes(int32_t iResID)
bool Enter(C4Object *pTarget, bool fCalls=true, bool fCopyMotion=true, bool *pfRejectCollect=nullptr)
void DoExperience(int32_t change)
bool CreateContentsByList(C4IDList &idlist)
void SetCommand(int32_t iCommand, C4Object *pTarget, C4Value iTx, int32_t iTy=0, C4Object *pTarget2=nullptr, bool fControl=false, C4Value iData=C4VNull, int32_t iRetries=0, C4String *szText=nullptr)
void SetName(const char *NewName=nullptr) override
bool SetLightRange(int32_t iToRange, int32_t iToFadeoutRange)
void AssignRemoval(bool exit_contents=false)
bool Promote(int32_t torank, bool exception, bool fForceRankName)
bool Save(C4Group &hGroup, bool fSavegame, bool fStoreTiny, C4DefList *pDefs)
bool IsElement(C4ObjectInfo *pInfo)
C4ObjectInfo * New(C4ID n_id, C4DefList *pDefs)
C4ObjectInfo * GetFirst()
void Strip(C4DefList &rDefs)
C4ObjectInfo * GetIdle(C4ID c_id, C4DefList &rDefs)
int32_t Load(C4Group &hGroup)
bool DenumeratePointers()
C4Object * GetFirstObject() const
const C4ObjectLink * GetLink(const C4Object *obj) const
virtual bool Add(C4Object *new_obj, SortType sort_type, C4ObjectList *sorted_list=nullptr)
virtual bool Remove(C4Object *obj)
bool IsContained(const C4Object *obj) const
C4Object * GetObject(int index=0) const
void DenumeratePointers()
static const C4ObjectPtr Null
C4PlayerControlAssignmentSet * GetDefaultSet()
C4PlayerControlAssignmentSet * GetSetByName(const char *szName)
void RegisterKeyset(int32_t iPlr, C4PlayerControlAssignmentSet *pKeyset)
void PlaceReadyBase(int32_t &tx, int32_t &ty, C4Object **pFirstBase)
void SetFoW(bool fEnable)
void PlaceReadyMaterial(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
void DoTeamSelection(int32_t idTeam)
void CountControl(ControlType eType, int32_t iID, int32_t iCntAdd=1)
void ZoomLimitsToViewport(C4Viewport *vp)
bool Message(const char *szMsg)
C4ObjectInfoList CrewInfoList
void SetPlayerColor(uint32_t dwNewClr)
bool HasMessageBoardQuery()
void ZoomLimitsToViewports()
void SetMaxZoom(C4Real zoom, bool no_increase, bool no_decrease)
void EvaluateLeague(bool fDisconnected, bool fWon)
bool SetKnowledge(C4ID id, bool fRemove)
bool SetHostility(int32_t iOpponent, int32_t iHostility, bool fSilent=false)
static bool Strip(const char *szFilename, bool fAggressive)
bool GainScenarioAchievement(const char *achievement_id, int32_t value, const char *scen_name_override=nullptr)
void PlaceReadyCrew(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
int32_t FindNewOwner() const
bool DoWealth(int32_t change)
void ExecBaseProduction()
int32_t ActiveCrewCount()
const char * GetName() const
bool LoadRuntimeData(C4Group &hGroup, C4ValueNumbers *)
bool SetWealth(int32_t val)
void CallMessageBoard(C4Object *pForObj, const StdStrBuf &sQueryString, bool fUppercase)
bool Load(const char *szFilename, bool fSavegame)
void PlaceReadyVehic(int32_t tx1, int32_t tx2, int32_t ty, C4Object *FirstBase)
void SetCursor(C4Object *pObj, bool fSelectArrow)
bool Init(int32_t iNumber, int32_t iAtClient, const char *szAtClientName, const char *szFilename, bool fScenarioInit, class C4PlayerInfo *pInfo, C4ValueNumbers *)
bool ScenarioAndTeamInit(int32_t idTeam)
bool ObjectInCrew(C4Object *tobj)
C4PlayerType GetType() const
void NotifyOwnedObjects()
bool IsHostileTowards(const C4Player *opponent) const
bool FinalInit(bool fInitialScore)
void SetZoom(C4Real zoom, bool direct, bool no_increase, bool no_decrease)
void AdjustCursorCommand()
void SetMinZoom(C4Real zoom, bool no_increase, bool no_decrease)
void ZoomToViewport(C4Viewport *vp, bool direct, bool no_increase=false, bool no_decrease=false)
void DrawHostility(C4Facet &cgo, int32_t iIndex)
void DefaultRuntimeData()
C4Object * GetHiExpActiveCrew()
void ToggleMouseControl()
void ZoomToViewports(bool direct, bool no_increase=false, bool no_decrease=false)
class C4TableGraph * pstatControls
void SetViewMode(int32_t iMode, C4Object *pTarget=nullptr, bool immediate_position=false)
void OnTeamSelectionFailed()
@ PS_TeamSelectionPending
class C4PlayerControlAssignmentSet * ControlSet
bool MakeCrewMember(C4Object *pObj, bool fForceInfo=true, bool fDoCalls=true)
void CheckCrewExPromotion()
class C4MessageBoardQuery * pMsgBoardQuery
void SetMaxZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
void SetMinZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool no_increase, bool no_decrease)
ControlType LastControlType
void ResetCursorView(bool immediate_position=false)
char AtClientName[C4MaxTitle+1]
C4Object * GetHiRankActiveCrew()
void SetViewLocked(bool to_val)
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *)
void SetZoomByViewRange(int32_t range_wdt, int32_t range_hgt, bool direct, bool no_increase, bool no_decrease)
int32_t GetSelectedCrewCount()
std::shared_ptr< class C4GamePadOpener > pGamepad
void DenumeratePointers()
bool SetObjectCrewStatus(C4Object *pCrew, bool fNewStatus)
class C4TableGraph * pstatActions
void SetSoundModifier(C4PropList *new_modifier)
bool RemoveMessageBoardQuery(C4Object *pForObj)
StdCopyStrBuf ControlSetName
bool MarkMessageBoardQueryAnswered(C4Object *pForObj)
class C4PlayerInfo * GetInfo()
char Filename[_MAX_PATH_LEN]
void ClearPointers(C4Object *tptr, bool fDeath)
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
bool ActivateMenuTeamSelection(bool fFromMain)
bool DoScore(int32_t iChange)
StdCopyStrBuf PrefControl
bool Load(C4Group &hGroup)
bool Save(C4Group &hGroup)
C4ScenarioParameters Achievements
uint32_t GetColor() const
C4ID GetScriptPlayerExtraID() const
void SetJoined(int32_t iNumber)
bool IsNoEliminationCheck() const
bool IsScenarioInitDesired() const
const char * GetName() const
int32_t GetInGameNumber() const
C4PlayerType GetType() const
C4PlayerInfo * GetPlayerInfoByIndex(int32_t index) const
C4PlayerInfo * GetPlayerInfoByID(int32_t id) const
C4Player * GetAtClient(int iClient, int iIndex=0) const
bool Hostile(int iPlayer1, int iPlayer2) const
C4Player * GetByIndex(int iIndex) const
bool MouseControlTaken() const
C4Player * Get(int iPlayer) const
int AverageScoreGain() const
void RecheckPlayerSort(C4Player *pForPlayer)
bool PositionTaken(int iPosition) const
bool Valid(int iPlayer) const
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
bool Open(C4Group &group, const char *filename) const
void EvaluatePlayer(C4Player *pPlr)
C4SPlrStart PlrStart[C4S_MaxPlayer]
void SetValue(const char *id, int32_t value, bool only_if_larger)
static StdStrBuf AddFilename2ID(const char *filename, const char *id)
C4SoundModifier * Get(class C4PropList *props, bool create_if_not_found)
void SetGlobalModifier(C4SoundModifier *new_modifier, int32_t player_index)
C4SoundModifierList Modifiers
void AddPlayer(class C4PlayerInfo &rInfo, bool fAdjustPlayer)
int32_t GetIndexedPlayer(int32_t iIndex) const
int32_t GetPlrStartIndex() const
int32_t GetPlayerCount() const
void RemovePlayerByID(int32_t iID)
bool IsRuntimeJoinTeamChoice() const
C4Team * GetTeamByID(int32_t iID) const
bool IsAutoGenerateTeams() const
bool IsJoin2TeamAllowed(int32_t idTeam, C4PlayerType plrType)
C4Team * GetGenerateTeamByID(int32_t iID)
int32_t GetForcedTeamSelection(int32_t idForPlayer) const
void SetPropList(C4PropList *PropList)
C4PropList * getPropList() const
void Denumerate(C4ValueNumbers *)
float GetZoomByViewRange(int32_t size_x, int32_t size_y) const
float GetZoomTarget() const
void SetZoomLimits(float to_min_zoom, float to_max_zoom)
void AdjustPosition(bool immediate=false)
void SetZoom(float zoom_value)
C4Viewport * GetViewport(int32_t player_nr, C4Viewport *prev=nullptr)
void Value(const T &rStruct)
virtual bool isDeserializer()
const char * getData() const
DWORD MakeColorReadableOnBlack(DWORD &rdwClr)