yard.cgi

造船所関連

 

# Sub Shipyard #
sub shipyard {
    if ($F{'yard'} == 1) { &yard_buy; return }
    if ($F{'yard'} == 2) { &yard_sell; return }
    if ($F{'yard'} == 3) { &yard_rep; return }
print <<YARD;
造船所<br><form method=$method action=$seacgi>
<input type=hidden name=id value="$F{'id'}">
<input type=hidden name=ps value="$F{'ps'}">
<input type=hidden name=mode value="play">
<input type=hidden name=yard value="1">
<input type=submit value="購入" class=button>
</form><form method=$method action=$seacgi>
<input type=hidden name=id value="$F{'id'}">
<input type=hidden name=ps value="$F{'ps'}">
<input type=hidden name=mode value="play">
<input type=hidden name=yard value="2">
<input type=submit value="売却" class=button>
</form><form method=$method action=$seacgi>
<input type=hidden name=id value="$F{'id'}">
<input type=hidden name=ps value="$F{'ps'}">
<input type=hidden name=mode value="play">
<input type=hidden name=yard value="3">
<input type=submit value="修理" class=button></form>
YARD
}

valueが1なら購入へ。valueが2なら売却へ。valueが3なら修理へ。
船の改造を追加したいなら改造のsubを作りココにvalueが4なら改造へという様にすればOKです。


# Sub Buy Yard #
sub yard_buy {
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
造船所のファイルを読み込み、@yardlineに格納。
    &form_table('up','100%',1);
    &reload;
    print qq|造船所:購入  |;
    &submit_button;
    print qq|</td></tr><tr><td align=left>\n|;
    foreach (0 .. $#yardline) {
@yardlineの最初から最後までforeachで処理。
        ($goods,$kind,$goods_img,$sale_area,$sale_port,$volume,$ship_hp,$knot,$price)
        = split(/<>/,$yardline[$_]);
$yardline[N番目]の値を<>ごとに分割し各変数に格納。
$goods「名前」,$kind「種類」,$goods_img「画像名」,$sale_area「販売エリア」,$sale_port「販売港」,$volume「積載」,$ship_hp「HP」,$knot「速度」,$price「価格」

            if ($sale_area =~ /$area/ || $sale_port =~ /$port/) {
            $checked = !$first ? ' checked' : '';
            $first = 1;
            &price_up;
能力の価格の処理
            print qq|<input type=radio name=goods value="$_"$checked>|;
            print qq|<img src="$img/$goods_img" height=15>$goods:$price G<br>|;
            if ($kind == 1) {
                print qq|[積載:$volume 耐久:$ship_hp 速度:$knot]<br>\n|;
            }
            elsif ($kind == 2) {
                print qq|戦闘力+$volume<br>\n|;
            }
            elsif ($kind == 3) {
                print qq|指揮力+$volume<br>\n|;
            }
            elsif ($kind == 4) {
                print qq|航海力+$volume<br>\n|;
            }
        }
    }
    print qq|<input type=hidden name=yard value="1"><input type=hidden name=mode value="buy_ship">\n|;
    &id_ps;
    &form_table('down');
}




# Sub Price Up #
sub price_up {
    if ($kind == 2 || $kind == 3 || $kind ==4) {
        my $rate = $atk + $cmd + $nav;
        $price = int($price * exp($rate * 0.03 - 3))
    }
}
能力の価格処理。価格 * ((攻撃力+指揮力+航海力)*0.03-3)のべき乗

