⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocol.pas

📁 类似文明的游戏源代码。
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  Bombs: word; //additional attack with bombs
  Cap: Cardinal; //special features, bitset with index Feature-mcFirstNonCap
  MaxUpgrade, //maximum used upgrade
  Weight: Byte;
  Lost: word;
  end;

TWonderInfo=record
  CityID, // -2 if destroyed, -1 if never completed, >=0 ID of city
  EffectiveOwner: integer // owning player if effective, -1 if expired or not built
  end;

TShipInfo=record
  Parts: array[0..nShipPart-1] of integer;
  end;

TEnemyReport=record
  TurnOfContact, TurnOfCivilReport, TurnOfMilReport,
  Attitude,
  Credibility: integer; // 0..100, last update: ToC
  Treaty: array[0..nPl-1] of integer;
    // diplomatic status with other nations, last update: ToCR
  Government, // gAnarchy..gDemocracy, last update: ToCR
  Money, // last update: ToCR
  ResearchTech, ResearchDone: integer; // last update: ToCR
  Tech: array[0..(nAdv+3) div 4 *4 -1] of ShortInt;
    // tech status indicator, last update: ToCR
  nModelCounted: integer;
    // number of models with info in UnCount, last update: ToMR
  UnCount: array[0..INFIN] of word;
    // number of available units for each model, last update: ToMR
  end;

TMoveAdviceData=record
  ToLoc,nStep,MoreTurns,MaxHostile: integer;
  dx,dy: array[0..24] of integer;
  end;
TTileInfo=record
  Food,Prod,Trade,ExplCity:integer
  end;
TCityReport=record
  HypoTiles,HypoTax,HypoLux,Working,Happy,FoodRep,ProdRep,Trade,PollRep,
    Corruption,Tax,Lux,Science,Support,Eaten,ProdCost,Storage,Deployed:integer;
  end;
TGetCityData=record
  Owner: integer;
  c: TCity
  end;
TCityAreaInfo=record
  Available: array [0..26] of integer;
  end;
TBattleForecast=record
  pAtt,mixAtt,HealthAtt,ExpAtt,FlagsAtt,Movement,EndHealthDef,
    EndHealthAtt: integer;
  end;
TShowMove=record
  Owner,Health,mix,emix,Flags,FromLoc,dx,dy,EndHealth,EndHealthDef: integer;
  end;
TOffer=record
  nDeliver, nCost: integer;
  Price: array[0..11] of Cardinal;
  end;
TChart=array [0..INFIN] of integer;
TEditTileData=record
  Loc, NewTile: integer
  end;
TCreateUnitData=record
  Loc, p, mix: integer;
  end;

TTileList= array[0..INFIN] of Cardinal;
TTileObservedLastList= array[0..INFIN] of SmallInt;
TByteList= array[0..INFIN] of Byte;
TCityList= array[0..INFIN] of TCity;
TUnList= array[0..INFIN] of TUn;
TModelList= array[0..INFIN] of TModel;
TEnemyUnList=array[0..INFIN] of TUnitInfo;
TEnemyCityList=array[0..INFIN] of TCityInfo;
TEnemyModelList=array[0..INFIN] of TModelInfo;

