123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- #include <OB_HOMIN.h>
- #include <OWORLD.h>
- enum
- {
- BULLET_TARGET_NONE =0,
- BULLET_TARGET_UNIT =1,
- BULLET_TARGET_TOWN,
- BULLET_TARGET_FIRM,
- BULLET_TARGET_WALL,
- };
- BulletHoming::BulletHoming() : Bullet()
- {
- target_type = BULLET_TARGET_NONE;
- target_recno = 0;
- }
- BulletHoming::~BulletHoming()
- {
- deinit();
- }
- void BulletHoming::init(char parentType, short parentRecno, short targetXLoc, short targetYLoc, char targetMobileType)
- {
- Bullet::init(parentType, parentRecno, targetXLoc, targetYLoc, targetMobileType);
-
-
-
- err_when(parent_type!=BULLET_BY_UNIT);
- Unit *parentUnit = unit_array[parentRecno];
-
- AttackInfo* attackInfo = parentUnit->attack_info_array+parentUnit->cur_attack;
- speed = attackInfo->bullet_speed;
- max_step = char((attackInfo->attack_range * ZOOM_LOC_WIDTH + speed-1)/ speed);
-
- SpriteFrame *spriteFrame = cur_sprite_frame();
-
- origin_x += spriteFrame->offset_x + spriteFrame->width/2;
- origin_y += spriteFrame->offset_y + spriteFrame->height/2;
- origin2_x = origin_x;
- origin2_y = origin_y;
- go_x += spriteFrame->offset_x + spriteFrame->width/2;
- go_y += spriteFrame->offset_y + spriteFrame->height/2;
-
- Location *locPtr = world.get_loc(targetXLoc, targetYLoc);
-
-
- if(locPtr->has_unit(targetMobileType))
- {
- target_type = BULLET_TARGET_UNIT;
-
- target_recno = locPtr->unit_recno(targetMobileType);
- }
-
- else if( locPtr->is_town() )
- {
- target_type = BULLET_TARGET_TOWN;
- target_recno = locPtr->town_recno();
- }
- else if( locPtr->is_firm() )
- {
- target_type = BULLET_TARGET_FIRM;
- target_recno = locPtr->firm_recno();
- }
- else if( locPtr->is_wall() )
- {
- target_type = BULLET_TARGET_WALL;
- }
- }
- void BulletHoming::deinit()
- {
- }
- void BulletHoming::process_move()
- {
- int actualStep = total_step;
- if(target_type == BULLET_TARGET_UNIT)
- {
- Unit *unitPtr;
- if( unit_array.is_deleted(target_recno) ||
- !(unitPtr = unit_array[target_recno]) ||
- !unitPtr->is_visible() )
- {
-
- target_type = BULLET_TARGET_NONE;
- }
- else
- {
-
- target_x_loc = unitPtr->next_x_loc();
- target_y_loc = unitPtr->next_y_loc();
-
-
-
- go_x = unitPtr->cur_x + ZOOM_LOC_WIDTH / 2;
- go_y = unitPtr->cur_y + ZOOM_LOC_HEIGHT /2;
-
- SpriteFrame *spriteFrame = cur_sprite_frame();
- int adjX = spriteFrame->offset_x+spriteFrame->width/2;
- int adjY = spriteFrame->offset_y+spriteFrame->height/2;
- int xStep = abs(go_x - (cur_x+adjX))/speed;
- int yStep = abs(go_y - (cur_y+adjY))/speed;
- total_step = cur_step + max(xStep, yStep);
-
-
-
-
-
-
- actualStep = total_step;
- if( total_step > max_step )
- {
- total_step = max_step;
-
- target_x_loc = (cur_x + adjX) + (int)(go_x-(cur_x+adjX)) / (actualStep - total_step) / ZOOM_LOC_WIDTH;
- target_x_loc = (cur_y + adjY) + (int)(go_y-(cur_y+adjY)) / (actualStep - total_step) / ZOOM_LOC_HEIGHT;
- }
- }
- }
-
- SpriteFrame *spriteFrame = cur_sprite_frame();
- short adjX = spriteFrame->offset_x + spriteFrame->width/2;
- short adjY = spriteFrame->offset_y + spriteFrame->height/2;
- origin_x = cur_x + adjX;
- origin_y = cur_y + adjY;
- cur_x = origin_x + (int)(go_x-origin_x) / (actualStep + 1 - cur_step);
- cur_y = origin_y + (int)(go_y-origin_y) / (actualStep + 1 - cur_step);
-
-
- if( cur_step > 3 )
- set_dir(origin2_x, origin2_y, cur_x, cur_y);
-
- spriteFrame= cur_sprite_frame();
- adjX = spriteFrame->offset_x + spriteFrame->width/2;
- adjY = spriteFrame->offset_y + spriteFrame->height/2;
- cur_x -= adjX;
- cur_y -= adjY;
- cur_step++;
-
- if( ++cur_frame > cur_sprite_move()->frame_count )
- cur_frame = 1;
-
- if( cur_step > total_step )
- {
- check_hit();
- cur_action = SPRITE_DIE;
-
-
- if( sprite_info->die.first_frame_recno )
- {
- next_x = cur_x = target_x_loc * ZOOM_LOC_WIDTH;
- next_y = cur_y = target_y_loc * ZOOM_LOC_HEIGHT;
- }
-
- cur_frame = 1;
- }
-
- else if( total_step - cur_step <= 1 )
- {
- warn_target();
- }
- }
|