CoolFace
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes838downloads
TTFInit.txt416 linesDownload Raw Back to ToTheFront
1 2/*I got tricky by not defining a color3right away in these CSprites so they can4work for both players by setting dc->color5before drawing them.  I actually made these6graphics by defining a color in the <CTRL-r>7menu, drawing the unit and deleting the color.8 9I had to leave a gap between the tank tread10and body because of how it is rendered when rotated.11*/12 13<1>/* Graphics Not Rendered in HTML */14 15<2>/* Graphics Not Rendered in HTML */16 17//This is an infantry.18 19<3>/* Graphics Not Rendered in HTML */20 21<4>/* Graphics Not Rendered in HTML */22 23 24U0 DrawHexes()25{26  F64 dx=2*HEX_SIDE+2*DCOS,dy=2*DSIN,27        x,y,x1,y1,x2,y2;28  I64 i,j;29  map_dc->color=WHITE;30  GrRect(map_dc,0,0,map_dc->width,map_dc->height);31  map_dc->color=BLACK;32  y=0;33  for (j=0;j<map_rows;j+=2) {34    x=DCOS;35    GrLine(map_dc,x,y,x-DCOS,y+DSIN);36    GrLine(map_dc,x-DCOS,y+DSIN,x,y+2*DSIN);37    for (i=0;i<map_cols;i++) {38      x1=x; y1=y;39      x2=x1+HEX_SIDE; y2=y1;40      GrLine(map_dc,x1,y1,x2,y2);41      x1=x2; y1=y2;42      x2+=DCOS; y2+=DSIN;43      GrLine(map_dc,x1,y1,x2,y2);44      GrLine(map_dc,x2,y2,x2-DCOS,y2+DSIN);45      x1=x2; y1=y2;46      x2+=HEX_SIDE;47      GrLine(map_dc,x1,y1,x2,y2);48      GrLine(map_dc,x2,y2,x2+DCOS,y2+DSIN);49      x1=x2; y1=y2;50      x2+=DCOS; y2-=DSIN;51      if (j || i<map_cols-1)52        GrLine(map_dc,x1,y1,x2,y2);53      x+=dx;54    }55    y+=dy;56  }57  x=DCOS;58  for (i=0;i<map_cols;i++) {59    x1=x; y1=y;60    x2=x1+HEX_SIDE; y2=y1;61    GrLine(map_dc,x1,y1,x2,y2);62    x1=x2; y1=y2;63    x2+=DCOS; y2+=DSIN;64    GrLine(map_dc,x1,y1,x2,y2);65    x1=x2; y1=y2;66    x2+=HEX_SIDE;67    GrLine(map_dc,x1,y1,x2,y2);68    x1=x2; y1=y2;69    x2+=DCOS; y2-=DSIN;70    GrLine(map_dc,x1,y1,x2,y2);71    x+=dx;72  }73}74 75U0 MakeTerrain(U8 color,I64 cnt,I64 clus_lo,I64 clus_hi)76{77  I64 i,j,l,row,col;78  for (i=0;i<cnt;i++) {79    col=RandU32%map_cols;80    row=RandU32%map_rows;81    l=clus_lo+RandU16%(clus_hi-clus_lo+1);82    for (j=0;j<l;j++) {83      terrain[row][col]=color;84      Toward(&row,&col,RandU16%6);85      col=ClampI64(col,0,map_cols-1);86      row=ClampI64(row,0,map_rows-1);87    }88  }89}90 91U0 MakeRivers()92{93  I64 i,row,col,direction;94  for (i=0;i<4;i++) {95    row=RandU32%map_rows;96    col=RandU32%map_cols;97    direction=RandU16%6;98    while (TRUE) {99      rivers[row][col]=TRUE;100      Toward(&row,&col,direction);101      if (!(0<=row<map_rows && 0<=col<map_cols))102        break;103      if (!(RandU16&3))104        direction=(direction+(7-RandU16%3))%6;105    }106  }107}108 109U0 MakeRoads()110{111  I64 i,row,col,direction;112  for (i=0;i<5;i++) {113    row=RandU32%map_rows;114    col=RandU32%map_cols;115    direction=RandU16%6;116    while (TRUE) {117      roads[row][col]=TRUE;118      Toward(&row,&col,direction);119      if (!(0<=row<map_rows && 0<=col<map_cols))120        break;121      if (!(RandU16%3))122        direction=(direction+(7-RandU16%3))%6;123    }124  }125}126 127U0 DrawTerrain()128{129  I64 i,j;130  F64 x,y;131  for (j=0;j<map_rows;j++)132    for (i=0;i<map_cols;i++) {133      map_dc->color=terrain[j][i];134      RowCol2XY(&x,&y,j,i);135      GrFloodFill(map_dc,x,y);136    }137}138 139U0 DrawRivers()140{141  I64 i,j,k,r,c;142  F64 x1,y1,x2,y2;143  for (j=0;j<map_rows;j++)144    for (i=0;i<map_cols;i++) {145      if (rivers[j][i]) {146        RowCol2XY(&x1,&y1,j,i);147        for (k=0;k<6;k++) {148          r=j;c=i;149          Toward(&r,&c,k);150          if (0<=r<map_rows && 0<=c<map_cols &&151                rivers[r][c]) {152            RowCol2XY(&x2,&y2,r,c);153            map_dc->color=LTBLUE;154            map_dc->thick=4;155            GrLine3(map_dc,x1,y1,0,x2,y2,0);156            map_dc->color=BLUE;157            map_dc->thick=2;158            GrLine3(map_dc,x1,y1,0,x2,y2,0);159          }160        }161      }162    }163}164 165U0 DrawRoads()166{167  I64 i,j,k,r,c;168  F64 x1,y1,x2,y2;169  map_dc->color=RED;170  map_dc->thick=3;171  for (j=0;j<map_rows;j++)172    for (i=0;i<map_cols;i++) {173      if (roads[j][i]) {174        RowCol2XY(&x1,&y1,j,i);175        for (k=0;k<6;k++) {176          r=j;c=i;177          Toward(&r,&c,k);178          if (0<=r<map_rows && 0<=c<map_cols &&179                roads[r][c]) {180            RowCol2XY(&x2,&y2,r,c);181            GrLine3(map_dc,x1,y1,0,x2,y2,0);182          }183        }184      }185    }186}187 188U0 DrawDots()189{190  I64 i,j;191  F64 x,y;192  map_dc->color=BLACK;193  for (j=0;j<map_rows;j++)194    for (i=0;i<map_cols;i++) {195      RowCol2XY(&x,&y,j,i);196      GrPlot(map_dc,x,y);197    }198}199 200U0 HexCentersCalc()201{202  I64 i,j;203  F64 x,y;204  for (j=0;j<map_rows;j++)205    for (i=0;i<map_cols;i++) {206      x=(2*HEX_SIDE+2*DCOS)*i+HEX_SIDE/2+DCOS;207      if (j&1)208        x+=HEX_SIDE+DCOS;209      y=DSIN*(j+1);210      hex_centers[j][i].x=x;211      hex_centers[j][i].y=y;212    }213}214 215U0 InitMap()216{217  HexCentersCalc;218  DrawHexes;219  MemSet(terrain,PLAINS,sizeof(terrain));220  MemSet(roads,FALSE,sizeof(roads));221  MemSet(rivers,FALSE,sizeof(rivers));222  MemSet(vis_map,FALSE,sizeof(vis_map));223  MakeTerrain(MOUNTAINS,0.03*map_cols*map_cols,5,35);224  MakeTerrain(TREES,0.03*map_cols*map_cols,5,35);225  DrawTerrain;226  MakeRivers;227  DrawRivers;228  MakeRoads;229  DrawRoads;230  DrawDots;231}232 233U0 InitUnits()234{235  I64 i,j,row,col,type;236  Unit *tmpu;237  MemSet(units,0,sizeof(units));238  alive_cnt[0]=alive_cnt[1]=UNITS_NUM;239  for (j=0;j<2;j++)240    for (i=0;i<alive_cnt[j];i++) {241      tmpu=&units[j][i];242      tmpu->player=j;243      tmpu->num=i;244      tmpu->life=100;245      tmpu->facing=RandU16%6;246      if (!j) {247        if (i>=UNITS_NUM/2) {248          if (i>=15*UNITS_NUM/16)249            type=UT_ARTILLERY;250          else251            type=UT_INFANTRY;252        } else {253          if (i>=UNITS_NUM/4)254            type=UT_MD_TANK;255          else256            type=UT_LT_TANK;257        }258      } else {259        if (i>=UNITS_NUM/2) {260          if (i>=15*UNITS_NUM/16)261            type=UT_ARTILLERY;262          else263            type=UT_INFANTRY;264        } else {265          if (i>=UNITS_NUM/4)266            type=UT_MD_TANK;267          else268            type=UT_LT_TANK;269        }270      }271      tmpu->type=type;272      switch (type) {273        case UT_INFANTRY:274          tmpu->infantry=TRUE;275          tmpu->indirect_fire=FALSE;276          tmpu->armor    =0;277          tmpu->armored_attack  =15;278          tmpu->unarmored_attack=180;279          tmpu->accuracy=45;280          tmpu->range    =5;281          tmpu->movement=4;282          tmpu->img      =<1>;283          break;284        case UT_ARTILLERY:285          tmpu->infantry=TRUE;286          tmpu->indirect_fire=TRUE;287          tmpu->armor    =0;288          tmpu->armored_attack  =60;289          tmpu->unarmored_attack=180;290          tmpu->accuracy=25;291          tmpu->range    =20;292          tmpu->movement=2;293          tmpu->img      =<2>;294          break;295        case UT_LT_TANK:296          tmpu->infantry=FALSE;297          tmpu->indirect_fire=FALSE;298          tmpu->armor    =30;299          tmpu->armored_attack  =40;300          tmpu->unarmored_attack=60;301          tmpu->accuracy=25;302          tmpu->range    =8;303          tmpu->movement=24;304          tmpu->img      =<3>;305          break;306        case UT_MD_TANK:307          tmpu->infantry=FALSE;308          tmpu->indirect_fire=FALSE;309          tmpu->armor    =60;310          tmpu->armored_attack  =60;311          tmpu->unarmored_attack=80;312          tmpu->accuracy=25;313          tmpu->range    =12;314          tmpu->movement=16;315          tmpu->img      =<4>;316          break;317      }318      do {319        row=RandU32%map_rows;320        col=RandU32%(map_cols/3);321        if (j)322          col+=2*map_cols/3;323      } while (UnitFind(row,col));324      tmpu->row=row;325      tmpu->col=col;326      LBts(&tmpu->vis[cur_player],0);327    }328}329 330U0 ViewPlayerSet(I8 p)331{332  CMenuEntry *tmpse;333  view_player=p;334  if (tmpse=MenuEntryFind(Fs->cur_menu,"View/Player1"))335    tmpse->checked= view_player==0;336  if (tmpse=MenuEntryFind(Fs->cur_menu,"View/Player2"))337    tmpse->checked= view_player==1;338}339 340U0 Init()341{342  DocClear;343  "GameSeed(0x%X)\n",Seed(PopUpGetI64("GameSeed(0x%X):",Seed));344  moving_unit=NULL;345  InitMap;346  ViewPlayerSet(cur_player=0);347  enemy_player=1;348  if (map_width<GR_WIDTH) {349    x0=(MAP_WIDTH-map_width)>>1;350    y0=(MAP_HEIGHT-map_height)>>1+FONT_HEIGHT;351  } else {352    x0=0;353    y0=FONT_HEIGHT;354  }355  InitUnits;356  QueInit(&indirect_head);357  turn=0;358  fire_radius=0;359  show_vis_row=-1;360  show_vis_col=-1;361  *msg_buf=0;362  msg_off_timeout=0;363  phase=PHASE_END;364}365 366U0 CleanUp()367{368  QueDel(&indirect_head,TRUE);369}370 371U0 PlayerPick(U8 *dirname,I64 player)372{373  I64 i=0;374  U8 *st;375  CDirEntry *tmpde,*tmpde1,*tmpde2;376  CDoc *doc=DocNew;377  Bool *old_silent=Silent;378  st=MStrPrint("%s/*.HC*",dirname);379  tmpde=FilesFind(st);380  Free(st);381  tmpde2=FilesFind("~/ToTheFront/*.HC*");382  tmpde1=tmpde;383  Silent(old_silent);384 385  DocPrint(doc,"Player %d Type\n\n$LTBLUE$",player+1);386  while (tmpde1) {387    if (!(i++&3))388      DocPrint(doc,"\n");389    st=StrNew(tmpde1->name);390    FileExtRem(st);391    tmpde1->user_data=DocPrint(doc,"$MU-UL,\"%-10ts\",LE=%d$ ",st,tmpde1);392    Free(st);393    tmpde1=tmpde1->next;394  }395  tmpde1=tmpde2;396  while (tmpde1) {397    if (!(i++&3))398      DocPrint(doc,"\n");399    st=StrNew(tmpde1->name);400    FileExtRem(st);401    tmpde1->user_data=DocPrint(doc,"$MU-UL,\"%-10ts\",LE=%d$ ",st,tmpde1);402    Free(st);403    tmpde1=tmpde1->next;404  }405  DocPrint(doc,"\n\n\n$FG$Create your own AI in ~/ToTheFront.");406  while ((tmpde1=PopUpMenu(doc))<=0);407  ExeFile(tmpde1->full_name);408  DocDel(doc);409  DirTreeDel(tmpde);410  DirTreeDel(tmpde2);411  ExePrint("player_indirect[%d]=&PlayerIndirect;"412        "player_move[%d]=&PlayerMove;"413        "player_direct[%d]=&PlayerDirect;",414        player,player,player);415}416