CoolFace
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes838downloads
ToTheFront.txt216 linesDownload Raw Back to ToTheFront
1 2U0 AnimationDelaySet()3{4  animation_delay=PopUpRangeF64(0,100,25,"%3f% %%","Animation Delay\n")/100;5}6 7U0 TurnNew()8{9  I64 i,j;10  for (j=0;j<2;j++)11    for (i=0;i<UNITS_NUM;i++) {12      units[j][i].remaining_movement=units[j][i].movement;13      units[j][i].fired=FALSE;14    }15  phase=PHASE_START;16  moving_unit=NULL;17 18  SleepUntil(msg_off_timeout);19  msg_off_timeout=cnts.jiffies+JIFFY_FREQ*2*animation_delay+1;20  Snd(74);21  StrPrint(msg_buf,"Turn %d",++turn);22  VRSetUp(0);23  VRSetUp(1);24  VisRecalc(VR_ALL_UNITS);25  cur_player=(turn&1)^1;26  enemy_player=cur_player^1;27}28 29U0 PhaseNew()30{31  cur_player^=1;32  enemy_player=cur_player^1;33  if (++phase>=PHASE_END) {34    IndirectResolveAll;35    TurnNew;36  }37 38  SleepUntil(msg_off_timeout);39  msg_off_timeout=cnts.jiffies+JIFFY_FREQ*2*animation_delay+1;40  Snd(74);41  switch (phase) {42    case PHASE_INDIRECT0:43    case PHASE_INDIRECT1:44      StrPrint(msg_buf,"Player %d Artillery Plot",cur_player+1);45      break;46    case PHASE_MOVE0:47    case PHASE_MOVE1:48      StrPrint(msg_buf,"Player %d Move",cur_player+1);49      break;50    case PHASE_DIRECT0:51    case PHASE_DIRECT1:52      StrPrint(msg_buf,"Player %d Fire",cur_player+1);53      break;54  }55}56 57U0 CharDo(U8 ch)58{59  I64 old_inhibit,old_draw_it;60  Bool old_cursor;61  switch (ch) {62    case CH_ESC:63    case CH_SHIFT_ESC:64      throw('ExitGame',TRUE);65    case CH_SPACE:66      throw('PhaseOvr',TRUE);67    case '\n':68      throw('NewGame',TRUE);69    case '1':70      ViewPlayerSet(0);71      break;72    case '2':73      ViewPlayerSet(1);74      break;75    case 'c':76      old_draw_it=Fs->draw_it;77      old_inhibit=Fs->win_inhibit;78      Fs->draw_it=Fs->next_settings->draw_it;79      Fs->win_inhibit=WIG_USER_TASK_DFT;80      old_cursor=DocCursor(ON);81      DocBottom;82      "\n$GREEN$<SHIFT-ESC>$FG$ to return to game.\n";83      View;84      DocBottom;85      DocCursor(old_cursor);86      Fs->win_inhibit=old_inhibit;87      Fs->draw_it=old_draw_it;88      break;89    case 'd':90      AnimationDelaySet;91      break;92  }93}94 95U0 UserChk()96{97  I64 ch;98  if (!alive_cnt[0] || !alive_cnt[1])99    throw('GameOver',TRUE);100  if (ch=ScanChar)101    CharDo(ch);102}103 104U0 TaskEndCB()105{106  Snd;107  progress4=progress4_max=progress1=progress1_max=0;108  Exit;109}110 111I64 PhaseDo()112{113  I64 res='ExitGame';114  PhaseNew;115  try {116    if (phase&~1==PHASE_INDIRECT)117      Call(player_indirect[cur_player]);118    else if (phase&~1==PHASE_MOVE)119      Call(player_move[cur_player]);120    else121      Call(player_direct[cur_player]);122  } catch {123    res=Fs->except_ch;124    Fs->catch_except=TRUE;125  }126  return res;127}128 129U0 ToTheFront()130{131  I64 res,ch;132  map_dc=DCNew(MAP_WIDTH,MAP_HEIGHT);133 134  SettingsPush; //See SettingsPush135  Cd(__DIR__);136  Fs->win_inhibit|=WIF_SELF_MS_L|WIF_SELF_MS_R|WIG_DBL_CLICK;137 138  MenuPush(139        "File {"140        "  Abort(,CH_SHIFT_ESC);"141        "  Exit(,CH_ESC);"142        "}"143        "Play {"144        "  EndPhase(,CH_SPACE);"145        "  Restart(,'\n');"146        "}"147        "View {"148        "  Player1(,'1');"149        "  Player2(,'2');"150        "  OddsCalculations(,'c');"151        "  LOS(,0,SCF_SHIFT);"152        "}"153        "Settings {"154        "  AnimationDelay(,'d');"155        "}"156        );157 158  AutoComplete;159  WinBorder;160  WinMax;161  DocCursor;162  DocMax;163  Init;164  PlayerPick("AIs",0);165  PlayerPick("AIs",1);166 167  PopUpOk("$PURPLE$$TX+CX,\"ToTheFront\"$$FG$\n\n"168        "$GREEN${Left-click}$FG$ to move or fire units.\n"169        "$GREEN$<SPACE>$FG$\tor $GREEN${Right-click}$FG$ to end phase.\n"170        "$GREEN$<SHIFT>$FG$\tto show line-of-sight.\n"171        "$GREEN$<ENTER>$FG$\tto start new game.\n"172        "$GREEN$  1$FG$\tPlayer 1 view.\n"173        "$GREEN$  2$FG$\tPlayer 2 view.\n"174        "$GREEN$  c$FG$\tView odds calculations.\n"175        "$GREEN$  d$FG$\tSet animation delay.");176  Fs->task_end_cb=&TaskEndCB; //<CTRL-ALT-x>177  Fs->draw_it=&DrawIt;178  try {179    do {180      res=PhaseDo;181      if (res=='GameOver') {182        while (TRUE) {183          msg_off_timeout=0;184          StrCpy(msg_buf,"Game Over");185          Snd;186          ch=GetChar(,FALSE);187          if (ch=='\n') {188            CleanUp;189            Init;190            break;191          } else if (ch==CH_ESC || ch==CH_SHIFT_ESC) {192            res='ExitGame';193            break;194          } else if (ch=='1')195            ViewPlayerSet(0);196          else if (ch=='2')197            ViewPlayerSet(1);198          else if (ch=='d')199            AnimationDelaySet;200        }201      } else if (res=='NewGame') {202        CleanUp;203        Init;204      }205    } while (res!='ExitGame');206  } catch207    PutExcept;208  ProgressBarsRst;209 210  SettingsPop;211  DCDel(map_dc);212  CleanUp;213  MenuPop;214  Seed;215}216