• R/O
  • SSH
  • HTTPS

thief: コミット


コミットメタ情報

リビジョン37 (tree)
日時2012-01-21 20:07:30
作者seussnu

ログメッセージ

0.0.8-alpha2
・ オブジェクトの行動順番を修正
・ 若干高速化

変更サマリ

差分

--- thief.js (revision 36)
+++ thief.js (revision 37)
@@ -55,7 +55,8 @@
5555 ' SAN:${THIEF.global.adventurer.%get@san%}' +
5656 ' AC:${THIEF.global.adventurer.%get@armorPoint%}',
5757 'Turn:${THIEF.global.turn}' +
58- ' CT:${THIEF.global.adventurer.%get@ct%}'
58+ ' CT:${THIEF.global.adventurer.%get@ct%}' +
59+ ' ${THIEF.global.actLV.actObjectList.length}'
5960 ],
6061 messagePosition : 'top', // top or bottom
6162 messageLines : 3,
@@ -313,11 +314,6 @@
313314 };
314315 }
315316
316-// xxx : Manualable
317-// $xxx : Common
318-// _xxx : DebugModeOnly
319-//
320-
321317 THIEF.func = {};
322318 THIEF.func.method = {};
323319 THIEF.func.method.get = function (param) {
@@ -367,6 +363,11 @@
367363 }
368364 THIEF.html.addDebugMessage('...' + obj.get(THIEF.PROP.displayName) + 'を' + this.get(THIEF.PROP.displayName) + 'のインベントリ座標[' + objX + ', ' + objY + ']から除外完了。');
369365
366+ if(this.type === 'level' && obj.active){
367+ THIEF.html.addDebugMessage('アクティブリストから除外');
368+ this[THIEF.PROP.actObjectList].remove(obj);
369+ }
370+
370371 return true;
371372 };
372373
@@ -416,8 +417,15 @@
416417 THIEF.html.addDebugMessage('...アルファベットの割り当て処理完了。');
417418 }
418419
420+ // 格納
419421 this.inventory[i][j].push(obj);
420422 THIEF.html.addDebugMessage('[' + i + ', ' + j + ']に' + obj.get(THIEF.PROP.alphabet) + 'として追加');
423+
424+ if(this.type === 'level' && obj.active){
425+ THIEF.html.addDebugMessage('アクティブリストに追加');
426+ this[THIEF.PROP.actObjectList].push(obj);
427+ }
428+
421429 result = true;
422430 }
423431 }
@@ -584,7 +592,7 @@
584592 return true;
585593 };
586594
587-THIEF.func.method.getInventoryXyObjects = function(x, y) {
595+THIEF.func.method.getInventoryXyObjectList = function(x, y) {
588596 return this.inventory[x][y];
589597 };
590598
@@ -598,21 +606,13 @@
598606 return obj;
599607 };
600608
601-THIEF.func.method.delInventoryObject = function(o) {
602- this.delInventoryXyObject(o.x, o.y, o);
609+THIEF.func.method.removeInventoryObject = function(o) {
610+ this.removeInventoryXyObject(o.x, o.y, o);
603611 };
604612
605613
606-THIEF.func.method.delInventoryXyObject = function(x, y, o) {
614+THIEF.func.method.removeInventoryXyObject = function(x, y, o) {
607615 this.inventory[x][y].remove(o);
608- /*
609- if (this.mapRefreshPointList) {
610- this.mapRefreshPointList.push({
611- x: x,
612- y: y
613- });
614- }
615- */
616616 };
617617
618618 // ループ処理を加えること
@@ -812,6 +812,9 @@
812812
813813 THIEF.html.addDebugMessage('...CPU行動完了');
814814
815+ // TODO
816+ this.ct = 99;
817+
815818 return true;
816819 };
817820
@@ -871,8 +874,9 @@
871874 return this.cpu();
872875 };
873876
874-THIEF.func.method.notify = function() {
877+THIEF.func.method.getObjectList = function(compObj, recursive){
875878
879+ var list = [];
876880 if (typeof this.inventory !== "undefined") {
877881 var width = this.get(THIEF.PROP.inventoryWidth);
878882 for (var x = 0; x < width; x++) {
@@ -879,99 +883,73 @@
879883 if (typeof this.inventory[x] === "undefined") {
880884 break;
881885 }
882- var length = this.get(THIEF.PROP.inventoryHeight);
883- for (var y = 0; y < length; y++) {
886+ var height = this.get(THIEF.PROP.inventoryHeight);
887+ for (var y = 0; y < height; y++) {
884888 if (typeof this.inventory[x][y] === "undefined") {
885889 break;
886890 }
887- var height = this.inventory[x][y].length;
888- for (var h = 0; h < height; h++) {
889- this.inventory[x][y][h].notify();
891+ var depth = this.inventory[x][y].length;
892+ for (var z = 0; z < depth; z++) {
893+
894+ var result = true;
895+ for(var name in compObj){
896+ if(this.inventory[x][y][z][name] === compObj[name]){
897+
898+ } else {
899+ result = false;
900+ break;
901+ }
902+ }
903+ if(result){
904+ list.push(this.inventory[x][y][z]);
905+ }
906+ if(recursive){
907+ // 持ち物の持ち物も検索
908+ list = list.concat(this.inventory[x][y][z].getObjectList(compObj, recursive));
909+ }
890910 }
891911 }
892912 }
893913 }
894914
895- // CT を増加
896- if (this.get(THIEF.PROP.active)) {
915+ return list;
916+};
897917
898- if (this.ct > 100) {
899- this.ct = 100;
900- }
918+THIEF.func.method.execActiveObjects = function(){
919+ var result = true;
901920
902- if (typeof this.get(THIEF.PROP.dex) === undefined) {
903- this[THIEF.PROP.ct] += this.get(THIEF.PROP.dex);
904- } else {
905- this[THIEF.PROP.ct] += 33; // test
906- }
907- THIEF.html.addDebugMessage(this.get(THIEF.PROP.displayName) + ' の CT を ' + this[THIEF.PROP.ct] + ' に増加。');
908- }
921+ if (this[THIEF.PROP.actObjectList]) {
922+ // アクティブリストを降順にソート
923+ this[THIEF.PROP.actObjectList].sort(function(a, b){
924+ return b.ct - a.ct;
925+ });
926+
927+ while(this[THIEF.PROP.actObjectList][0] && this[THIEF.PROP.actObjectList][0].ct >= 100){
928+ var obj = this[THIEF.PROP.actObjectList][0];
929+ if(obj.ct >= 100){
930+ THIEF.html.addDebugMessage(obj.get(THIEF.PROP.displayName) + ' の処理を開始...');
931+ result = obj.action();
932+ if(result){
933+ THIEF.html.addDebugMessage('...処理を完了');
934+ } else {
935+ THIEF.html.addDebugMessage('...' + obj.get(THIEF.PROP.displayName) + ' は処理が完了しなかった。');
936+ break;
937+ }
938+ }
909939
910- // ct が 100 を超えていたら行動対象に登録
911- if (this.get(THIEF.PROP.ct) >= 100) {
912- if (typeof this[THIEF.PROP.myOwner][THIEF.PROP.actObjectList] === "undefined") {
913- this[THIEF.PROP.myOwner][THIEF.PROP.actObjectList] = [];
940+ // アクティブリストを降順にソート
941+ this[THIEF.PROP.actObjectList].sort(function(a, b){
942+ return b.ct - a.ct;
943+ });
914944 }
915- THIEF.html.addDebugMessage(this.get(THIEF.PROP.displayName) + ' を、オーナ:' + this[THIEF.PROP.myOwner].get(THIEF.PROP.displayName) + ' に登録。');
916- this[THIEF.PROP.myOwner][THIEF.PROP.actObjectList].push(this);
917945 }
946+ return result;
918947 };
919948
920949 THIEF.func.method.action = function() {
921950
922951 THIEF.html.addDebugMessage(this.get(THIEF.PROP.displayName) + ' の行動を開始...');
923-
924- if (typeof this[THIEF.PROP.actObjectList] !== 'undefined') {
925-
926- // ct の小さい順にソートする
927- for (var i = 0; i < this[THIEF.PROP.actObjectList].length - 2; i++) {
928- var isSorted = true;
929- for (var j = this[THIEF.PROP.actObjectList].length - 1; j >= (1 + i); j--) {
930- if (this[THIEF.PROP.actObjectList][j].get(THIEF.PROP.ct) < this[THIEF.PROP.actObjectList][j - 1].get(THIEF.PROP.ct)) {
931- var swap = this[THIEF.PROP.actObjectList][j];
932- this[THIEF.PROP.actObjectList][j] = this[THIEF.PROP.actObjectList][j - 1];
933- this[THIEF.PROP.actObjectList][j - 1] = swap;
934- isSorted = false;
935- }
936- }
937- if (isSorted) {
938- break;
939- }
940- }
941-
942- // ct の大きい順(配列の最後部)から実行
943- var obj = this[THIEF.PROP.actObjectList].pop();
944- for (; typeof obj !== 'undefined'; obj = this[THIEF.PROP.actObjectList].pop()) {
945- THIEF.html.addDebugMessage(obj.get(THIEF.PROP.displayName) + ' の処理を開始...');
946- if (obj.action() === false) {
947- // 行動が完了しない場合、現在のオブジェクトを再登録して一時停止(結果的に入力を待つ)
948- THIEF.html.addDebugMessage('...' + obj.get(THIEF.PROP.displayName) + ' は処理が完了しなかった。');
949- this[THIEF.PROP.actObjectList].push(obj);
950-
951- break;
952- }
953- THIEF.html.addDebugMessage('...処理を完了');
954- }
955- }
956-
957- var result = true;
958- if (typeof this[THIEF.PROP.actObjectList] === 'undefined' || this[THIEF.PROP.actObjectList].length === 0) {
959- if (this.active && this.turnEnd !== THIEF.global.turn) {
960-
961- if (this.get(THIEF.PROP.ct) >= 100) {
962- if (this.next()) {
963- this.turnEnd = THIEF.global.turn;
964- //this[THIEF.PARAM.ct] -= 100;
965- result = true;
966- } else {
967- result = false;
968- }
969- }
970- }
971- } else if (this[THIEF.PROP.actObjectList].length > 0) {
972- result = false;
973- }
974-
952+ var result = this.next();
975953 THIEF.html.addDebugMessage('... ' + this.get(THIEF.PROP.displayName) + ' の行動を完了。 (result = ' + result + ')');
976954
977955 return result;
@@ -983,7 +961,7 @@
983961 this.dp--;
984962 if (this.dp <= 0) {
985963 THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.decay, this.name));
986- THIEF.global.actLV.delInventoryObject(this);
964+ THIEF.global.actLV.removeInventoryObject(this);
987965 }
988966 }
989967
@@ -1039,7 +1017,7 @@
10391017 };
10401018
10411019 THIEF.func.method.goTheStairs = function(trueIsUpFalseIsDown) {
1042- var floor = THIEF.global.actLV.getInventoryXyObjects(this.x, this.y);
1020+ var floor = THIEF.global.actLV.getInventoryXyObjectList(this.x, this.y);
10431021 var stairs;
10441022 var flag = false;
10451023 // 足元に、階段があるか確認
@@ -1102,10 +1080,12 @@
11021080 }
11031081 }
11041082
1083+ this.ct -= 100;
11051084 THIEF.global.actLV.addToInventory(this, stairs.partner.point.x, stairs.partner.point.y);
1085+ THIEF.util.updateStatus();
11061086 THIEF.html.refresh();
1107- THIEF.util.updateStatus();
11081087
1088+
11091089 } else {
11101090 if (trueIsUpFalseIsDown) {
11111091 THIEF.html.addMessage(THIEF.util.getText(THIEF.Data.Text.doesNotGoUpStairs));
@@ -1160,7 +1140,7 @@
11601140 };
11611141
11621142 THIEF.func.command.pickup = function() {
1163- var tmp = THIEF.global.actLV.getInventoryXyObjects(this.x, this.y);
1143+ var tmp = THIEF.global.actLV.getInventoryXyObjectList(this.x, this.y);
11641144 var finish = true;
11651145 var objs = [];
11661146
@@ -1572,7 +1552,6 @@
15721552
15731553 THIEF.util.test = function() {
15741554
1575-
15761555 THIEF.global.adventurer = THIEF.util.factory(THIEF.Data.Obj.Human);
15771556 THIEF.global.adventurer.color = 'red';
15781557 THIEF.global.adventurer.next = THIEF.global.adventurer.inputWait;
@@ -1624,9 +1603,16 @@
16241603 if (completion) {
16251604 THIEF.global.turn++;
16261605 THIEF.html.addDebugMessage('<em>ターン:' + THIEF.global.turn + ' を開始</em>...');
1627- THIEF.html.addDebugMessage('通知を開始...');
1628- THIEF.global.actLV.notify();
1629- THIEF.html.addDebugMessage('...通知を完了');
1606+ THIEF.html.addDebugMessage('CT の増減を開始...');
1607+ for(var i=0; i<THIEF.global.actLV[THIEF.PROP.actObjectList].length; i++){
1608+ var obj = THIEF.global.actLV[THIEF.PROP.actObjectList][i];
1609+ if(obj.dex){
1610+ obj.ct += obj.dex * 4;
1611+ } else {
1612+ obj.ct = 100;
1613+ }
1614+ }
1615+ THIEF.html.addDebugMessage('...増減を完了');
16301616
16311617 // 各レベルに実施させること
16321618 if (!THIEF.global.actLV.safety && Math.random() > 0.9) {
@@ -1637,7 +1623,7 @@
16371623 }
16381624
16391625 THIEF.html.addDebugMessage('アクティブになったオブジェクトの処理を実施...');
1640- completion = THIEF.global.actLV.action();
1626+ completion = THIEF.global.actLV.execActiveObjects();
16411627 THIEF.html.addDebugMessage('...アクティブになったオブジェクトの処理を完了');
16421628
16431629 THIEF.util.updateStatus();
@@ -1742,6 +1728,7 @@
17421728 case THIEF.KEY.a:
17431729 case THIEF.KEY.c:
17441730 case THIEF.KEY.d:
1731+ case THIEF.KEY.f:
17451732 case THIEF.KEY.v:
17461733 if (e.ctrlKey) {
17471734 block = false;
@@ -2003,6 +1990,7 @@
20031990 level[THIEF.PROP.inventoryWidth] = dun.width || THIEF.Data.Scenario.$.width || 60;
20041991 level[THIEF.PROP.inventoryHeight] = dun.height || THIEF.Data.Scenario.$.height || 20;
20051992 level[THIEF.PROP.inventoryDepth] = dun.depth || THIEF.Data.Scenario.$.depth || 256;
1993+ level[THIEF.PROP.actObjectList] = []; //level.getObjectList({active:true}, true);
20061994 level.inventoryCellSize = 1;
20071995
20081996 var template = {};
@@ -2123,6 +2111,7 @@
21232111 level.safety = template.safety;
21242112 }
21252113
2114+ level.type = 'level';
21262115 level.created = true;
21272116 dun[lvNum] = level;
21282117
@@ -2776,7 +2765,7 @@
27762765
27772766 if (arguments[0][lang]) {
27782767 text = arguments[0][lang];
2779- THIEF.html.addDebugMessage('言語設定は、優先度 ' + i + ' の ' + THIEF.conf.languagePriolity[i] + ' とする。');
2768+ THIEF.html.addDebugMessage('言語設定は、優先度 ' + i + ' の ' + THIEF.conf.languagePriolity[i] + ' : ' + text);
27802769 break;
27812770 }
27822771 }
旧リポジトリブラウザで表示