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

📄 term.pas

📁 类似文明的游戏源代码。
💻 PAS
📖 第 1 页 / 共 5 页
字号:
        end;
      Server(sSetResearch,me,NewResearch,nil^);
      end;{select tech}

    // tell what happened in cities
    UpdatePanel:=false;
    ShowCityList:=false;
    for cix:=0 to MyRO.nCity-1 do with MyCity[cix] do if Loc>=0 then
      begin
      if (Status and 7<>0) and (Project and (cpImp+cpIndex)=cpImp+imTrGoods) then
        if (MyData.ImpOrder[Status and 7-1,0]>=0) then
          AutoBuild(cix,MyData.ImpOrder[Status and 7-1])
        else Flags:=Flags or chTypeDel;
      if (Size>=NeedAqueductSize) and (MyRO.Tech[Imp[imAqueduct].Preq]<tsApplicable)
        or (Size>=NeedSewerSize) and (MyRO.Tech[Imp[imSewer].Preq]<tsApplicable) then
        Flags:=Flags and not chNoGrowthWarning; // don't remind of unknown building
      if Flags and chNoSettlerProd=0 then
        Status:=Status and not csToldDelay
      else if Status and csToldDelay=0 then
        Status:=Status or csToldDelay
      else Flags:=Flags and not chNoSettlerProd;
      if Flags and CityRepMask<>0 then
        if (MyRO.Turn=0) or mRepScreens.Checked then
          begin {show what happened in cities}
          SetTroopLoc(MyCity[cix].Loc);
          PanelPaint;
          MarkCity(MyCity[cix].Loc);
          CityDlg.cix:=cix;
          CityDlg.CloseAction:=None;
          if MyRO.Turn=0 then CityDlg.Happened:=0
          else CityDlg.Happened:=Flags and CityRepMask;
          CityDlg.ProdHint:= (Flags and CityRepMask and (chProduction or chFounded)<>0)
            and (Project and (cpImp+cpIndex)=cpImp+imTrGoods);
          CityDlg.ShowModal;
          UpdatePanel:=true;
          end
        else if mRepList.Checked then
          ShowCityList:=true
      end; {city loop}
    if ShowCityList then
      begin
      CityDlg.CloseAction:=None;
      CityListDlg.Kind:=kCityEvents;
      CityListDlg.ShowModal;
      if CityDlg.Visible then CityDlg.Close;
      UpdatePanel:=true;
      end;

    if MyRO.Happened and phGliderLost<>0 then
      ContextMessage(Phrases.Lookup('GLIDERLOST'), 'GLIDERLOST', hkMisc,
        miscModelList);
    if MyRO.Happened and phPlaneLost<>0 then
      ContextMessage(Phrases.Lookup('PLANELOST'), 'PLANELOST', hkFeature,
        mcFuel);
    if MyRO.Happened and phPeaceEvacuation<>0 then
      for p1:=0 to nPl-1 do if 1 shl p1 and MyData.PeaceEvaHappened<>0 then
        SimpleMessage(Tribe[p1].TPhrase('WITHDRAW'), ''{!!!Sound});
    if MyRO.Happened and phPeaceViolation<>0 then
      for p1:=0 to nPl-1 do
        if (1 shl p1 and MyRO.Alive<>0) and (MyRO.EvaStart[p1]=MyRO.Turn) then
          SimpleMessage(Format(Tribe[p1].TPhrase('VIOLATION'),
            [TurnToString(MyRO.Turn+PeaceEvaTurns-1)]), ''{!!!Sound});
    if MyRO.Happened and phChangeGov<>0 then
      begin
      SelectDlg.Caption:=Phrases.Lookup('TITLE_GOV');
      SelectDlg.Kind:=kGov;
      SelectDlg.ShowModal;
      Server(sSetGovernment,me,SelectDlg.result,nil^);
      Play('GOV');
      UpdatePanel:=true;
      end;

    if UpdatePanel then
      begin SumCities(TaxSum,ScienceSum); PanelPaint; end;

    for uix:=0 to MyRO.nUn-1 do with MyUn[uix] do if Loc>=0 then
      begin
      if Flags and unWithdrawn<>0 then Status:=0;
      if Health=100 then
        Status:=Status and not usRecover;
      if (Master>=0) or UnitExhausted(uix) then
        Status:=Status and not usWaiting
      else Status:=Status or usWaiting;
      if Status and usGoto<>0 then
        begin {continue multi-turn goto}
        SetUnFocus(uix);
        SetTroopLoc(Loc);
        FocusOnLoc(TroopLoc,flRepaintPanel or flImmUpdate);
        if Status shr 16=$7FFF then MoveAdviceData.ToLoc:=maNextCity
        else MoveAdviceData.ToLoc:=Status shr 16;
        MoveAdviceData.MoreTurns:=999;
        MoveAdviceData.MaxHostile:=100;
        MoveResult:=eOK;
        if Server(sGetMoveAdvice,me,UnFocus,MoveAdviceData)>=rExecuted then
          begin
          ok:=true;
          for i:=0 to MoveAdviceData.nStep-1 do
            begin
            Loc1:=dLoc(Loc,MoveAdviceData.dx[i],MoveAdviceData.dy[i]);
            if (MyMap[Loc1] and (fCity or fOwned)=fCity) // don't capture cities during auto move
              or (MyMap[Loc1] and (fUnit or fOwned)=fUnit) then // don't attack during auto move
              begin ok:=false; Break end
            else
              begin
              if (Loc1=MoveAdviceData.ToLoc) or (MoveAdviceData.ToLoc=maNextCity)
                and (MyMap[dLoc(Loc,MoveAdviceData.dx[i],MoveAdviceData.dy[i])] and fCity<>0) then
                MoveOptions:=muAutoNoWait
              else MoveOptions:=0;
              MoveResult:=MoveUnit(MoveAdviceData.dx[i],MoveAdviceData.dy[i],MoveOptions);
              if (MoveResult<rExecuted) or (MoveResult=eEnemySpotted) then
                begin ok:=false; Break end;
              end
            end;
          Stop:=not ok or (Loc=MoveAdviceData.ToLoc)
            or (MoveAdviceData.ToLoc=maNextCity) and (MyMap[Loc] and fCity<>0)
          end
        else Stop:=true;

        if MoveResult<>eDied then
          if Stop then Status:=Status and ($FFFF-usGoto)
          else Status:=Status and not usWaiting;
        end;

      if Status and (usEnhance or usGoto)=usEnhance then
        // continue terrain enhancement
        begin
        MoveResult:=ProcessEnhancement(uix,MyData.EnhancementJobs);
        if MoveResult<>eDied then
          if MoveResult=eJobDone then Status:=Status and not usEnhance
          else Status:=Status and not usWaiting;
        end
      end
    end; // ClientMode=cTurn

  if G.Difficulty[me]=0 then
    begin SetTroopLoc(-1); MainPaint end {supervisor}
  else
    begin
    if ClientMode>=scContact then SetUnFocus(-1)
    else NextUnit(-1,false);
    if UnFocus<0 then
      begin
      UnStartLoc:=-1;
      if Multi or (ClientMode=cResume) then
        if MyRO.nCity>0 then FocusOnLoc(MyCity[0].Loc)
        else FocusOnLoc(MyUn[0].Loc);
      SetTroopLoc(-1);
      PanelPaint
      end
    end;
  end;{InitTurn}

