1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
|
/*
* Seven Kingdoms: Ancient Adversaries
*
* Copyright 1997,1998 Enlight Software Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Filename : OU_MARI.CPP
// Description : sea unit
#include <OSYS.h>
#include <OTERRAIN.h>
#include <OU_CARA.h>
#include <OPOWER.h>
#include <OU_MARI.h>
#include <OREMOTE.h>
#include <ONATIONA.h>
#include <OCONFIG.h>
#ifdef DEBUG2
#include <OFONT.h>
#endif
//------- Define constant ----------//
const int WAVE_CYCLE = 8;
//------- Begin of function UnitMarine::UnitMarine -------//
UnitMarine::UnitMarine()
{
menu_mode = 0;
extra_move_in_beach = NO_EXTRA_MOVE;
in_beach = 0;
selected_unit_id = 0;
//------- transporting units vars ---------//
unit_count = 0;
memset(unit_recno_array, 0, sizeof(short)*MAX_UNIT_IN_SHIP);
//------- transporting goods vars ---------//
memset( stop_array, 0, MAX_STOP_FOR_SHIP * sizeof(ShipStop) );
journey_status = ON_WAY_TO_FIRM;
dest_stop_id = 0;
stop_defined_num = 0;
wait_count = 0;
stop_x_loc = 0;
stop_y_loc = 0;
memset(raw_qty_array, 0, sizeof(short)*MAX_RAW);
memset(product_raw_qty_array, 0, sizeof(short)*MAX_PRODUCT);
auto_mode = 1; // there should be no button to toggle it if the ship is only for trading
cur_firm_recno = 0;
}
//------- End of function UnitMarine::UnitMarine -------//
//------- Begin of function UnitMarine::~UnitMarine -------//
UnitMarine::~UnitMarine()
{
//-------- del those units in the ship -------//
for(int i=0; i<unit_count; i++)
{
if( !unit_array.SpriteArray::is_deleted(unit_recno_array[i]) )
unit_array.del(unit_recno_array[i]);
}
}
//------- End of function UnitMarine::~UnitMarine -------//
//------- Begin of function UnitMarine::init -------//
void UnitMarine::init(int unitId, int nationRecno, int rankId, int unitLoyalty, int startX, int startY)
{
attack_mode_selected = 0; // for fix_attack_info() to set attack_info_array
Unit::init(unitId, nationRecno, rankId, unitLoyalty, startX, startY);
short spriteId = sprite_info->get_sub_sprite_info(1)->sprite_id;
splash.init( spriteId, cur_x_loc(), cur_y_loc() );
splash.cur_frame = 1;
//------- set carry_goods_capacity -------//
carry_goods_capacity = unit_res[unitId]->carry_goods_capacity;
//------- set menu mode of the unit -------//
UnitInfo* unitInfo = unit_res[unitId];
if( unitInfo->carry_unit_capacity==0 && unitInfo->carry_goods_capacity>0 ) // if this ship only carries goods
menu_mode = SHIP_MENU_GOODS;
else
menu_mode = SHIP_MENU_UNIT;
}
//------- End of function UnitMarine::init -------//
//------- Begin of function UnitMarine::update_abs_pos ------//
void UnitMarine::update_abs_pos(SpriteFrame *spriteFrame)
{
Unit::update_abs_pos(spriteFrame);
short h = wave_height(6);
abs_y1 -= h;
abs_y2 -= h;
}
//------- End of function UnitMarine::update_abs_pos -------//
//------- Begin of function UnitMarine::draw -------//
void UnitMarine::draw()
{
// -------- update splash parameter --------//
// ###### begin Gilbert 8/9 #######//
char oldSplashAction = splash.cur_action;
switch(cur_action)
{
case SPRITE_MOVE:
splash.cur_action = SPRITE_MOVE;
if( splash.cur_action != oldSplashAction)
splash.cur_frame = 1;
else
{
++splash.cur_frame;
if( splash.cur_frame < 1 || splash.cur_frame > splash.cur_sprite_move()->frame_count )
splash.cur_frame = 1;
}
break;
default:
splash.cur_action = SPRITE_IDLE;
if( splash.cur_action != oldSplashAction)
splash.cur_frame = 1;
else
{
++splash.cur_frame;
if( splash.cur_frame < 1 || splash.cur_frame > splash.cur_sprite_stop()->frame_count)
splash.cur_frame = 1;
}
break;
}
// ###### end Gilbert 8/9 #######//
splash.cur_x = cur_x;
splash.cur_y = cur_y - wave_height(7);
splash.cur_dir = cur_dir;
splash.final_dir = final_dir;
splash.turn_delay = turn_delay;
// --------- draw splash and then the unit --------//
// ###### begin Gilbert 24/9 #######//
if( cur_action != SPRITE_DIE )
splash.draw();
// ###### end Gilbert 24/9 #######//
Unit::draw();
#ifdef DEBUG2
if(selected_flag && 0)
{
vga_util.d3_panel_up( INFO_X1, INFO_Y1+144, INFO_X2, INFO_Y1+144+87 );
int x=INFO_X1+4, y=INFO_Y1+200, refreshFlag=INFO_REPAINT;
font_san.field( x, y, " " , x+2, sprite_recno, 1, INFO_X2-2, refreshFlag);
font_san.field( x+20, y, " " , x+22, next_x_loc(), 1, INFO_X2-2, refreshFlag);
font_san.field( x+50, y, " " , x+52, next_y_loc(), 1, INFO_X2-2, refreshFlag);
font_san.field( x+70, y, " " , x+72, nation_recno, 1, INFO_X2-2, refreshFlag);
font_san.field( x+100, y, " " , x+102, action_mode, 1, INFO_X2-2, refreshFlag);
font_san.field( x+120, y, " " , x+122, action_para, 1, INFO_X2-2, refreshFlag);
font_san.field( x+140, y, " " , x+142, action_x_loc, 1, INFO_X2-2, refreshFlag);
font_san.field( x+160, y, " " , x+162, action_y_loc, 1, INFO_X2-2, refreshFlag);
y-=20;
font_san.field( x+100, y, " " , x+102, action_mode2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+120, y, " " , x+122, action_para2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+140, y, " " , x+142, action_x_loc2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+160, y, " " , x+162, action_y_loc2, 1, INFO_X2-2, refreshFlag);
y-=20;
font_san.field( x+160, y, " " , x+162, cur_action, 1, INFO_X2-2, refreshFlag);
}
#endif
}
//------- End of function UnitMarine::draw -------//
//------- Begin of function UnitMarine::draw_outlined -------//
void UnitMarine::draw_outlined()
{
// -------- update splash parameter --------//
// ###### begin Gilbert 8/9 #######//
char oldSplashAction = splash.cur_action;
switch(cur_action)
{
case SPRITE_MOVE:
splash.cur_action = SPRITE_MOVE;
if( splash.cur_action != oldSplashAction)
splash.cur_frame = 1;
else
{
++splash.cur_frame;
if( splash.cur_frame < 1 || splash.cur_frame > splash.cur_sprite_move()->frame_count )
splash.cur_frame = 1;
}
break;
default:
splash.cur_action = SPRITE_IDLE;
if( splash.cur_action != oldSplashAction)
splash.cur_frame = 1;
else
{
++splash.cur_frame;
if( splash.cur_frame < 1 || splash.cur_frame > splash.cur_sprite_stop()->frame_count)
splash.cur_frame = 1;
}
break;
}
// ###### end Gilbert 8/9 #######//
splash.cur_x = cur_x;
splash.cur_y = cur_y - wave_height(7);
splash.cur_dir = cur_dir;
splash.final_dir = final_dir;
splash.turn_delay = turn_delay;
// --------- draw splash and then the unit --------//
// ###### begin Gilbert 24/9 #######//
if( cur_action != SPRITE_DIE )
splash.draw();
// ###### end Gilbert 24/9 #######//
Unit::draw_outlined();
#ifdef DEBUG2
if(selected_flag && 0)
{
vga_util.d3_panel_up( INFO_X1, INFO_Y1+144, INFO_X2, INFO_Y1+144+87 );
int x=INFO_X1+4, y=INFO_Y1+200, refreshFlag=INFO_REPAINT;
font_san.field( x, y, " " , x+2, sprite_recno, 1, INFO_X2-2, refreshFlag);
font_san.field( x+20, y, " " , x+22, next_x_loc(), 1, INFO_X2-2, refreshFlag);
font_san.field( x+50, y, " " , x+52, next_y_loc(), 1, INFO_X2-2, refreshFlag);
font_san.field( x+70, y, " " , x+72, nation_recno, 1, INFO_X2-2, refreshFlag);
font_san.field( x+100, y, " " , x+102, action_mode, 1, INFO_X2-2, refreshFlag);
font_san.field( x+120, y, " " , x+122, action_para, 1, INFO_X2-2, refreshFlag);
font_san.field( x+140, y, " " , x+142, action_x_loc, 1, INFO_X2-2, refreshFlag);
font_san.field( x+160, y, " " , x+162, action_y_loc, 1, INFO_X2-2, refreshFlag);
y-=20;
font_san.field( x+100, y, " " , x+102, action_mode2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+120, y, " " , x+122, action_para2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+140, y, " " , x+142, action_x_loc2, 1, INFO_X2-2, refreshFlag);
font_san.field( x+160, y, " " , x+162, action_y_loc2, 1, INFO_X2-2, refreshFlag);
y-=20;
font_san.field( x+160, y, " " , x+162, cur_action, 1, INFO_X2-2, refreshFlag);
}
#endif
}
//------- End of function UnitMarine::draw_outlined -------//
//------- Begin of function UnitMarine::wave_height -------//
short UnitMarine::wave_height(int phase)
{
err_when( phase < 0);
static short height[WAVE_CYCLE] = { 4,3,2,1,0,1,2,3 };
return height[((sys.frame_count /4) + phase) % WAVE_CYCLE];
}
//------- End of function UnitMarine::wave_height -------//
//--------- Begin of function UnitMarine::del_unit ---------//
//
// Delete a unit from the ship. This function is called by
// Unit::deinit() when the unit is killed.
//
// <int> unitRecno - recno of the unit to be loaded.
//
void UnitMarine::del_unit(int unitRecno)
{
for( int i=0 ; i<unit_count ; i++ )
{
if( unit_recno_array[i] == unitRecno )
{
err_when( unit_count > MAX_UNIT_IN_SHIP );
misc.del_array_rec(unit_recno_array, unit_count, sizeof(unit_recno_array[0]), i+1);
return;
}
}
err_here();
}
//----------- End of function UnitMarine::del_unit -----------//
//--------- Begin of function UnitMarine::load_unit ---------//
//
// Load an unit to the ship.
//
// <int> unitRecno - recno of the unit to be loaded.
//
void UnitMarine::load_unit(int unitRecno)
{
if(unit_array.is_deleted(unitRecno))
return;
Unit *unitPtr = unit_array[unitRecno];
if(unitPtr->hit_points<=0 || unitPtr->cur_action==SPRITE_DIE || unitPtr->action_mode2==ACTION_DIE)
return;
if( unit_count == MAX_UNIT_IN_SHIP )
return;
unit_recno_array[unit_count++] = unitRecno;
unitPtr->set_mode(UNIT_MODE_ON_SHIP, sprite_recno); // set unit mode
if(unitPtr->selected_flag)
{
unitPtr->selected_flag = 0;
unit_array.selected_count--;
}
unitPtr->deinit_sprite();
//--- if this marine unit is currently selected ---//
if(unit_array.selected_recno==sprite_recno)
{
if(!remote.is_enable() || nation_recno==nation_array.player_recno || config.show_ai_info)
disp_info(INFO_UPDATE);
}
}
//----------- End of function UnitMarine::load_unit -----------//
//--------- Begin of function UnitMarine::unload_unit ---------//
//
// Unload an unit from the ship.
//
// <int> unitSeqId - sequence id. of the unit in unit_recno_array[]
//
void UnitMarine::unload_unit(int unitSeqId, char remoteAction)
{
err_when(unitSeqId > unit_count);
if(!remoteAction && remote.is_enable() )
{
// packet structure : <unit recno> <unitSeqId>
short *shortPtr = (short *)remote.new_send_queue_msg(MSG_U_SHIP_UNLOAD_UNIT, 2*sizeof(short));
*shortPtr = sprite_recno;
shortPtr[1] = unitSeqId;
return;
}
//-------- unload unit now -------//
if( unloading_unit(0, unitSeqId-1) ) // unit is unloaded
{
err_when( unit_count+1 > MAX_UNIT_IN_SHIP );
misc.del_array_rec(unit_recno_array, unit_count+1, sizeof(unit_recno_array[0]), unitSeqId);
}
}
//----------- End of function UnitMarine::unload_unit -----------//
//--------- Begin of function UnitMarine::unload_all_units ---------//
void UnitMarine::unload_all_units(char remoteAction)
{
if(!remoteAction && remote.is_enable() )
{
// packet structure : <unit recno>
short *shortPtr = (short *)remote.new_send_queue_msg(MSG_U_SHIP_UNLOAD_ALL_UNITS, sizeof(short));
*shortPtr = sprite_recno;
return;
}
unloading_unit(1); // unload all units
}
//----------- End of function UnitMarine::unload_all_units -----------//
//--------- Begin of function UnitMarine::unloading_unit ---------//
//
// <int> isAll - 1 for unload all the units
// - otherwise 0
// <int> unitSeqId - if(isAll==0) unitSeqId+1 is the recno of the
// selected unit in unit_recno_array[]
//
int UnitMarine::unloading_unit(int isAll, int unitSeqId)
{
if( !is_on_coast() )
return 0;
//-------------------------------------------------------------------------//
// return if no territory is nearby the ship
//-------------------------------------------------------------------------//
int curXLoc = next_x_loc(); // ship location
int curYLoc = next_y_loc();
int unprocess = isAll ? unit_count : 1;
Unit *unitPtr = isAll ? unit_array[unit_recno_array[unprocess-1]] : unit_array[unit_recno_array[unitSeqId]];
Location *locPtr;
int xShift, yShift, checkXLoc, checkYLoc;
int regionId = 0; // unload all the units in the same territory
int found = 0, i = 2;
int sqtSize = 5, sqtArea = sqtSize*sqtSize;
#ifdef DEBUG
long debugCount = 0L;
#endif
if(isAll && nation_recno == nation_array.player_recno ) // for player's camp, patrol() can only be called when the player presses the button.
power.reset_selection();
while(unprocess) // using the calculated 'i' to reduce useless calculation
{
err_when(debugCount++ > 4*long(MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC));
misc.cal_move_around_a_point(i, MAX_WORLD_X_LOC, MAX_WORLD_Y_LOC, xShift, yShift);
checkXLoc = curXLoc+xShift;
checkYLoc = curYLoc+yShift;
if(checkXLoc<0 || checkXLoc>=MAX_WORLD_X_LOC || checkYLoc<0 || checkYLoc>=MAX_WORLD_Y_LOC)
{
i++;
continue;
}
locPtr = world.get_loc(checkXLoc, checkYLoc);
//-------------------------------------------------------------------------//
// check for space to unload the unit
//-------------------------------------------------------------------------//
if(!regionId || locPtr->region_id == regionId)
{
if(locPtr->walkable())
found = 1;
if(locPtr->can_move(UNIT_LAND))//unitPtr->mobile_type))
{
regionId = locPtr->region_id;
unitPtr->init_sprite(checkXLoc, checkYLoc);
unitPtr->set_mode(0);
if( isAll && nation_recno == nation_array.player_recno ) // for player's camp, patrol() can only be called when the player presses the button.
{
unitPtr->selected_flag = 1; // mark selected if unload all
unit_array.selected_count++;
if( !unit_array.selected_recno )
unit_array.selected_recno = unitPtr->sprite_recno;
}
unprocess--;
unit_count--;
if(unprocess)
unitPtr = unit_array[unit_recno_array[unprocess-1]]; // point to next unit
else
break; // finished, all have been unloaded
}
}
//-------------------------------------------------------------------------//
// stop checking if there is totally bouned by unacessible location
//-------------------------------------------------------------------------//
if(i==sqtArea)
{
if(found)
{
found = 0; // reset found
sqtSize += 2;
sqtArea = sqtSize*sqtSize;
}
else // no continuous location for the unit to unload, some units can't be unloaded
return 0;
}
i++;
}
//-------- display info --------//
if( nation_recno == nation_array.player_recno ) // for player's camp, patrol() can only be called when the player presses the button.
info.disp();
return 1;
}
//----------- End of function UnitMarine::unloading_unit -----------//
//--------- Begin of function UnitMarine::is_on_coast ---------//
//
// Return whether the unit is on the coast and ready for unloading.
//
int UnitMarine::is_on_coast()
{
Location *locPtr;
int xShift, yShift, checkXLoc, checkYLoc, found=0;
int curXLoc = next_x_loc(); // ship location
int curYLoc = next_y_loc();
for(int i=2; i<=9; i++) // checking for the surrouding location
{
misc.cal_move_around_a_point(i, 3, 3, xShift, yShift);
checkXLoc = curXLoc + xShift;
checkYLoc = curYLoc + yShift;
if(checkXLoc<0 || checkXLoc>=MAX_WORLD_X_LOC || checkYLoc<0 || checkYLoc>=MAX_WORLD_Y_LOC)
continue;
locPtr = world.get_loc(checkXLoc, checkYLoc);
if(terrain_res[locPtr->terrain_id]->average_type!=TERRAIN_OCEAN && // a territory nearby
locPtr->walkable())
{
return 1;
}
}
return 0;
}
//----------- End of function UnitMarine::is_on_coast -----------//
//--------- Begin of function UnitMarine::extra_move ---------//
void UnitMarine::extra_move()
{
static char offset[3] = {0, 1, -1};
int curXLoc = next_x_loc();
int curYLoc = next_y_loc();
int vecX = action_x_loc2 - curXLoc;
int vecY = action_y_loc2 - curYLoc;
int checkXLoc, checkYLoc, i, found=0;
if(vecX==0 || vecY==0)
{
if(vecX==0)
{
vecY /= abs(vecY);
checkYLoc = curYLoc + vecY;
}
else // vecY==0
{
vecX /= abs(vecX);
checkXLoc = curXLoc + vecX;
}
for(i=0; i<3; i++)
{
if(vecX==0)
checkXLoc = curXLoc + offset[i];
else
checkYLoc = curYLoc + offset[i];
if(checkXLoc<0 || checkXLoc>=MAX_WORLD_X_LOC || checkYLoc<0 || checkYLoc>=MAX_WORLD_Y_LOC)
continue;
if(world.get_loc(checkXLoc, checkYLoc)->can_move(mobile_type))
{
found++;
break;
}
}
}
else
{
vecX /= abs(vecX);
vecY /= abs(vecY);
checkXLoc = curXLoc + vecX;
checkYLoc = curYLoc + vecY;
if(world.get_loc(checkXLoc, checkYLoc)->can_move(mobile_type))
found++;
}
if(!found)
return;
set_dir(curXLoc, curYLoc, checkXLoc, checkYLoc);
cur_action = SPRITE_SHIP_EXTRA_MOVE;
go_x = checkXLoc*ZOOM_LOC_WIDTH;
go_y = checkYLoc*ZOOM_LOC_HEIGHT;
err_when(cur_x==go_x && cur_y==go_y);
//extra_move_in_beach = EXTRA_MOVING_IN;
}
//----------- End of function UnitMarine::extra_move -----------//
//------- Begin of function UnitMarine::process_extra_move ------//
void UnitMarine::process_extra_move()
{
static short vector_x_array[] = { 0, 1, 1, 1, 0, -1, -1, -1}; // default vectors, temporary only
static short vector_y_array[] = {-1, -1, 0, 1, 1, 1, 0, -1};
if(!match_dir()) // process turning
return;
if(cur_x!=go_x || cur_y!=go_y)
{
//------------------------------------------------------------------------//
// set cargo_recno, extra_move_in_beach
//------------------------------------------------------------------------//
if(cur_x==next_x && cur_y==next_y)
{
int goXLoc = go_x>>ZOOM_X_SHIFT_COUNT;
int goYLoc = go_y>>ZOOM_Y_SHIFT_COUNT;
if(!world.get_loc(goXLoc, goYLoc)->can_move(mobile_type))
{
go_x = next_x;
go_y = next_y;
return;
}
int curXLoc = next_x_loc();
int curYLoc = next_y_loc();
world.set_unit_recno(curXLoc, curYLoc, mobile_type, 0);
world.set_unit_recno(goXLoc, goYLoc, mobile_type, sprite_recno);
next_x = go_x;
next_y = go_y;
err_when( ((curXLoc%2)|(curYLoc%2)) + ((goXLoc%2)|(goYLoc%2)) != 1); // one pair location must be even, another is not even
in_beach = !(curXLoc%2 || curYLoc%2);
if(goXLoc%2 || goYLoc%2) // not even location
extra_move_in_beach = EXTRA_MOVING_IN;
else // even location
extra_move_in_beach = EXTRA_MOVING_OUT;
}
//else
// int debug = 0;
//---------- process moving -----------//
short stepX = sprite_info->speed;
short stepY = sprite_info->speed;
short vectorX = vector_x_array[final_dir] * sprite_info->speed; // cur_dir may be changed in the above set_next() call
short vectorY = vector_y_array[final_dir] * sprite_info->speed;
if(abs(cur_x-go_x) <= stepX)
cur_x = go_x;
else
cur_x += vectorX;
if(abs(cur_y-go_y) <= stepY)
cur_y = go_y;
else
cur_y += vectorY;
err_when(extra_move_in_beach!=EXTRA_MOVING_IN && extra_move_in_beach!=EXTRA_MOVING_OUT);
err_when(cur_action!=SPRITE_SHIP_EXTRA_MOVE);
}
if(cur_x==go_x && cur_y==go_y)
{
if(result_node_array==NULL)
{
cur_action = SPRITE_IDLE;
cur_frame = 1;
move_to_x_loc = next_x_loc();
move_to_y_loc = next_y_loc();
}
else
{
cur_action = SPRITE_MOVE;
next_move();
}
if(in_beach)
{
extra_move_in_beach = EXTRA_MOVE_FINISH;
err_when(move_to_x_loc%2==0 && move_to_y_loc%2==0);
err_when(result_node_array || result_path_dist);
}
else
{
extra_move_in_beach = NO_EXTRA_MOVE;
err_when(move_to_x_loc%2 || move_to_y_loc%2);
err_when(result_node_array || result_path_dist);
}
err_when(cur_action==SPRITE_IDLE && (extra_move_in_beach==EXTRA_MOVING_IN || extra_move_in_beach==EXTRA_MOVING_OUT));
}
}
//----------- End of function UnitMarine::process_extra_move -----------//
//------------ Begin of function UnitMarine::actual_damage --------------//
//
// This function returns the actual hit damage this unit can do to a target.
//
float UnitMarine::actual_damage()
{
float attackDamage = Unit::actual_damage();
//-----------------------------------------//
//
// If there is units on the ship, the units
// leadership will increase the attacking damage.
//
// actual damage = normal damage X (100+highest leadership unit on the ship) / 100
//
//-----------------------------------------//
Unit* unitPtr;
int t, highestLeadership=0;
for( int i=0 ; i<unit_count ; i++ )
{
unitPtr = unit_array[ unit_recno_array[i] ];
if( unitPtr->skill.skill_id == SKILL_LEADING )
{
if( (t=unitPtr->skill.skill_level) > highestLeadership )
highestLeadership = t;
}
}
return attackDamage * (100+highestLeadership) / 100;
}
//------------ End of function UnitMarine::actual_damage --------------//
//------- Begin of function UnitMarine::total_carried_goods -------//
int UnitMarine::total_carried_goods()
{
int totalQty=0;
for( int i=0 ; i<MAX_RAW ; i++ )
{
totalQty += raw_qty_array[i];
totalQty += product_raw_qty_array[i];
}
return totalQty;
}
//------- End of function UnitMarine::total_carried_goods -------//
//------- Begin of function UnitMarine::can_resign -------//
int UnitMarine::can_resign()
{
err_when(unit_count < 0);
return unit_count == 0;
}
//------- End of function UnitMarine::can_resign -------//
//--------- Begin of function UnitMarine::copy_route ---------//
//
// Copies trade route from copyUnitRecno to this ship.
//
void UnitMarine::copy_route(short copyUnitRecno, int remoteAction)
{
if( sprite_recno == copyUnitRecno )
return;
UnitMarine* copyUnit = (UnitMarine*)unit_array[copyUnitRecno];
if( copyUnit->nation_recno != nation_recno )
return;
if( remote.is_enable() && !remoteAction )
{
// packet structure : <unit recno> <copy recno>
short *shortPtr = (short *)remote.new_send_queue_msg(MSG_U_SHIP_COPY_ROUTE, 2*sizeof(short));
*shortPtr = sprite_recno;
shortPtr[1] = copyUnitRecno;
return;
}
// clear existing stops
int num_stops = stop_defined_num;
for( int i=0; i<num_stops; i++ )
del_stop(1, COMMAND_AUTO); // stop ids shift up
ShipStop* shipStopA = copyUnit->stop_array;
ShipStop* shipStopB = stop_array;
for( int i=0; i<MAX_STOP_FOR_CARAVAN; i++, shipStopA++, shipStopB++ )
{
if( !shipStopA->firm_recno )
break;
if( firm_array.is_deleted(shipStopA->firm_recno) )
continue;
Firm* firmPtr = firm_array[shipStopA->firm_recno];
set_stop(i+1, shipStopA->firm_loc_x1, shipStopA->firm_loc_y1, COMMAND_AUTO);
if( shipStopA->pick_up_type == AUTO_PICK_UP )
{
set_stop_pick_up(i+1, AUTO_PICK_UP, COMMAND_AUTO );
}
else if( shipStopA->pick_up_type == NO_PICK_UP )
{
set_stop_pick_up(i+1, NO_PICK_UP, COMMAND_AUTO );
}
else
{
for( int b=0; b<MAX_PICK_UP_GOODS; ++b )
{
if( shipStopA->pick_up_array[b] != shipStopB->pick_up_array[b] )
set_stop_pick_up(i+1, b+1, COMMAND_PLAYER);
}
}
}
}
//---------- End of function UnitMarine::copy_route ----------//
|