hschumann2/TempleOS-Source-Code
0838
1 2U0 PlayerIndirect()3{4 Unit *tmpu=NULL;5 I64 i,remaining=0,msg_code,arg1,arg2;6 F64 target_x,target_y;7 ViewPlayerSet(cur_player);8 for (i=0;i<UNITS_NUM;i++) {9 tmpu=&units[cur_player][i];10 if (tmpu->life>0 && tmpu->indirect_fire)11 remaining++;12 }13 while (remaining) {14 if (!alive_cnt[0] || !alive_cnt[1])15 throw('GameOver',TRUE);16 msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_L_UP|17 1<<MSG_MS_R_UP);18 switch (msg_code) {19 case MSG_KEY_DOWN:20 CharDo(arg1);21 break;22 case MSG_MS_L_DOWN:23 if (CursorInWin(Fs,arg1,arg2)) {24 arg1-=x0; arg2-=y0;25 CursorUpdate(Fs,arg1,arg2);26 if (tmpu=UnitFind(cursor_row,cursor_col)) {27 if (tmpu->player==enemy_player || tmpu->fired ||28 !tmpu->indirect_fire)29 tmpu=NULL;30 else {31 RowCol2XY(&fire_radius_x,&fire_radius_y,tmpu->row,tmpu->col);32 fire_radius=tmpu->range*2*HEX_RADIUS;33 }34 }35 }36 break;37 case MSG_MS_L_UP:38 if (CursorInWin(Fs,arg1,arg2)) {39 arg1-=x0; arg2-=y0;40 CursorUpdate(Fs,arg1,arg2);41 RowCol2XY(&target_x,&target_y,cursor_row,cursor_col);42 if (!tmpu)43 Beep;44 else {45 if (Sqrt(Sqr(fire_radius_x-target_x)+Sqr(fire_radius_y-target_y))>46 fire_radius)47 Beep;48 else {49 IndirectAdd(tmpu,cursor_row,cursor_col);50 remaining--;51 }52 }53 }54 tmpu=NULL;55 fire_radius=0;56 break;57 case MSG_MS_R_UP:58 if (CursorInWin(Fs,arg1,arg2))59 throw('PhaseOvr',TRUE);60 break;61 }62 }63 throw('PhaseOvr',TRUE);64}65 66U0 PlayerMove()67{68 Unit *tmpu=NULL;69 I64 msg_code,arg1,arg2;70 ViewPlayerSet(cur_player);71 while (TRUE) {72 if (!alive_cnt[0] || !alive_cnt[1])73 throw('GameOver',TRUE);74 msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_L_UP|75 1<<MSG_MS_R_UP);76 switch (msg_code) {77 case MSG_KEY_DOWN:78 CharDo(arg1);79 break;80 case MSG_MS_L_DOWN:81 if (CursorInWin(Fs,arg1,arg2)) {82 arg1-=x0; arg2-=y0;83 CursorUpdate(Fs,arg1,arg2);84 if (tmpu=UnitFind(cursor_row,cursor_col)) {85 if (tmpu->player==enemy_player || !tmpu->remaining_movement)86 tmpu=NULL;87 }88 }89 break;90 case MSG_MS_L_UP:91 if (CursorInWin(Fs,arg1,arg2)) {92 arg1-=x0; arg2-=y0;93 CursorUpdate(Fs,arg1,arg2);94 if (!tmpu)95 Beep;96 else {97 UnitMove(tmpu,arg1,arg2);98 break;99 }100 }101 tmpu=NULL;102 break;103 case MSG_MS_R_UP:104 if (CursorInWin(Fs,arg1,arg2))105 throw('PhaseOvr',TRUE);106 break;107 }108 }109}110 111U0 PlayerDirect()112{113 Unit *tmpu=NULL,*target;114 I64 msg_code,arg1,arg2;115 ViewPlayerSet(cur_player);116 while (TRUE) {117 if (!alive_cnt[0] || !alive_cnt[1])118 throw('GameOver',TRUE);119 msg_code=GetMsg(&arg1,&arg2,1<<MSG_KEY_DOWN|1<<MSG_MS_L_DOWN|1<<MSG_MS_L_UP|120 1<<MSG_MS_R_UP);121 switch (msg_code) {122 case MSG_KEY_DOWN:123 CharDo(arg1);124 break;125 case MSG_MS_L_DOWN:126 if (CursorInWin(Fs,arg1,arg2)) {127 arg1-=x0; arg2-=y0;128 CursorUpdate(Fs,arg1,arg2);129 if (tmpu=UnitFind(cursor_row,cursor_col)) {130 if (tmpu->player==enemy_player || tmpu->fired ||131 tmpu->indirect_fire)132 tmpu=NULL;133 else {134 VRSetUp(cur_player);135 RowCol2XY(&fire_radius_x,&fire_radius_y,tmpu->row,tmpu->col);136 fire_radius=tmpu->range*2*HEX_RADIUS;137 VisRecalc(VR_ONE_FRIENDLY_UNIT,tmpu);138 }139 }140 }141 break;142 case MSG_MS_L_UP:143 if (CursorInWin(Fs,arg1,arg2)) {144 arg1-=x0; arg2-=y0;145 CursorUpdate(Fs,arg1,arg2);146 target=UnitFind(cursor_row,cursor_col);147 if (!tmpu)148 Beep;149 else {150 if (!target || target->player!=enemy_player ||151 !Bt(&target->vis,0))152 Beep;153 else154 UnitDirectFire(tmpu,target);155 VisRecalc(VR_UPDATE_FRIENDLY_UNIT,tmpu);156 }157 }158 tmpu=NULL;159 fire_radius=0;160 break;161 case MSG_MS_R_UP:162 if (CursorInWin(Fs,arg1,arg2))163 throw('PhaseOvr',TRUE);164 break;165 }166 }167}168 