TPlayerContext=record
  Data: pointer;
  Map:^TTileList; {the playground, a list of tiles with index = location, see tile flags}
  MapObservedLast:^TTileObservedLastList;
    // turn in which the tile was observed last, index = location
  BorderHelper:^TByteList;
  Un:^TUnList; {units}
  City:^TCityList; {cities}
  Model:^TModelList; {unit models}
  EnemyUn:^TEnemyUnList; //known units of enemy players
  EnemyCity:^TEnemyCityList; //known cities of enemy players
  EnemyModel:^TEnemyModelList; //known unit models of enemy players
  EnemyReport: array[0..nPl-1] of ^TEnemyReport;

  TestFlags, //options turned on in the "Manipulation" menu
  Turn, //current turn
  Alive, {bitset of IDs of players still alive, flag 1 shl p for player p}
  Happened, //flags indicate what happened within the last turnaround
  AnarchyStart, // start turn of anarchy, <0 if not in anarchy
  Credibility, // own credibility
  MaxCredibility, // maximum credibility still to achieve
  nUn, {number of units}
  nCity, {number of cities}
  nModel, {number of developed unit models}
  nEnemyUn,nEnemyCity,nEnemyModel,
  Government, {gAnarchy..gDemocracy}
  Money,TaxRate,LuxRate,
  Research, {collected research points for currently researched tech}
  ResearchTech: integer; //currently researched tech
  DevModel: TModel; {unit model currently under development}
  Tech: array[0..(nAdv+3) div 4 *4 -1] of ShortInt; {tech status indicator}
  Attitude: array[0..nPl-1] of integer; // attitude to other nations
  Treaty: array[0..nPl-1] of integer; // treaty with other nations
  EvaStart: array[0..nPl-1] of integer; // peace treaty: start of evacuation period
  Tribute: array[0..nPl-1] of integer;
    // defined each turn payment with other nations (+ received, - payed)
  TributePaid: array[0..nPl-1] of integer;
    // last turn payment with other nations (+ received, - payed)
  Wonder: array[0..27] of TWonderInfo;
  Ship: array[0..nPl-1] of TShipInfo;
  NatBuilt: array[28..(nImp+3) div 4 *4 -1] of ShortInt;
  Filler: array[0..959] of byte;
  end;

TInitModuleData=record
  Server: TServerCall;
  DataVersion, DataSize: integer;
  end;
TNewGameData=record
  lx,ly,LandMass,MaxTurn: integer;
  Difficulty: array[0..nPl-1] of integer;
    {difficulty levels of the players, if it's 0 this player is the supervisor,
    -1 for unused slots}
  RO: array[0..nPl-1] of ^TPlayerContext;
  end;
TNewGameExData=record
  lx,ly,LandMass,MaxTurn,RND: integer;
  Difficulty: array[0..nPl-1] of integer;
    {difficulty levels of the players, if it's 0 this player is the supervisor,
    -1 for unused slots}
  Controlled: integer;
  end;


const
{predefined unit models:}
nSpecialModel=11;
SpecialModel: array[0..nSpecialModel-1] of TModel=
((Kind:mkSettler;Domain:dGround;Attack:0;Defense:10;Speed:150;Cost:40;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Settlers}
(Kind:mkSettler;Domain:dGround;Attack:0;Defense:20;Speed:300;Cost:40;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Engineers}
(Kind:mkSelfDeveloped;Domain:dGround;Attack:6;Defense:6;Speed:150;Cost:10;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Militia}
(Kind:mkSpecial_TownGuard;Domain:dGround;Attack:4;Defense:6;Speed:150;Cost:20;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Town Guard}
(*(Kind:mkDiplomat;Domain:dGround;Attack:0;Defense:0;Speed:250;Cost:30;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Diplomat}*)
(Kind:mkDiplomat;Domain:dGround;Attack:12;Defense:12;Speed:250;Cost:20;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Spy}
(Kind:mkCaravan;Domain:dGround;Attack:0;Defense:6;Speed:150;Cost:60;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Caravan}
(*(Kind:mkCaravan;Domain:dGround;Attack:0;Defense:10;Speed:250;Cost:60;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Freight}
(Kind:mkScout;Domain:dGround;Attack:0;Defense:0;Speed:350;Cost:10;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Scout}
(Kind:mkScout;Domain:dGround;Attack:0;Defense:0;Speed:350;Cost:10;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Mech. Scout}*)
(Kind:mkSpecial_Boat;Domain:dSea;Attack:0;Defense:3;Speed:350;Cost:20;MTrans:1;
  Cap:(0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Boat}
(Kind:mkSlaves;Domain:dGround;Attack:0;Defense:15;Speed:150;Cost:40;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)), {Slaves}
(Kind:mkSpecial_Carriage;Domain:dGround;Attack:50;Defense:30;Speed:250;Cost:50;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)),
(Kind:mkSpecial_SubCabin;Domain:dSea;Attack:16;Defense:0;Speed:350;Cost:40;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)),
(Kind:mkSpecial_Glider;Domain:dAir;Attack:6;Defense:6;Speed:450;Cost:30;
  Cap:(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)));

