« W:ETソースコード朗読会 第四回 | メイン | W:ETソースコード朗読会 補足1 »
April 15, 2005
■ W:ETソースコード朗読会 第五回
Reading the Source Code of W:ET #5
今回の目標
武器個別の攻撃判定を前回前々回と見ました。今回はそんな武器によって傷ついた体を癒してくれるヘルスパックについてみていきましょう。ちなみにソースコード的にはこのヘルスパックも扱い分類としては「武器」です。つまり、マシンガン構えているのもヘルスパック抱えているのも敵対行為とみなされます。みなさん、戦場で救護班になっても敵はあなたを狙ってきます。注意しましょう。
ヘルスパックを出す
g_weapon.cの184行以降を見てください。メディックがヘルスパックを出す処理についてのコードが書かれています。早速コードを見ましょう。
void Weapon_Medic( gentity_t *ent ) { gitem_t *item; gentity_t *ent2; vec3_t velocity, offset; vec3_t angles,mins,maxs; vec3_t tosspos, viewpos; trace_t tr;
ここはいつも通りの宣言と初期化部分ですね。見慣れない構造体に、gitem_tというものがあります。定義を見てみましょうか。
typedef struct gitem_s { char *classname; // spawning name char *pickup_sound; char *world_model[MAX_ITEM_MODELS]; (省略) int giClipIndex; // which clip this weapon uses. this allows the sniper rifle to use the same clip as the garand, etc. char *precaches; // string of all models and images this item will use char *sounds; // string of all sounds this item will use } gitem_t;
どうやらアイテムに関するプロパティを含む構造体のようですね。具体的にはクラス名、表示モデルデータ、拾った時の音などでしょうか。
本文の続きを見ていきましょう。
if (level.time - ent->client->ps.classWeaponTime > level.medicChargeTime[ent->client->sess.sessionTeam-1]) { ent->client->ps.classWeaponTime = level.time - level.medicChargeTime[ent->client->sess.sessionTeam-1]; } if( ent->client->sess.skill[SK_FIRST_AID] >= 2 ) { ent->client->ps.classWeaponTime += level.medicChargeTime[ent->client->sess.sessionTeam-1]*0.15; } else { ent->client->ps.classWeaponTime += level.medicChargeTime[ent->client->sess.sessionTeam-1]*0.25; }
二つのif構文があります。最初の条件節は、クラスごとのチャージが満タン以上になっていた場合、チャージをちょうど満タンに設定しなおしています。次の条件節では、プレイヤーのメディックスキルが2以上の場合にチャージ消費量を15%、そうでなければ25%に設定しています。
item = BG_FindItemForClassName("item_health"); VectorCopy( ent->client->ps.viewangles, angles ); if ( angles[PITCH] < -30 ) { angles[PITCH] = -30; } else if ( angles[PITCH] > 30 ) { angles[PITCH] = 30; }
最初の行で、itemにはitem_healthをクラスネームとするアイテムのデータが代入されました。次の行にてanglesにプレイヤーの姿勢角がコピーされています。
後のifブロックでは、プレイヤー視野角のピッチ、つまり上下方向の角度をみています。これが±30度以上の場合、30度もしくは-30度に設定しなおします。
AngleVectors( angles, velocity, NULL, NULL ); VectorScale( velocity, 64, offset); offset[2] += ent->client->ps.viewheight/2; VectorScale( velocity, 75, velocity ); velocity[2] += 50 + crandom() * 25;
ここでは、実際にヘルスパックを「発射」する速度や向きを設定しています。anglesの方向に大きさ64のベクトルがoffsetに代入され、高さ方向にプレイヤーの視点の高さの半分が加算されます。そしてヘルスパックの発射速度はanglesの方向に75の速さと上方向に50〜75がプラスされたものになります。つまり、見ている方向にまっすぐ出るのではなく、少し浮き気味に発射されます。私たちが実際ゲーム中で見るのと同じ状態ですね。
VectorCopy( muzzleEffect, tosspos ); VectorMA( tosspos, 48, forward, tosspos ); VectorCopy( ent->client->ps.origin, viewpos ); VectorSet( mins, -(ITEM_RADIUS + 8), -(ITEM_RADIUS+8), 0 ); VectorSet( maxs, (ITEM_RADIUS + 8), (ITEM_RADIUS+8), 2*(ITEM_RADIUS+8) );
ここではヘルスパックが打ち出される場所とヘルスパックの大きさを設定しています。
trap_EngineerTrace( &tr, viewpos, mins, maxs, tosspos, ent->s.number, MASK_MISSILESHOT ); if( tr.startsolid ) { VectorCopy( forward, viewpos ); VectorNormalizeFast( viewpos ); VectorMA( ent->r.currentOrigin, -24.f, viewpos, viewpos ); trap_EngineerTrace(&tr, viewpos, mins, maxs, tosspos, ent->s.number, MASK_MISSILESHOT); VectorCopy( tr.endpos, tosspos ); } else if( tr.fraction < 1 ) { // oops, bad launch spot VectorCopy( tr.endpos, tosspos ); SnapVectorTowards( tosspos, viewpos ); }
こちらは射出する最終準備です。もし、ヘルスパック発生位置が壁の中の場合、プレイヤーの少し後ろに射出位置を変更しています。
ent2 = LaunchItem( item, tosspos, velocity, ent->s.number ); ent2->think = MagicSink; ent2->nextthink = level.time + 30000; ent2->parent = ent; // JPW NERVE so we can score properly later }
最後に、実際にアイテムを射出する関数を呼び出し、ent2にアイテムを登録しています。射出されてから30000ミリ秒後、つまり30秒後にMagicSink関数が呼ばれてこのアイテムは沈んで消える設定をし、この関数は全ての処理を終えます。
ヘルスパックを拾ったら
さて今度はヘルスパックを拾った場合についてみていきましょう。g_items.cの645行以降をみてください。
int Pickup_Health (gentity_t *ent, gentity_t *other) { int max; int quantity = 0; if( other->client->ps.stats[STAT_PLAYER_CLASS] != PC_MEDIC ) { if( ent->parent && ent->parent->client && other->client->sess.sessionTeam == ent->parent->client->sess.sessionTeam ) { if (!(ent->parent->client->PCSpecialPickedUpCount % MEDIC_SPECIAL_PICKUP_MOD)) { AddScore(ent->parent, WOLF_HEALTH_UP); G_LogPrintf("Health_Pack: %d %d\n", ent->parent - g_entities, other - g_entities); } G_AddSkillPoints( ent->parent, SK_FIRST_AID, 1.f ); G_DebugAddSkillPoints( ent->parent, SK_FIRST_AID, 1.f, "health pack picked up" ); ent->parent->client->PCSpecialPickedUpCount++; } }
最初の宣言と初期化のあとに多重ifがあります。最初の条件は、拾おうとしている人がメディック以外かどうか、次にパックを出したものが存在し、かつプレイヤーで、しかもパックを出した人と拾おうとしている人のチームが同じかどうかをみています。さらに次のifでパックを拾った回数が4の倍数かどうかをみており、そうならば出した人にスコアを与えその旨ログに出力します。そしてパックを出した人にメディックのXPを1与えて、アイテムを拾った回数を1増やします。
max = other->client->ps.stats[STAT_MAX_HEALTH]; if( other->client->sess.playerType == PC_MEDIC ) { max *= 1.12f; } other->health += ent->item->quantity; if (other->health > max ) { other->health = max; } other->client->ps.stats[STAT_HEALTH] = other->health; return -1; }
ここの部分で拾った人の体力を回復させています。まずはmaxへ規定の最大体力を代入しています。メディックならこれを1.12倍します。もし回復した体力が最大値を超えた場合、これを最大値へ再設定します。
最後に
今回は武器ではなく、ヘルスパックというアイテムを出す処理と拾った時の処理について見ました。ここで取り上げた以外にも、落ちているパックを拾う処理、パックを出すのにチャージが足りているかを判断する処理、拾ったパックを消す処理など色々あります。是非そういった部分もチェックしてみることをおすすめします。
投稿者 ikanatto : April 15, 2005 06:32 PM
■ コメント
Combining debt through home equity loans can be your ticket to better FICO scores. Both here Deed of Trustand there diamond and sapphire bracelet Mortgage Life Insurance [URL=http://www.racecitysynthetics.com/linkmachine/partners/directory_financial_services.html] Mortgage Life Insurance[/URL] http://www.racecitysynthetics.com/linkmachine/partners/directory_financial_services.html Initial Interest Rate FDIC Special Lien
投稿者 Mortgage Life Insurance : October 14, 2006 12:17 PM
When you consolidate with us you are eligible for their Borrower Benefits Package, which can reduce your interest rate by an additional 1.25 percent. debt management service http://oldweb.uwp.edu/academic/business/news/articles/debt-management-service.html Agency Contract Sales Price GPM
投稿者 debt management service : October 20, 2006 09:26 PM
Say, for example, you still owe $100,000 on a $150,000 loan taken out for 30 years at 6.5 percent. If you refinance the balance for another 30 years at 5.75 percent, you'd be paying $583.57 instead of $948.10 a month, a savings of $364.53. lower debt http://oldweb.uwp.edu/academic/business/news/articles/lower-debt.html Office of Thrift Supervision Federal Reserve Bank Periodic Payment Cap
投稿者 lower debt : October 25, 2006 02:05 PM
Debt and debt-consolidation strategies go together in the American economy like peanut butter and jelly. debt help http://oldweb.uwp.edu/academic/business/news/articles/debt-help.html Consumer Reporting Agency (or bureau) Equal Credit Opportunity Act (ECOA) Acknowledgment
投稿者 debt help : October 28, 2006 07:15 PM
A rally in the Treasury market has sent bond interest rates tumbling to seven- month lows, bringing mortgage rates down as well and giving the languishing housing sector a blip up. debt creditor http://oldweb.uwp.edu/academic/business/news/articles/debt-creditor.html Negative Amortization Escrow Reimbursement Junior Mortgage
投稿者 debt creditor : October 28, 2006 07:17 PM
Growing evidence that the economy is slowing is behind the decline in interest rates, which move in the opposite direction from bond prices. mortgage rate quote http://idea.zanestate.edu/wordpress/articles/mortgage-rate-quote.html california mortgage leads current mortgage interest rate mortgage loan status
投稿者 mortgage rate quote : November 7, 2006 07:24 PM
Do you end every month with barely enough cash to pay the bills, and sometimes have to tap into your savings to get by? todays mortgage rates http://theory.lcs.mit.edu/theory-seminars/2005fa/docs/Capital-Mortgage.html today mortgage rates home mortgage rate mortgage markets
投稿者 todays mortgage rates : November 15, 2006 04:20 AM
If paying your mortgage has become a hardship, it's time to look for a better deal. cash-or-nothing http://idea.zanestate.edu/bb/docs/Money-Lenders.html
投稿者 cash-or-nothing : November 30, 2006 05:55 PM
Growing evidence that the economy is slowing is behind the decline in interest rates, which move in the opposite direction from bond prices. vt morgage rates http://interactive.cens.ucla.edu/nims/docs/VT-Morgage-Rates.html
投稿者 vt morgage rates : December 11, 2006 03:55 PM
Do you end every month with barely enough cash to pay the bills, and sometimes have to tap into your savings to get by? hawaii mortage rates http://hr.nau.edu/jobs/docs/Hawaii-Mortage-Rates.html
投稿者 hawaii mortage rates : December 13, 2006 01:10 PM
Best job... [URL=http://fm7.biz/pnd]poker sites[/URL] | poker sites | http://fm7.biz/pnd
投稿者 poker sites : January 2, 2007 11:11 AM
Great hosting!! [URL=http://sex-cams.kanak.fr]sex cams[/URL] | sex cams | http://sex-cams.kanak.fr
投稿者 sex cams : January 2, 2007 11:11 AM
Top website. [URL=http://jemurl.com/a9]poker sites[/URL] | poker sites | http://jemurl.com/a9
投稿者 poker sites : January 2, 2007 11:11 AM
jenna lewis sex tape photos http://hometown.aol.com/action658523472/jenna-lewis-sex-tape-photos.htm
[url=http://hometown.aol.com/horny68842857/tranny-real-sex.htm]tranny real sex[/url]
camilla sex tranny
投稿者 4glww8vs : February 20, 2007 09:07 AM
charity poker tournament running setting up tournament http://hometown.aol.com/internet9487chip/charity-poker-tournament-running-setting-up-tournament.htm
tranny sex and xxx http://hometown.aol.com/teeny040352853/tranny-sex-and-xxx.htm
male strippers getting money from women http://hometown.aol.com/teeny84202584/male-strippers-getting-money-from-women.htm
tranny sex mature lesbian http://hometown.aol.com/horny68842857/tranny-sex-mature-lesbian.htm
tranny sex vids http://hometown.aol.com/teeny040352853/tranny-sex-vids.htm
sex with tranny story http://hometown.aol.com/horny68842857/sex-with-tranny-story.htm
jenna lewis sex tape full http://hometown.aol.com/action658523472/jenna-lewis-sex-tape-full.htm
how to make love and sex with 69 http://hometown.aol.com/teeny040352853/how-to-make-love-and-sex-with-69.htm
tranny sex video clips http://hometown.aol.com/horny68842857/tranny-sex-video-clips.htm
tit sex tranny http://hometown.aol.com/horny68842857/tit-sex-tranny.htm
asian xxx photos http://hometown.aol.com/couple72638144/asian-xxx-photos.htm
lesbian porn 89 http://hometown.aol.com/horny68842857/lesbian-porn-89.htm
best xxx asian site http://hometown.aol.com/couple72638144/best-xxx-asian-site.htm
gay leather ass boy http://hometown.aol.com/teen512517388/gay-leather-ass-boy.htm
hottest tranny sex http://hometown.aol.com/pretty66780802/hottest-tranny-sex.htm
tranny sex xxx http://hometown.aol.com/teeny040352853/tranny-sex-xxx.htm
tranny sex movies http://hometown.aol.com/teeny040352853/tranny-sex-movies.htm
outdoor asian xxx http://hometown.aol.com/couple72638144/outdoor-asian-xxx.htm
phoenix gambling books http://hometown.aol.com/internet9487chip/phoenix-gambling-books.htm
tranny having sex with women http://hometown.aol.com/pretty66780802/tranny-having-sex-with-women.htm
gay electro leather http://hometown.aol.com/teen512517388/gay-electro-leather.htm
male strippers getting money from women http://hometown.aol.com/horny68842857/male-strippers-getting-money-from-women.htm
89 porn panties http://hometown.aol.com/horny68842857/89-porn-panties.htm
tranny sex trailer http://hometown.aol.com/horny68842857/tranny-sex-trailer.htm
how to make love and sex with 69 http://hometown.aol.com/horny68842857/how-to-make-love-and-sex-with-69.htm
tranny sex trailors http://hometown.aol.com/teeny040352853/tranny-sex-trailors.htm
free slot machine dowloads http://hometown.aol.com/internet9487chip/free-slot-machine-dowloads.htm
asian xxx las palmas gran canary http://hometown.aol.com/couple72638144/asian-xxx-las-palmas-gran-canary.htm
where can i watch jenna lewis sex tape free http://hometown.aol.com/action658523472/where-can-i-watch-jenna-lewis-sex-tape-free.htm
tranny solo sex http://hometown.aol.com/teeny040352853/tranny-solo-sex.htm
投稿者 hr3d5is0 : February 20, 2007 09:07 AM
hardcore asain porn http://hometown.aol.com/girls284911472/hardcore-asain-porn.htm
lil kim gang of roses porn video http://hometown.aol.com/hard11987370/lil-kim-gang-of-roses-porn-video.htm
free porn clips of asain girls http://hometown.aol.com/girls284911472/free-porn-clips-of-asain-girls.htm
porn with video game characters http://hometown.aol.com/hard11987370/porn-with-video-game-characters.htm
how to make love and sex with 69 http://hometown.aol.com/teen80869438/how-to-make-love-and-sex-with-69.htm
1 video game porn http://hometown.aol.com/hard11987370/1-video-game-porn.htm
xxx free stories http://hometown.aol.com/hard05348903/xxx-free-stories.htm
sexy skinny women porn http://hometown.aol.com/woman798717903/sexy-skinny-women-porn.htm
male strippers getting money from women http://hometown.aol.com/pretty873853159/male-strippers-getting-money-from-women.htm
teachers students fucking http://hometown.aol.com/hard05348903/teachers-students-fucking.htm
video game chariciters in porn http://hometown.aol.com/hard11987370/video-game-chariciters-in-porn.htm
sexy hardcore porn videos http://hometown.aol.com/woman798717903/sexy-hardcore-porn-videos.htm
xxx free stories http://hometown.aol.com/pretty264949745/xxx-free-stories.htm
video game babes porn http://hometown.aol.com/hard11987370/video-game-babes-porn.htm
xxx free stories http://hometown.aol.com/hard11987370/xxx-free-stories.htm
xxx free stories http://hometown.aol.com/pretty873853159/xxx-free-stories.htm
dorki asian whores http://hometown.aol.com/teen80869438/dorki-asian-whores.htm
how to make love and sex with 69 http://hometown.aol.com/hard05348903/how-to-make-love-and-sex-with-69.htm
sex asian girl genital http://hometown.aol.com/pretty873853159/sex-asian-girl-genital.htm
asain email porn http://hometown.aol.com/girls284911472/asain-email-porn.htm
asian bukake whores http://hometown.aol.com/teen80869438/asian-bukake-whores.htm
porn asain fucked cock http://hometown.aol.com/girls284911472/porn-asain-fucked-cock.htm
asian and white girl sex http://hometown.aol.com/pretty873853159/asian-and-white-girl-sex.htm
how to make love and sex with 69 http://hometown.aol.com/pretty264949745/how-to-make-love-and-sex-with-69.htm
hardcore asian whores http://hometown.aol.com/pretty264949745/hardcore-asian-whores.htm
hawaiian asain porn http://hometown.aol.com/hard52286950/hawaiian-asain-porn.htm
free sexy girls porn http://hometown.aol.com/woman798717903/free-sexy-girls-porn.htm
my friends sexy mom free porn http://hometown.aol.com/woman798717903/my-friends-sexy-mom-free-porn.htm
slutty asian lesbian whores http://hometown.aol.com/pretty264949745/slutty-asian-lesbian-whores.htm
asain pornstar kitty porn http://hometown.aol.com/hard52286950/asain-pornstar-kitty-porn.htm
投稿者 bcesqaur92 : February 25, 2007 10:00 PM
training the male dog slave http://hometown.aol.com/boys38615163/training-the-male-dog-slave.htm
how to become a male toilet slave http://hometown.aol.com/male223559218/how-to-become-a-male-toilet-slave.htm
asian slave boy white master http://hometown.aol.com/couple29329481/asian-slave-boy-white-master.htm
spanking story male submission http://hometown.aol.com/teen455660922/spanking-story-male-submission.htm
master male slave bdsm personals free http://hometown.aol.com/male223559218/master-male-slave-bdsm-personals-free.htm
male sex slave training http://hometown.aol.com/movies62177710/male-sex-slave-training.htm
what is bdsm male milking http://hometown.aol.com/couple29329481/what-is-bdsm-male-milking.htm
sissy male maid spanking http://hometown.aol.com/males16627900/sissy-male-maid-spanking.htm
male slave exchange http://hometown.aol.com/male223559218/male-slave-exchange.htm
painted male nipples http://hometown.aol.com/couple29329481/painted-male-nipples.htm
male tampon slave http://hometown.aol.com/movies62177710/male-tampon-slave.htm
bacchus male spanking http://hometown.aol.com/teen455660922/bacchus-male-spanking.htm
males naked in europe http://hometown.aol.com/pics87073190/males-naked-in-europe.htm
male slave fisting http://hometown.aol.com/couple29329481/male-slave-fisting.htm
spanking an adult male http://hometown.aol.com/males16627900/spanking-an-adult-male.htm
male butt spanking http://hometown.aol.com/pics87073190/male-butt-spanking.htm
kneeling male slave http://hometown.aol.com/male223559218/kneeling-male-slave.htm
american males naked in europe http://hometown.aol.com/pics87073190/american-males-naked-in-europe.htm
roman male slave http://hometown.aol.com/male223559218/roman-male-slave.htm
sexy male european models http://hometown.aol.com/males16627900/sexy-male-european-models.htm
male cross dressing slave stories http://hometown.aol.com/boys38615163/male-cross-dressing-slave-stories.htm
male slave ass http://hometown.aol.com/males16627900/male-slave-ass.htm
male slave and mistress http://hometown.aol.com/boys38615163/male-slave-and-mistress.htm
spanking stories male http://hometown.aol.com/males16627900/spanking-stories-male.htm
male spanking drawings http://hometown.aol.com/males16627900/male-spanking-drawings.htm
leather slave male http://hometown.aol.com/pics87073190/leather-slave-male.htm
male spanking cartoon http://hometown.aol.com/males16627900/male-spanking-cartoon.htm
male bodybuilders leather http://hometown.aol.com/pics87073190/male-bodybuilders-leather.htm
leather sm dog slave male http://hometown.aol.com/male223559218/leather-sm-dog-slave-male.htm
male slaves obeying dominant mistresses http://hometown.aol.com/boys38615163/male-slaves-obeying-dominant-mistresses.htm
投稿者 lbrmskmd75 : February 25, 2007 10:02 PM
amatuer porn galleries http://hometown.aol.com/anal48428871/amatuer-porn-galleries.htm
asian womendrinking cum http://hometown.aol.com/hard328533492/asian-womendrinking-cum.htm
facials asian cum shots http://hometown.aol.com/hard328533492/facials-asian-cum-shots.htm
video samples of adult amatuer porn sites http://hometown.aol.com/girls50861881/video-samples-of-adult-amatuer-porn-sites.htm
asian girls shooting cum http://hometown.aol.com/hard328533492/asian-girls-shooting-cum.htm
asian women cum shot http://hometown.aol.com/hard328533492/asian-women-cum-shot.htm
asian escort dancer fresno ca http://hometown.aol.com/hard328533492/asian-escort-dancer-fresno-ca.htm
private amatuer porn sites http://hometown.aol.com/sweet439543652/private-amatuer-porn-sit