# Sub Buy Ship #
sub buy_ship {
    &get_me($F{'id'});
    if ($action ne $F{'reload'}) { &play; exit }
    &get_port($area,$port);
    &ship_data;
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
    ($goods,$kind,$goods_img,$sale_area,$sale_port,$volume,$ship_hp,$knot,$price)
     = split(/<>/, $yardline[$F{'goods'}] );
    if ( $sale_area !~ /$area/ && $sale_port !~ /$port/ ) { &play("不正です"); exit }
    &price_up;
    if ( $money < $price ) { &play("資金が足りません"); exit }
    if ( $#ship_ind == 16 && $kind == 1 ) { &play("これ以上船は買えません"); exit}
    if ( $kind == 1 && $#ship_ind < 16 ) {
        push(@ship_ind , "$goods_img,$volume,$ship_hp,$knot,$goods");
        &msg("$goodsを買いました");
        &add_record("$goodsを $priceで 購入")
    }
    elsif ( $kind == 2 ) {
        if ($atk >= $atk_limit) { &play("これ以上は無理です"); exit }
        $atk += $volume;
        &msg("武装しました");
        &add_record("戦闘力 + $volume")
    }
    elsif ( $kind == 3 ) {
        if ($cmd >= $cmd_limit) { &play("これ以上は無理です"); exit }
        $cmd += $volume;
        &msg("指揮力が高まりました");
        &add_record("指揮力 + $volume")
    }
    elsif ( $kind == 4 ) {
        if ($nav >= $nav_limit) { &play("これ以上は無理です"); exit }
        $nav += $volume;
        &msg("航海力が高まりました");
        &add_record("航海力 + $volume")
    }
    $action = '';
    $money -= $price;
    &play;
}
購入処理

# Sub Yard Sell #
sub yard_sell {
    if ( $#ship_ind < 0) { print qq|船がありません|; &return_button; return }
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
    &form_table('up','100%',1);
    &reload;
    print qq|造船所:売却  |;
    &submit_button;
    print qq|</td></tr><tr><td align=left>\n|;
    for ($i = 0; $i <= $#ship_ind; $i++) {
        ($price) = map{ (split(/<>/))[8] } grep {$ship[$i][4] eq (split(/<>/,$_))[0]} @yardline;
@yardlineのN番目の9番目の値「価格」を分割抽出し、プレーヤーのN番目の船の名前と一致した船の名前の価格を$priceに格納。

        $price = int($price / 2);
        $checked = $i == 0 ? ' checked' : '';
        print qq|<input type=radio name=goods value="$i"$checked>|;
        print qq|$ship[$i][4]:$price G<br>\n|;
        print qq|[積載:$ship[$i][1] 耐久:$ship[$i][2] 速度:$ship[$i][3]]<br>|;
    }
    print qq|<input type=hidden name=yard value="2"><input type=hidden name=mode value="sell_ship">\n|;
    &id_ps;
    &form_table('down');
}

# Sub Sell Ship #
sub sell_ship {
    &get_me($F{'id'});
    if ($action ne $F{'reload'}) { &play; exit }
    &ship_data;
    &fleet;
    &load_data;
    if ( ($total - $total_load - $food - $sailor - $ship[$F{'goods'}][1]) < 0 ) {
        &play("残積荷が足りません");
        return
    }
    $action = '';
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
    ($price) = map{ (split(/<>/))[8] } grep {$ship[$F{'goods'}][4] eq (split(/<>/,$_))[0]} @yardline;
    splice(@ship_ind , $F{'goods'} ,1);
    my $upmoney = int($price / 2);
    $money += $upmoney;
    &msg("$ship[$F{'goods'}][4]を売却しました");
    &add_record("$ship[$F{'goods'}][4]を $upmoneyで 売却");
    &play;
}
売却処理

# Sub Yard Repair #
sub yard_rep {
    if ( $#ship_ind < 0) { print qq|船がありません|; &return_button; return }
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
    &form_table('up','100%',1);
    &reload;
    print qq|造船所:修理  |;
    &submit_button;
    print qq|</td></tr><tr><td align=left>\n|;
    for ($i = 0; $i <= $#ship_ind; $i++) {
        ($max_hp,$price) = map{ (split(/<>/))[6,8] } grep {$ship[$i][4] eq (split(/<>/,$_))[0]} @yardline;
        if (!$max_hp) { $max_hp = $ship[$F{'goods'}][1] * 0.2; $price = $ship[$F{'goods'}][1] * 10000; }
$max_hpが偽ならば、$max_hpは積載*0.2、価格は積載*10000。
        if ($max_hp <= $ship[$i][2]) { next }
        $price = $max_hp ? int($price * 0.03 / ($ship[$i][2] / $max_hp)) : 0;
A ? B : C は、Aが真であればBを、偽であればCを値とする。
つまり、$priceに $max_hpが真であれば、($price*0.03/(船のHP/$max_hp))を格納し、偽ならば0を格納する。
        if ($ship[$i][1] > 500) { $down = $ship[$i][1] - 20 }
        elsif ($ship[$i][1] > 100) { $down = $ship[$i][1] - 10 }
        else { $down = $ship[$i][1] }
修理後の積載減少の処理

        $checked = !$f ? ' checked' : '';
        $f = 1;
        print qq|<input type=radio name=goods value="$i"$checked>|;
        print qq|$ship[$i][4]:$price G<br>\n|;
        print qq|[積載:$ship[$i][1] 耐久:$ship[$i][2] 速度:$ship[$i][3]]<br>|;
        print qq|修理後 [積載:$down 耐久:$max_hp]<br>|;
    }
    print qq|修理できる船はありません<input type=hidden name=mode value="play">\n| if !$f;
    print qq|<input type=hidden name=yard value="3"><input type=hidden name=mode value="rep_ship">\n| if $f;
    &id_ps;
    &form_table('down');
}

# Sub Repair Ship #
sub rep_ship {
    &get_me($F{'id'});
    if ($action ne $F{'reload'}) { &play; exit }
    &ship_data;
    &fleet;
    &load_data;
    my $YardFile = new Nfile("$datadir/$yarddat",'read');
    my @yardline = $YardFile->read;
    ($max_hp,$price) = map{ (split(/<>/))[6,8] } grep {$ship[$F{'goods'}][4] eq (split(/<>/,$_))[0]} @yardline;
    if (!$max_hp) { $max_hp = $ship[$F{'goods'}][1] * 0.2; $price = $ship[$F{'goods'}][1] * 10000; }
    $price = $max_hp ? int($price * 0.03 / ($ship[$F{'goods'}][2] / $max_hp)) : 0;
    if ( $money < $price ) { &play("資金が足りません"); exit }
    if ($ship[$F{'goods'}][1] > 500) { $down = 20 }
    elsif ($ship[$F{'goods'}][1] > 100) { $down = 10 }
    if ( ($total - $total_load - $food - $sailor - $down) < 0 ) {
        &play("残積荷が足りません");
        return
    }
    $action = '';
    $ship[$F{'goods'}][1] = $ship[$F{'goods'}][1] - $down;
    splice(@ship_ind , $F{'goods'} ,1 ,"$ship[$F{'goods'}][0],$ship[$F{'goods'}][1],$max_hp,$ship[$F{'goods'}][3],$ship[$F{'goods'}][4]");
    $money -= $price;
    &msg("$ship[$F{'goods'}][4]を修理しました");
    &add_record("$ship[$F{'goods'}][4]を $priceで 修理");
    &play;
}
修理処理

1;

最終更新:2010年09月20日 23:30
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。