# HG changeset patch # User sheepluva # Date 1391528131 -3600 # Node ID 8c5fa1d15bd59dcb720f9d43f73bb9de050ee690 # Parent cb0b750bd8a3ef98e6ef12e5f685aa1eb094e563 fixing the remaining PChar issues pas2c ran into to this point, now it stops because of being unable to deal with "set of char" diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uAmmos.pas --- a/hedgewars/uAmmos.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uAmmos.pas Tue Feb 04 16:35:31 2014 +0100 @@ -398,7 +398,7 @@ s:= s + ' (' + IntToStr(Count) + ')'; if (Propz and ammoprop_Timerable) <> 0 then s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds]; - AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo); + AddCaption(Str2PChar(s), Team^.Clan^.Color, capgrpAmmoinfo); if (Propz and ammoprop_NeedTarget) <> 0 then begin if Gear <> nil then Gear^.State:= Gear^.State or gstHHChooseTarget; diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uCaptions.pas --- a/hedgewars/uCaptions.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uCaptions.pas Tue Feb 04 16:35:31 2014 +0100 @@ -23,7 +23,7 @@ interface uses uTypes; -procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); +procedure AddCaption(caption: PChar; Color: Longword; Group: TCapGroup); procedure DrawCaptions; procedure ReloadCaptions(unload: boolean); @@ -42,8 +42,11 @@ var Captions: array[TCapGroup] of TCaptionStr; -procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup); +procedure AddCaption(caption: PChar; Color: Longword; Group: TCapGroup); +var + s: shortstring; begin + s:= caption; if cOnlyStats then exit; if Length(s) = 0 then exit; diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uGame.pas --- a/hedgewars/uGame.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uGame.pas Tue Feb 04 16:35:31 2014 +0100 @@ -26,7 +26,7 @@ //////////////////// implementation //////////////////// -uses uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions, +uses uUtils, uInputHandler, uTeams, uIO, uAI, uGears, uSound, uLocale, uCaptions, uTypes, uVariables, uCommands, uConsts, uVisualGearsList {$IFDEF USE_TOUCH_INTERFACE}, uTouch{$ENDIF}; @@ -77,7 +77,7 @@ else if not isAudioMuted then begin str(i, s); - AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume) + AddCaption(FormatPChar(trmsg[sidVolume], Str2PChar(s)), cWhiteColor, capgrpVolume) end end; end; diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uGears.pas Tue Feb 04 16:35:31 2014 +0100 @@ -331,7 +331,7 @@ if i = 1 then AddCaption(trmsg[sidRoundSD], cWhiteColor, capgrpGameState) else if (i = 2) or ((i > 0) and ((i mod 50 = 0) or ((i <= 25) and (i mod 5 = 0)))) then - AddCaption(Format(trmsg[sidRoundsSD], s), cWhiteColor, capgrpGameState); + AddCaption(FormatPChar(trmsg[sidRoundsSD], Str2PChar(s)), cWhiteColor, capgrpGameState); end; end; if bBetweenTurns diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uGearsHedgehog.pas --- a/hedgewars/uGearsHedgehog.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uGearsHedgehog.pas Tue Feb 04 16:35:31 2014 +0100 @@ -185,23 +185,23 @@ color:= Gear^.Hedgehog^.Team^.Clan^.Color; case Gear^.MsgParam of 1: begin - AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate); + AddCaption(FormatPChar(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate); CurWeapon^.Bounciness:= 350; end; 2: begin - AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate); + AddCaption(FormatPChar(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate); CurWeapon^.Bounciness:= 700; end; 3: begin - AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate); + AddCaption(FormatPChar(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate); CurWeapon^.Bounciness:= 1000; end; 4: begin - AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate); + AddCaption(FormatPChar(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate); CurWeapon^.Bounciness:= 2000; end; 5: begin - AddCaption(FormatA(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate); + AddCaption(FormatPChar(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate); CurWeapon^.Bounciness:= 4000; end end @@ -533,7 +533,7 @@ if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) then begin s:= inttostr(Ammoz[a].Ammo.NumPerTurn - MultiShootAttacks + 1); - AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate); + AddCaption(formatPChar(trmsg[sidRemaining], Str2Pchar(s)), cWhiteColor, capgrpAmmostate); end; if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) @@ -651,7 +651,7 @@ s:= trammo[Ammoz[ammo].NameId] + ' (+' + IntToStr(cnt) + ')' else s:= trammo[Ammoz[ammo].NameId] + ' (+' + IntToStr(Ammoz[ammo].NumberInCase) + ')'; - AddCaption(s, HH.Team^.Clan^.Color, capgrpAmmoinfo); + AddCaption(Str2PChar(s), HH.Team^.Clan^.Color, capgrpAmmoinfo); // show ammo icon vga:= AddVisualGear(X, Y, vgtAmmo); @@ -714,7 +714,7 @@ HH^.Hedgehog^.Effects[hePoisoned] := 0; str(Gear^.Health, s); s:= '+' + s; - AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); + AddCaption(Str2PChar(s), HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); RenderHealth(HH^.Hedgehog^); RecountTeamHealth(HH^.Hedgehog^.Team); @@ -1268,7 +1268,7 @@ Gear^.State:= (Gear^.State or gstHHDeath) and (not gstAnimation); Gear^.doStep:= @doStepHedgehogDead; // Death message - AddCaption(Format(GetEventString(eidDied), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); + AddCaption(FormatPChar(GetEventString(eidDied), Str2PChar(Gear^.Hedgehog^.Name)), cWhiteColor, capgrpMessage); end; end else @@ -1277,7 +1277,7 @@ Gear^.doStep:= @doStepHedgehogGone; // Gone message - AddCaption(Format(GetEventString(eidGone), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); + AddCaption(FormatPChar(GetEventString(eidGone), Str2PChar(Gear^.Hedgehog^.Name)), cWhiteColor, capgrpMessage); end end; exit diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uGearsUtils.pas --- a/hedgewars/uGearsUtils.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uGearsUtils.pas Tue Feb 04 16:35:31 2014 +0100 @@ -234,7 +234,7 @@ inc(CurrentHedgehog^.Gear^.Health,vampDmg); str(vampDmg, s); s:= '+' + s; - AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); + AddCaption(Str2PChar(s), CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo); RenderHealth(CurrentHedgehog^); RecountTeamHealth(CurrentHedgehog^.Team); i:= 0; @@ -419,7 +419,7 @@ begin Gear^.doStep := @doStepDrowningGear; Gear^.State := Gear^.State and (not gstHHDriven); - AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage); + AddCaption(FormatPChar(GetEventString(eidDrowned), Str2PChar(Gear^.Hedgehog^.Name)), cWhiteColor, capgrpMessage); end end else diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uLocale.pas --- a/hedgewars/uLocale.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uLocale.pas Tue Feb 04 16:35:31 2014 +0100 @@ -25,6 +25,7 @@ const MAX_EVENT_STRINGS = 100; procedure LoadLocale(FileName: shortstring); +function FormatPChar(fmt: PChar; arg: PChar): PChar; function Format(fmt: shortstring; var arg: shortstring): shortstring; function FormatA(fmt: PChar; arg: ansistring): ansistring; function GetEventString(e: TEventId): PChar; @@ -109,6 +110,14 @@ GetEventString:= trevt[e][GetRandom(trevt_n[e])]; // Pick a random message and return it end; +function FormatPChar(fmt: PChar; arg: PChar): PChar; +var + s: shortstring; +begin + s:= arg; + FormatPChar:= Str2PChar(FormatA(fmt, s)); +end; + function Format(fmt: shortstring; var arg: shortstring): shortstring; var i: LongInt; begin diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uRenderUtils.pas --- a/hedgewars/uRenderUtils.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uRenderUtils.pas Tue Feb 04 16:35:31 2014 +0100 @@ -77,13 +77,13 @@ WriteInRoundRect:= WriteInRoundRect(Surface, X, Y, Color, Font, s, 0); end;*) -function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring; maxLength: LongWord): TSDL_Rect; +function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar; maxLength: LongWord): TSDL_Rect; var w, h: LongInt; tmpsurf: PSDL_Surface; clr: TSDL_Color; finalRect, textRect: TSDL_Rect; begin - TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), @w, @h); + TTF_SizeUTF8(Fontz[Font].Handle, s, @w, @h); if (maxLength <> 0) and (w > maxLength) then w := maxLength; finalRect.x:= X; finalRect.y:= Y; @@ -97,7 +97,7 @@ clr.r:= (Color shr 16) and $FF; clr.g:= (Color shr 8) and $FF; clr.b:= Color and $FF; - tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); + tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr); finalRect.x:= X + cFontBorder + 2; finalRect.y:= Y + cFontBorder; SDLTry(tmpsurf <> nil, true); diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uStats.pas --- a/hedgewars/uStats.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uStats.pas Tue Feb 04 16:35:31 2014 +0100 @@ -112,7 +112,7 @@ begin AddVoice(sndStupid, PreviousTeam^.voicepack); if CurrentHedgehog^.stats.DamageGiven = CurrentHedgehog^.stats.StepDamageRecv then - AddCaption(Format(GetEventString(eidHurtSelf), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); + AddCaption(FormatPChar(GetEventString(eidHurtSelf), Str2PChar(CurrentHedgehog^.Name)), cWhiteColor, capgrpMessage); end else if DamageClan <> 0 then @@ -140,7 +140,7 @@ else if isTurnSkipped then begin AddVoice(sndBoring, PreviousTeam^.voicepack); - AddCaption(Format(GetEventString(eidTurnSkipped), CurrentHedgehog^.Name), cWhiteColor, capgrpMessage); + AddCaption(FormatPChar(GetEventString(eidTurnSkipped), Str2PChar(CurrentHedgehog^.Name)), cWhiteColor, capgrpMessage); end else if not PlacingHogs then AddVoice(sndCoward, PreviousTeam^.voicepack); diff -r cb0b750bd8a3 -r 8c5fa1d15bd5 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Tue Feb 04 15:23:37 2014 +0100 +++ b/hedgewars/uTeams.pas Tue Feb 04 16:35:31 2014 +0100 @@ -103,7 +103,7 @@ else AddVoice(sndVictory, Teams[0]^.voicepack); - AddCaption(s, cWhiteColor, capgrpGameState); + AddCaption(Str2PChar(s), cWhiteColor, capgrpGameState); SendStat(siGameResult, s); AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) end; @@ -334,7 +334,7 @@ end; if cHedgehogTurnTime < 1000000 then ReadyTimeLeft:= cReadyDelay; - AddCaption(Format(shortstring(trmsg[sidReady]), CurrentTeam^.TeamName), cWhiteColor, capgrpGameState) + AddCaption(FormatPChar(trmsg[sidReady], Str2PChar(CurrentTeam^.TeamName)), cWhiteColor, capgrpGameState) end else begin