// File: /workspace/github_cpp_makefile_star2_O2/Worthy-Wang[P]Warcraft3-StartWar/warcraftWorld.cpp
// Function: warcraft::WarcraftWorld::createAndShow(warcraft::Headquarters*)
bool WarcraftWorld::createAndShow(Headquarters *head)
{
    //基地生命元少于当前创造的勇士生命值时 返回false
    while (head->getBaseHp() < GameConfig::getInstance()->getInitWarriorHp(_caseNum, head->getWarriorType()))
        return false;
    //创建勇士
    WarriorPtr warrior = head->createWarrior(head->getWarriorType());
    WarriorViewPtr warriorView;

    //设置武器
    switch (head->getWarriorType())
    {
    case DRAGON:
    {
        WeaponPtr weapon = head->createWeapon(head->getWarriorId() % 3, DRAGON);
        warrior->setWeapon(weapon);
        warriorView.reset(new DragonView(warrior));
        HeadquartersView headView(head);
        //show
        warriorView->show();
        cout << "It has a " << weapon->getName() << endl;
        break;
    }
    case ICEMAN:
    {
        WeaponPtr weapon = head->createWeapon(head->getWarriorId() % 3, ICEMAN);
        warrior->setWeapon(weapon);
        warriorView.reset(new IcemanView(warrior));
        HeadquartersView headView(head);
        //show
        warriorView->show();
        cout << "It has a " << weapon->getName() << endl;
        break;
    }
    case LION:
    {
        WeaponPtr weapon = head->createWeapon(head->getWarriorId() % 3, LION);
        warrior->setWeapon(weapon);
        warriorView.reset(new LionView(warrior));
        HeadquartersView headView(head);
        //show
        warriorView->show();
        break;
    }
    case NINJA:
    {
        WeaponPtr weapon1 = head->createWeapon(head->getWarriorId() % 3, NINJA);
        WeaponPtr weapon2 = head->createWeapon((head->getWarriorId() + 1) % 3, NINJA);
        warrior->setWeapon(weapon1);
        warrior->setWeapon(weapon2);
        warriorView.reset(new NinjaView(warrior));
        HeadquartersView headView(head);
        //show
        warriorView->show();
        cout << "It has a " << weapon1->getName() << " and a " << weapon2->getName() << endl;
        break;
    }
    case WOLF:
    {
        warriorView.reset(new WolfView(warrior));
        HeadquartersView headView(head);
        //show
        warriorView->show();
        break;
    }
    }
    if (head->getColor() == RED)
        _citys[0]->attach(warrior);
    else
        _citys[GameConfig::getInstance()->getCityNum(_caseNum) + 1]->attach(warrior);
    head->nextWarriorType();
    head->nextWarriorId();
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %rbx
movq %rdi, %r15
movq 0x8(%rsi), %r13
movq 0x10(%rsi), %rax
leaq 0xa3f7(%rip), %rcx      # 0x16168
movq (%rcx), %rdi
movq 0x28(%r15), %rsi
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,4), %edx
callq 0x7306
movq %rax, %r14
cmpq %rax, %r13
jb 0xc2e8
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,4), %edx
leaq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x6ab4
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq 0x10(%rbx), %rax
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,4), %eax
cmpq $0x4, %rax
ja 0xc245
leaq 0x2b52(%rip), %rcx      # 0xe91c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
pushq $0x3
popq %r12
movq %r13, -0x58(%rbp)
jmpq *%rax
movq 0x18(%rbx), %rax
xorl %edx, %edx
divq %r12
leaq -0xa0(%rbp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x70f8
movq -0x38(%rbp), %r12
leaq -0x180(%rbp), %r13
leaq -0xa0(%rbp), %rsi
movq %r13, %rdi
callq 0x52c4
addq $0x40, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x81d4
leaq -0x178(%rbp), %rdi
callq 0x5302
pushq $0x18
popq %rdi
callq 0x4170
movq %rax, %r12
leaq -0x170(%rbp), %r13
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x5392
movb $0x1, %al
movl %eax, -0x5c(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x7444
movl $0x0, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x73fe
leaq -0x168(%rbp), %rdi
callq 0x5302
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x58(%rbp), %r13
movq 0xa144(%rip), %rdi      # 0x15fd0
leaq 0x2bc0(%rip), %rsi      # 0xea53
callq 0x4160
movq %rax, %r12
movq -0xa0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x80(%rbp), %rdi
callq 0x41d0
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x4150
movq %rax, %rdi
callq 0x40b0
jmp 0xbff9
pushq $0x18
popq %rdi
callq 0x4170
movq %rax, %r12
leaq -0xf0(%rbp), %r13
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x5392
movq %r12, %rdi
movq %r13, %rsi
callq 0x7990
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x794a
leaq -0xe8(%rbp), %rdi
callq 0x5302
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x58(%rbp), %r13
jmp 0xc245
movq 0x18(%rbx), %rax
xorl %edx, %edx
divq %r12
leaq -0xa0(%rbp), %rdi
pushq $0x2
popq %rcx
movq %rbx, %rsi
callq 0x70f8
movq -0x38(%rbp), %r12
leaq -0x160(%rbp), %r13
leaq -0xa0(%rbp), %rsi
movq %r13, %rdi
callq 0x52c4
addq $0x40, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x81d4
leaq -0x158(%rbp), %rdi
callq 0x5302
pushq $0x18
popq %rdi
callq 0x4170
movq %rax, %r12
leaq -0x150(%rbp), %r13
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x5392
movq %r12, %rdi
movq %r13, %rsi
callq 0x76e4
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x769e
leaq -0x148(%rbp), %rdi
callq 0x5302
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x58(%rbp), %r13
movq 0xa00e(%rip), %rdi      # 0x15fd0
leaq 0x2a8a(%rip), %rsi      # 0xea53
callq 0x4160
movq %rax, %r12
movq -0xa0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x80(%rbp), %rdi
callq 0x41d0
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x4150
movq %rax, %rdi
callq 0x40b0
leaq -0x80(%rbp), %rdi
callq 0x40a0
leaq -0x98(%rbp), %rdi
jmp 0xc240
movq 0x18(%rbx), %rax
xorl %edx, %edx
divq %r12
leaq -0x80(%rbp), %rdi
pushq $0x3
popq %rcx
movq %rbx, %rsi
callq 0x70f8
movq -0x38(%rbp), %r12
leaq -0x140(%rbp), %r13
leaq -0x80(%rbp), %rsi
movq %r13, %rdi
callq 0x52c4
addq $0x40, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x81d4
leaq -0x138(%rbp), %rdi
callq 0x5302
pushq $0x18
popq %rdi
callq 0x4170
movq %rax, %r12
leaq -0x130(%rbp), %r13
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x5392
movq %r12, %rdi
movq %r13, %rsi
callq 0x7840
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x77fa
leaq -0x128(%rbp), %rdi
callq 0x5302
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x58(%rbp), %r13
leaq -0x78(%rbp), %rdi
jmp 0xc240
movq 0x18(%rbx), %rax
xorl %edx, %edx
divq %r12
leaq -0xc0(%rbp), %rdi
pushq $0x1
popq %rcx
movq %rbx, %rsi
callq 0x70f8
movq 0x18(%rbx), %rax
incq %rax
xorl %edx, %edx
divq %r12
leaq -0xb0(%rbp), %rdi
pushq $0x1
popq %rcx
movq %rbx, %rsi
callq 0x70f8
movq -0x38(%rbp), %r12
leaq -0x120(%rbp), %r13
leaq -0xc0(%rbp), %rsi
movq %r13, %rdi
callq 0x52c4
addq $0x40, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x81d4
leaq -0x118(%rbp), %rdi
callq 0x5302
movq -0x38(%rbp), %r12
leaq -0x110(%rbp), %r13
leaq -0xb0(%rbp), %rsi
movq %r13, %rdi
callq 0x52c4
addq $0x40, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x81d4
leaq -0x108(%rbp), %rdi
callq 0x5302
pushq $0x18
popq %rdi
callq 0x4170
movq %rax, %r12
leaq -0x100(%rbp), %r13
leaq -0x38(%rbp), %rsi
movq %r13, %rdi
callq 0x5392
movq %r12, %rdi
movq %r13, %rsi
callq 0x7594
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x754e
leaq -0xf8(%rbp), %rdi
callq 0x5302
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x58(%rbp), %r13
movq 0x9e27(%rip), %rdi      # 0x15fd0
leaq 0x28a3(%rip), %rsi      # 0xea53
callq 0x4160
movq %rax, %r12
movq -0xc0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x80(%rbp), %rdi
callq 0x41d0
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x4150
leaq 0x287e(%rip), %rsi      # 0xea5d
movq %rax, %rdi
callq 0x4160
movq %rax, %r12
movq -0xb0(%rbp), %rsi
addq $0x10, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x41d0
leaq -0xa0(%rbp), %rsi
movq %r12, %rdi
callq 0x4150
movq %rax, %rdi
callq 0x40b0
leaq -0xa0(%rbp), %rdi
callq 0x40a0
leaq -0x80(%rbp), %rdi
callq 0x40a0
leaq -0xa8(%rbp), %rdi
callq 0x5302
leaq -0xb8(%rbp), %rdi
callq 0x5302
cmpl $0x0, (%rbx)
je 0xc299
leaq 0x9f17(%rip), %rax      # 0x16168
movq (%rax), %rax
movq 0x10(%r15), %rcx
movq 0x28(%r15), %rdx
movq 0x18(%rax), %rax
shlq $0x7, %rdx
movq -0x78(%rax,%rdx), %rax
shlq $0x4, %rax
movq 0x10(%rcx,%rax), %r15
leaq -0xd0(%rbp), %r12
leaq -0x38(%rbp), %rsi
movq %r12, %rdi
callq 0x5392
movq %r15, %rdi
movq %r12, %rsi
callq 0xb60a
leaq -0xc8(%rbp), %rdi
jmp 0xc2c5
movq 0x10(%r15), %rax
movq (%rax), %r15
leaq -0xe0(%rbp), %r12
leaq -0x38(%rbp), %rsi
movq %r12, %rdi
callq 0x5392
movq %r15, %rdi
movq %r12, %rsi
callq 0xb60a
leaq -0xd8(%rbp), %rdi
callq 0x5302
movq %rbx, %rdi
callq 0xd21c
incq 0x18(%rbx)
leaq -0x48(%rbp), %rdi
callq 0x5302
leaq -0x30(%rbp), %rdi
callq 0x5302
cmpq %r14, %r13
setae %al
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc3d7
jmp 0xc3f5
jmp 0xc40f
jmp 0xc40f
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
jmp 0xc355
jmp 0xc3f5
jmp 0xc35f
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
jmp 0xc355
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
jmp 0xc382
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
jmp 0xc3a6
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x5302
jmp 0xc3f8
movq %rax, %rbx
jmp 0xc387
jmp 0xc40f
jmp 0xc40f
jmp 0xc3c1
movq %rax, %rbx
jmp 0xc404
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x5302
leaq -0x78(%rbp), %rdi
jmp 0xc419
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
jmp 0xc3a6
movq %rax, %rbx
leaq -0x158(%rbp), %rdi
callq 0x5302
jmp 0xc412
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
jmp 0xc419
jmp 0xc3c1
jmp 0xc3c1
jmp 0xc3c1
jmp 0xc3c1
movq %rax, %rbx
jmp 0xc41e
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x40a0
jmp 0xc3da
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x40a0
jmp 0xc3f8
jmp 0xc3e7
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x40a0
jmp 0xc412
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x5302
leaq -0xb8(%rbp), %rdi
jmp 0xc419
jmp 0xc40f
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x5302
leaq -0x48(%rbp), %rdi
callq 0x5302
leaq -0x30(%rbp), %rdi
callq 0x5302
movq %rbx, %rdi
callq 0x4250
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x5302
cmpb $0x0, -0x5c(%rbp)
je 0xc412
pushq $0x18
popq %rsi
movq %r12, %rdi
callq 0x4180
jmp 0xc412
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
jmp 0xc419
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0xc419