var
i,j,p1,mix,ToLoc: integer;
Color: TColor;
Name,s: string;
TribeInfo: TTribeInfo;
mi: TModelInfo;
SkipTurn: boolean;

begin {>>>client}
case Command of
  cDebugMessage:
    LogDlg.Add(NewPlayer, G.RO[0].Turn, pchar(@Data));

  cInitModule:
    begin
    InitModule;
    Server:=TInitModuleData(Data).Server;
    TInitModuleData(Data).DataSize:=SizeOf(TPersistentData);
    end;

  cReleaseModule:
    begin
    BigImp.Free;
    SmallImp.Free;
    UnusedTribeFiles.Free;
    TribeNames.Free;
    MainMap.Free;
    IsoEngine.Done
    end;

  cHelpOnly,cStartHelp:
    begin
    Age:=0;
    InitTexture(OuterTex,'StdTextures',0);
    InitTexture(InnerTex,'StdTextures',1);
    BaseWin.DlgTex:=OuterTex;
    Tribes.Init;
    HelpDlg.Left:=(Screen.Width-HelpDlg.Width) div 2;
    HelpDlg.Top:=(Screen.Height-HelpDlg.Height) div 2;
    HelpDlg.Difficulty:=0;
    if Command=cHelpOnly then
      HelpDlg.ShowPage(hkText, HelpDlg.TextIndex('MAIN'), true)
    else HelpDlg.ShowPage(hkText, HelpDlg.TextIndex('START'), true);
    Tribes.Done;
    end;

  cNewGame,cLoadGame,cNewMap:
    begin
    GenerateNames:=mNames.Checked;
    GameOK:=true;
    G:=TNewGameData(Data);
    me:=-1;
    ClientMode:=-1;
    idle:=false;
    FillChar(Jump,SizeOf(Jump),0);
    GameMode:=Command;
    for i:=0 to nGrExt-1 do
      FillChar(GrExt[i].pixUsed,GrExt[i].Data.Height div 49 *10,0);
    IsoEngine.Reset;
    Tribes.Init;
    GetTribeList;
    for p1:=0 to nPl-1 do if (G.RO[p1]<>nil) and (G.RO[p1].Data<>nil) then
      with TPersistentData(G.RO[p1].Data^) do
        begin
        FarTech:=adNone;
        FillChar(EnhancementJobs,SizeOf(EnhancementJobs),jNone);
        FillChar(ImpOrder,SizeOf(ImpOrder),-1);
        ColdWarStart:=-ColdWarTurns-1;
        ToldAge:=-1;
        ToldModels:=3;
        ToldAlive:=0;
        for i:=0 to nPl-1 do if G.Difficulty[i]>0 then inc(ToldAlive,1 shl i);
        ToldBankrupt:=0;
        PeaceEvaHappened:=0;
        FillChar(ToldShip,SizeOf(ToldShip),0);
        for i:=0 to 27 do with ToldWonders[i] do
          begin CityID:=-1; EffectiveOwner:=-1 end;
        FillChar(ToldTech,SizeOf(ToldTech),tsNA);
        end;

    HelpDlg.Left:=Screen.Width-HelpDlg.Width-8;
    HelpDlg.Top:=8;
    Age:=0;
    InitTexture(OuterTex,'StdTextures',0);
    InitTexture(InnerTex,'StdTextures',1);
    BaseWin.DlgTex:=OuterTex;
    InputDlg.Tex:=InnerTex;
    MessgDlg.Tex:=InnerTex;
    MessgExDlg.Tex:=InnerTex;
    LogDlg.mSlot.Visible:=true;
    LogDlg.Host:=self;
    CityDlg.Mode:=mImp;

    if Command=cNewMap then
      begin
      xTroop:=LeftPanelWidth_Editor+7;
      GameBtn.Hint:=Phrases.Lookup('MAPMENU');
      GameBtn.ButtonIndex:=24
      end
    else
      begin
      xTroop:=LeftPanelWidth+7;
      GameBtn.Hint:=Phrases.Lookup('GAMEMENU');
      GameBtn.ButtonIndex:=1
      end;
    for i:=0 to ControlCount-1 do if Controls[i] is TButtonC then
      Controls[i].visible:=true;
    Mini.Width:=G.lx*2; Mini.Height:=G.ly;
    xw:=0; yw:=ywmax div 2 and not 1;
    for i:=0 to nPl-1 do
      begin Tribe[i]:=nil; TribeOriginal[i]:=false; end;
    ToldSlavery:=-1;
    RepaintOnResize:=false;
    Closable:=false;
    end;

  cGetReady,cReplay: if NewPlayer=0 then
    begin
    i:=0;
    for p1:=0 to nPl-1 do
      if (G.Difficulty[p1]>0) and (Tribe[p1]=nil) then inc(i);
    if i>UnusedTribeFiles.Count then
      begin
      GameOK:=false;
      SimpleMessage(Phrases.Lookup('TOOFEWTRIBES'),'INVALID');
      end
    else
      begin
      for p1:=0 to nPl-1 do
        if (G.Difficulty[p1]>0) and (Tribe[p1]=nil) and (G.RO[p1]<>nil) then
          begin // let player select own tribes
          TribeInfo.trix:=p1;
          TribeNames.Clear;
          for j:=0 to UnusedTribeFiles.Count-1 do
            begin
            GetTribeInfo(UnusedTribeFiles[j], Name, Color);
            TribeNames.AddObject(Name,TObject(Color));
            end;
          assert(TribeNames.Count>0);
          SelectDlg.Caption:=Phrases.Lookup('TITLE_TRIBE');
          SelectDlg.Kind:=kTribe;
          SelectDlg.ShowModal;
          Application.ProcessMessages;
          TribeInfo.FileName:=UnusedTribeFiles[SelectDlg.result];
          UnusedTribeFiles.Delete(SelectDlg.result);

          if GameMode=cLoadGame then
            CreateTribe(TribeInfo.trix,TribeInfo.FileName,false)
          else Server(cSetTribe+(Length(TribeInfo.FileName)+1+7) div 4,
            0,0,TribeInfo);
          end;

      for p1:=0 to nPl-1 do
        if (G.Difficulty[p1]>0) and (Tribe[p1]=nil) and (G.RO[p1]=nil) then
          begin // autoselect enemy tribes
          j:=ChooseUnusedTribe;
          TribeInfo.FileName:=UnusedTribeFiles[j];
          UnusedTribeFiles.Delete(j);
          TribeInfo.trix:=p1;
          if GameMode=cLoadGame then
            CreateTribe(TribeInfo.trix,TribeInfo.FileName,false)
          else Server(cSetTribe+(Length(TribeInfo.FileName)+1+7) div 4,
            0,0,TribeInfo);
          end;
      end;
    if not mNames.Checked then
      for p1:=0 to nPl-1 do if Tribe[p1]<>nil then
        Tribe[p1].NumberName:=p1;
    end;

  cBreakGame:
    begin
    if CityDlg.Visible then
      begin CityDlg.CloseAction:=None; CityDlg.Close; end;
    if NatStatDlg.Visible then NatStatDlg.CloseNow;
    if LogDlg.Visible then LogDlg.Close;
    LogDlg.List.Clear;
    me:=-1;
    idle:=false;
    ClientMode:=-1;
    GameBtn.Visible:=false;
    StatBtn.Visible:=false;
    UnitBtn.Visible:=false;
    EOT.Visible:=false;
    InitPVSB(sb,0,1);
    for p1:=0 to nPl-1 do if Tribe[p1]<>nil then Tribe[p1].Free;
    Tribes.Done;
    RepaintOnResize:=false;
    Closable:=true; Close;
    end;

  cShowGame:
    begin
    with Panel.Canvas do
      begin
      Brush.Color:=$000000;
      FillRect(Rect(0,0,Panel.Width,Panel.Height));
      Brush.Style:=bsClear;
      end;
    FormResize(nil);
    Show;
    RepaintOnResize:=true;
    end;

  cTurn,cResume,cContinue:
    if not GameOK then Server(sResign,NewPlayer,0,nil^)
    else
      begin
      ClientMode:=Command;
      pTurn:=NewPlayer;
      if Jump[pTurn]>0 then
        Application.ProcessMessages;
      if Jump[pTurn]>0 then
        if G.RO[NewPlayer].Happened and phGameEnd<>0 then Jump[pTurn]:=0
        else dec(Jump[pTurn]);
      SkipTurn:= Jump[pTurn]>0;
      if SkipTurn then
        begin
        SetTroopLoc(-1);
        MiniPaint;
        if not EndTurn(false) then SkipTurn:=false;
        end;
      if not SkipTurn then
        begin
        if Command=cResume then
          begin // init non-original model pictures (maybe tribes not found)
          me:=0;
          for p1:=0 to nPl-1 do if G.RO[p1]<>nil then
            for mix:=0 to G.RO[p1].nModel-1 do
              if Tribe[p1].ModelPicture[mix].HGr=0 then
                begin
                MakeModelInfo(p1,mix,G.RO[p1].Model[mix],mi);
                InitEnemyModel(mi,true);
                end;
          me:=-1;
          end;

        if ((ClientMode<scDipStart) or (ClientMode>scDipBreak))
          and NatStatDlg.Visible then
          NatStatDlg.CloseNow;

⌨️ 快捷键说明

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