SpecialModelPreq: array[0..nSpecialModel-1] of integer=
(preNone,adExplosives,preNone,preNone,(*adWri,*)adIntelligence,adTrade,
(*adTheCorporation,adHorsebackRiding,adAutomobile,
adNavigation,adCombustionEngine,*)adMapMaking,preBuilder,preLeo,preLeo,preLeo);


procedure MakeUnitInfo(p: integer; const u: TUn; var ui: TUnitInfo);
procedure MakeModelInfo(p, mix: integer; const m: TModel; var mi: TModelInfo);
function IsSameModel(const mi1,mi2: TModelInfo): boolean;
function HypoSpecialTile(x,y,TerrType: integer): integer;


implementation

procedure MakeUnitInfo(p: integer; const u: TUn; var ui: TUnitInfo);
begin
ui.Owner:=p;
ui.Loc:=u.Loc;
ui.Health:=u.Health;
ui.Fuel:=u.Fuel;
ui.Job:=u.Job;
ui.Exp:=u.Exp;
ui.Load:=u.TroopLoad+u.AirLoad;
ui.mix:=u.mix;
ui.Flags:=u.Flags;
end;

procedure MakeModelInfo(p, mix: integer; const m: TModel; var mi: TModelInfo);
var
i: integer;
begin
mi.Owner:=p;
mi.mix:=mix;
mi.Domain:=m.Domain;
if m.Kind=mkEnemyDeveloped then mi.Kind:=mkSelfDeveloped // important for IsSameModel()
else mi.Kind:=m.Kind;
mi.Attack:=m.Attack;
mi.Defense:=m.Defense;
mi.Speed:=m.Speed;
mi.Cost:=m.Cost;
if mi.Domain=dAir then
  begin
  mi.TTrans:=m.Cap[mcAirTrans]*m.MTrans;
  mi.ATrans_Fuel:=m.Cap[mcFuel];
  end
else
  begin
  mi.TTrans:=m.Cap[mcSeaTrans]*m.MTrans;
  mi.ATrans_Fuel:=m.Cap[mcCarrier]*m.MTrans;
  end;
mi.Bombs:=m.Cap[mcBombs]*m.MStrength*2;
mi.Cap:=0;
for i:=mcFirstNonCap to nFeature-1 do if m.Cap[i]>0 then
  mi.Cap:=mi.Cap or (1 shl (i-mcFirstNonCap));
mi.MaxUpgrade:=0;
for i:=1 to nUpgrade-1 do if m.Upgrades and (1 shl i)<>0 then
  mi.MaxUpgrade:=i;
mi.Weight:=m.Weight;
mi.Lost:=0;
end;

function IsSameModel(const mi1,mi2: TModelInfo): boolean;
type
TModelInfo_Compare=array[0..5] of Cardinal;
var
Compare1, Compare2: ^TModelInfo_Compare;
begin
Compare1:=@mi1; Compare2:=@mi2;
result:=(Compare1[1] and $FFFF0000=Compare2[1] and $FFFF0000)
  and (Compare1[2]=Compare2[2]) and (Compare1[3]=Compare2[3])
  and (Compare1[4]=Compare2[4]) and (Compare1[5]=Compare2[5])
end;

function HypoSpecialTile(x,y,TerrType: integer): integer;
var
qx,qy: integer;
begin
if TerrType=fOcean then result:=0
else if TerrType=fGrass then {formula for productive grassland}
  if Odd((lymax+x-y shr 1) shr 1+x+(y+1) shr 1) then result:=1
  else result:=0
else {formula for special resources}
  begin
  qx:=(4*x-y+9980) div 10; qy:=(y+x) div 5;
  if ((4*x-y+10000) mod 10=0)
    and (qx and 3<>0) and (qy and 3<>qx shr 2 and 1 *2) then
    if TerrType=fArctic then result:=1
    else if TerrType=fShore then
      begin
      if (qx+qy) and 1=0 then
        if qx and 3=2 then result:=2
        else result:=1
      else result:=0
      end
    else result:=(qx+qy) and 1+1
  else result:=0;
  end;
end;

begin
assert(sizeof(TPlayerContext)=2048);
assert(sizeof(TModel)-2*sizeof(LongInt)-4*sizeof(word)=sIntSetDevModel and $F *4);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -