hschumann2/TempleOS-Source-Code
0838
1 2 3<1>/* Graphics Not Rendered in HTML */4 5U0 UnitDraw(CDC *dc,Unit *tmpu,I64 x,I64 y,F64 f)6{7 x+=x0; y+=y0;8 if (tmpu->infantry)9 Sprite3(dc,x,y,0,tmpu->img);10 else11 Sprite3ZB(dc,x,y,0,tmpu->img,f);12 if (phase&~1==PHASE_INDIRECT && tmpu->indirect_fire &&13 !tmpu->fired && tmpu->player==cur_player) {14 dc->thick=2;15 if (cur_player)16 dc->color=PURPLE;17 else18 dc->color=CYAN;19 GrCircle3(dc,x,y,0,20*Saw(4*tS,2.0));20 GrCircle3(dc,x,y,0,20*Saw(4*tS+1.0,2.0));21 dc->thick=1;22 }23}24 25U0 UnitsDraw(CDC *dc)26{27 I64 i,j;28 F64 x,y;29 Unit *tmpu;30 for (j=0;j<2;j++) {31 for (i=0;i<UNITS_NUM;i++) {32 tmpu=&units[j][i];33 if (tmpu==target_unit) {34 if (target_hit)35 dc->color=RED;36 else37 dc->color=GREEN;38 } else {39 if (j)40 dc->color=LTPURPLE;41 else42 dc->color=LTCYAN;43 }44 if (tmpu->life>0 && Bt(&tmpu->vis[view_player],0) &&45 tmpu!=moving_unit) {46 RowCol2XY(&x,&y,tmpu->row,tmpu->col);47 if (phase&~1==PHASE_MOVE && tmpu->remaining_movement ||48 (phase&~1==PHASE_INDIRECT&& tmpu->indirect_fire||49 phase&~1==PHASE_DIRECT&&!tmpu->indirect_fire) && !tmpu->fired ||50 Blink(5))51 UnitDraw(dc,tmpu,x,y,tmpu->facing*60.0*pi/180.0);52 }53 }54 }55}56 57U0 DrawIt(CTask *task,CDC *dc)58{59 F64 x,y;60 I64 i,j,r,c;61 U8 buf[STR_LEN];62 IndirectOrders *tmpi;63 64 //Erase text beneath.65 dc->color=WHITE;66 GrRect(dc,-task->scroll_x,-task->scroll_y,dc->width,dc->height);67 68 map_dc->flags|=DCF_NO_TRANSPARENTS;69 GrBlot(dc,x0,y0,map_dc);70 71 i=ms.pos.x-task->pix_left-task->scroll_x;72 j=ms.pos.y-task->pix_top -task->scroll_y;73 if (CursorInWin(task,i,j)) {74 i-=x0; j-=y0;75 CursorUpdate(task,i,j);76 }77 RowCol2XY(&x,&y,cursor_row,cursor_col);78 79 //Roads require multiple cursor fills80 dc->color=YELLOW;81 c=terrain[cursor_row][cursor_col];82 for (i=-(HEX_SIDE+DCOS)/2;i<=(HEX_SIDE+DCOS)/2;i++) {83 if (GrPeek(dc,x+i+x0,y+y0)==c)84 GrFloodFill(dc,x+i+x0,y+y0);85 for (j=-HEX_SIDE/2;j<=HEX_SIDE/2;j++)86 if (GrPeek(dc,x+j+x0,y+i+y0)==c)87 GrFloodFill(dc,x+j+x0,y+i+y0);88 }89 90 UnitsDraw(dc);91 if (firing) {92 dc->color=BLACK;93 GrCircle(dc,fire_x+x0,fire_y+y0,2);94 }95 if (indirect_explosion) {96 for (i=0;i<7;i++) {97 if (indirect_row&1)98 c=indirect_col+col_offsets_odd[i];99 else100 c=indirect_col+col_offsets_even[i];101 r=indirect_row+row_offsets[i];102 if (0<=r<map_rows && 0<=c<map_cols) {103 RowCol2XY(&x,&y,r,c);104 for (j=0;j<10;j++) {105 if (j&1)106 dc->color=LTRED;107 else108 dc->color=YELLOW;109 GrCircle(dc,x+RandU16%HEX_SIDE-HEX_SIDE/2+x0,110 y+RandU16%HEX_SIDE-HEX_SIDE/2+y0,2);111 }112 }113 }114 }115 if (moving_unit && moving_unit->vis[view_player]) {116 dc->color=YELLOW;117 UnitDraw(dc,moving_unit,move_x,move_y,move_facing);118 }119 ProgressBarsRst;120 if (moving_unit) {121 if (ms.pos.y<GR_HEIGHT/2) {122 progress4_max=moving_unit->movement;123 progress4=moving_unit->remaining_movement;124 } else {125 progress1_max=moving_unit->movement;126 progress1=moving_unit->remaining_movement;127 }128 }129 if (fire_radius) {130 dc->color=YELLOW;131 GrCircle(dc,fire_radius_x+x0,fire_radius_y+y0,fire_radius-1);132 GrCircle(dc,fire_radius_x+x0,fire_radius_y+y0,fire_radius+1);133 dc->color=RED;134 GrCircle(dc,fire_radius_x+x0,fire_radius_y+y0,fire_radius);135 }136 if (Blink(10)) {137 tmpi=indirect_head.next;138 while (tmpi!=&indirect_head) {139 if (tmpi->attacker->player==view_player) {140 RowCol2XY(&x,&y,tmpi->row,tmpi->col);141 Sprite3(dc,x+x0,y+y0,0,<1>);142 }143 tmpi=tmpi->next;144 }145 }146 if (Bt(kbd.down_bitmap,SC_SHIFT)) {147 if (show_vis_row!=cursor_row || show_vis_col!=cursor_col) {148 show_vis_row=cursor_row;149 show_vis_col=cursor_col;150 VisRecalcMap(show_vis_row,show_vis_col);151 }152 153 dc->color=LTGRAY;154 for (j=0;j<map_rows;j++)155 for (i=0;i<map_cols;i++)156 if (!vis_map[j][i]) {157 RowCol2XY(&x,&y,j,i);158 GrLine(dc,x-6+x0,y-6+y0,x+6+x0,y+6+y0);159 GrLine(dc,x+6+x0,y-6+y0,x-6+x0,y+6+y0);160 GrLine(dc,x+x0,y-6+y0,x+x0,y+6+y0);161 GrLine(dc,x+6+x0,y+y0,x-6+x0,y+y0);162 }163 }164 if (i=StrLen(msg_buf)*FONT_WIDTH) {165 dc->color=BLACK;166 GrRect(dc,(task->pix_width-i)>>1-10-task->scroll_x,167 (task->pix_height-FONT_HEIGHT)>>1-10-task->scroll_y,168 i+20,FONT_HEIGHT+20);169 170 dc->color=YELLOW;171 GrRect(dc,(task->pix_width-i)>>1-7-task->scroll_x,172 (task->pix_height-FONT_HEIGHT)>>1-7-task->scroll_y,173 i+14,FONT_HEIGHT+14);174 175 dc->color=RED;176 GrPrint(dc,(task->pix_width-i)>>1-task->scroll_x,177 (task->pix_height-FONT_HEIGHT)>>1-task->scroll_y,178 msg_buf);179 if (msg_off_timeout) {180 if (msg_off_timeout-cnts.jiffies<3*JIFFY_FREQ/2*animation_delay)181 Snd;182 if (cnts.jiffies>msg_off_timeout)183 *msg_buf=0;184 }185 }186 187 dc->color=WHITE;188 GrRect(dc,-task->scroll_x,-task->scroll_y,189 (13+7+10+10)*FONT_WIDTH,FONT_HEIGHT);190 191 if (phase&~1==PHASE_INDIRECT)192 StrPrint(buf,"Turn:%2d Artillery",turn);193 else if (phase&~1==PHASE_MOVE)194 StrPrint(buf,"Turn:%2d Move",turn);195 else196 StrPrint(buf,"Turn:%2d Fire",turn);197 dc->color=BLACK;198 GrPrint(dc,-task->scroll_x,-task->scroll_y,buf);199 200 StrPrint(buf,"%3d Units",alive_cnt[0]);201 if (cur_player || Blink)202 dc->color=CYAN;203 else204 dc->color=LTCYAN;205 GrPrint(dc,-task->scroll_x+(13+7)*FONT_WIDTH,-task->scroll_y,buf);206 207 StrPrint(buf,"%3d Units",alive_cnt[1]);208 if (!cur_player || Blink)209 dc->color=PURPLE;210 else211 dc->color=LTPURPLE;212 GrPrint(dc,-task->scroll_x+(13+7+10)*FONT_WIDTH,-task->scroll_y,buf);213}214 