X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。
リビジョン | 304 (tree) |
---|---|
日時 | 2022-04-17 01:50:09 |
作者 | xops-mikan |
R301にてAIの手榴弾投げパスが正しく動作しない場合がある問題の対策、一部処理を関数化
@@ -63,6 +63,7 @@ | ||
63 | 63 | cautioncnt = 0; |
64 | 64 | actioncnt = 0; |
65 | 65 | longattack = false; |
66 | + EventWeaponShot = false; | |
66 | 67 | LevelParam = NULL; |
67 | 68 | |
68 | 69 | MoveNavi = new AIMoveNavi; |
@@ -1205,12 +1206,17 @@ | ||
1205 | 1206 | ObjDriver->SetModeFlag(AI_CTRL_TURNDOWN); |
1206 | 1207 | } |
1207 | 1208 | |
1208 | - //投げる | |
1209 | + //照準に定まっているか確認 | |
1209 | 1210 | if( (fabsf(atan_rx) < DegreeToRadian(1.5f))&&(fabsf(atan_ry) < DegreeToRadian(1.5f)) ){ |
1211 | + //連射させない | |
1212 | + if( (ctrlhuman->GetWeaponBlazingmode() == false)&&(EventWeaponShot == true) ){ return 0; } | |
1213 | + | |
1210 | 1214 | //角度を設定 |
1211 | 1215 | ctrlhuman->SetRxRy(rx, ry); |
1212 | 1216 | |
1217 | + //投げる | |
1213 | 1218 | if( ObjMgr->ShotWeapon(ctrlid) != 0 ){ |
1219 | + EventWeaponShot = true; | |
1214 | 1220 | return 1; |
1215 | 1221 | } |
1216 | 1222 | } |
@@ -1630,6 +1636,7 @@ | ||
1630 | 1636 | { |
1631 | 1637 | int newbattlemode = AI_NORMAL; |
1632 | 1638 | float caution_rx; |
1639 | + int EventThrowGrenade = 0; | |
1633 | 1640 | |
1634 | 1641 | MoveNavi->MovePathNowState(); |
1635 | 1642 | enemyhuman = NULL; |
@@ -1656,11 +1663,15 @@ | ||
1656 | 1663 | |
1657 | 1664 | //手榴弾パス |
1658 | 1665 | if( MoveNavi->GetMoveMode() == AI_GRENADE ){ |
1659 | - if( ThrowGrenade() != 0 ){ | |
1666 | + EventThrowGrenade = ThrowGrenade(); | |
1667 | + if( EventThrowGrenade != 0 ){ | |
1660 | 1668 | MoveNavi->MovePathNextState(); |
1661 | 1669 | MoveNavi->MovePathNowState(); |
1662 | 1670 | } |
1663 | 1671 | } |
1672 | + if( EventThrowGrenade != 1 ){ | |
1673 | + EventWeaponShot = false; | |
1674 | + } | |
1664 | 1675 | |
1665 | 1676 | if( MoveNavi->GetMoveMode() == AI_RUN2 ){ //優先的な走りの処理 |
1666 | 1677 | //敵を見つけたら攻撃に入る |
@@ -1736,6 +1747,7 @@ | ||
1736 | 1747 | cautioncnt = 0; |
1737 | 1748 | actioncnt = 0; |
1738 | 1749 | longattack = false; |
1750 | + EventWeaponShot = false; | |
1739 | 1751 | |
1740 | 1752 | MoveNavi->Init(); |
1741 | 1753 | ObjDriver->Init(); |
@@ -78,12 +78,13 @@ | ||
78 | 78 | bool FaceCaution_flag; //!< 警戒中に特定の報告を向くフラグ |
79 | 79 | float FaceCaution_rx; //!< 警戒中に向く方向 |
80 | 80 | float total_move; //!< 合計移動量 |
81 | - int waitcnt; //!< 時間待ちカウント | |
82 | - int movejumpcnt; //!< ジャンプ判定カウント | |
83 | - int gotocnt; //!< 移動カウント | |
84 | - int cautioncnt; //!< 警戒中カウント | |
85 | - int actioncnt; //!< 攻撃中カウント | |
86 | - bool longattack; //!< 近距離・遠距離フラグ | |
81 | + int waitcnt; //!< 時間待ちカウント | |
82 | + int movejumpcnt; //!< ジャンプ判定カウント | |
83 | + int gotocnt; //!< 移動カウント | |
84 | + int cautioncnt; //!< 警戒中カウント | |
85 | + int actioncnt; //!< 攻撃中カウント | |
86 | + bool longattack; //!< 近距離・遠距離フラグ | |
87 | + bool EventWeaponShot; //!< イベントによる手榴弾投げフラグ | |
87 | 88 | AIParameter *LevelParam; //!< AIの性能値 |
88 | 89 | |
89 | 90 | bool CheckTargetPos(bool back); |
@@ -791,7 +791,7 @@ | ||
791 | 791 | //! @param filename ファイル名 |
792 | 792 | //! @param nowformat 現在の判別値 |
793 | 793 | //! @return 新たな判別値 |
794 | -int D3DGraphics::CheckFileExtension(const char* filename, int nowformat) | |
794 | +int D3DGraphics::CheckTextureFileExtension(const char* filename, int nowformat) | |
795 | 795 | { |
796 | 796 | char filename2[MAX_PATH]; |
797 | 797 |
@@ -832,7 +832,7 @@ | ||
832 | 832 | //! @param filename ファイル名 |
833 | 833 | //! @param nowformat 現在の判別値 |
834 | 834 | //! @return 新たな判別値 |
835 | -int D3DGraphics::CheckFileTypeFlag(const char* filename, int nowformat) | |
835 | +int D3DGraphics::CheckTextureFileTypeFlag(const char* filename, int nowformat) | |
836 | 836 | { |
837 | 837 | FILE *fp; |
838 | 838 | unsigned char header[4]; |
@@ -893,10 +893,10 @@ | ||
893 | 893 | if( id == -1 ){ return -1; } |
894 | 894 | |
895 | 895 | //まず拡張子でファイルフォーマットを判定 |
896 | - format = CheckFileExtension(filename, format); | |
896 | + format = CheckTextureFileExtension(filename, format); | |
897 | 897 | |
898 | 898 | //ファイルヘッダーの情報でも確認 |
899 | - format = CheckFileTypeFlag(filename, format); | |
899 | + format = CheckTextureFileTypeFlag(filename, format); | |
900 | 900 | |
901 | 901 | //対応してないフォーマット |
902 | 902 | if( format == 0 ){ return -1; } |
@@ -272,8 +272,8 @@ | ||
272 | 272 | #endif |
273 | 273 | |
274 | 274 | void CleanupD3Dresource(); |
275 | - int CheckFileExtension(const char* filename, int nowformat); | |
276 | - int CheckFileTypeFlag(const char* filename, int nowformat); | |
275 | + int CheckTextureFileExtension(const char* filename, int nowformat); | |
276 | + int CheckTextureFileTypeFlag(const char* filename, int nowformat); | |
277 | 277 | bool LoadBMPTexture(const char* filename, bool BlackTransparent, TEXTUREDATA *ptexture); |
278 | 278 | bool LoadDDSTexture(const char* filename, bool BlackTransparent, TEXTUREDATA *ptexture); |
279 | 279 | bool LoadJPEGTexture(const char* filename, bool BlackTransparent, TEXTUREDATA *ptexture); |
@@ -704,18 +704,9 @@ | ||
704 | 704 | mif = true; |
705 | 705 | |
706 | 706 | //拡張子が.txtならば |
707 | - //if( strcmp(PathFindExtension(fname), ".txt") == 0 ){ | |
708 | - // //MIFフラグを無効に | |
709 | - // mif = false; | |
710 | - //} | |
711 | - for(int i=strlen(fname)-1; i>0; i--){ | |
712 | - if( fname[i] == '.' ){ | |
713 | - if( strcmp(&(fname[i]), ".txt") == 0 ){ | |
714 | - //MIFフラグを無効に | |
715 | - mif = false; | |
716 | - } | |
717 | - break; | |
718 | - } | |
707 | + if( CheckFileExtension(fname, ".txt") == true ){ | |
708 | + //MIFフラグを無効に | |
709 | + mif = false; | |
719 | 710 | } |
720 | 711 | |
721 | 712 | #ifdef ENABLE_PATH_DELIMITER_SLASH |
@@ -1649,4 +1640,40 @@ | ||
1649 | 1640 | if( dir[i] == '\\' ){ dir[i+1] = '\0'; break; } |
1650 | 1641 | if( dir[i] == '/' ){ dir[i+1] = '\0'; break; } |
1651 | 1642 | } |
1643 | +} | |
1644 | + | |
1645 | +//! @brief ファイル拡張子を判定する | |
1646 | +//! @param filepath ファイル名 | |
1647 | +//! @param checkstr 拡張子名 | |
1648 | +//! @return 該当:true 非該当:false | |
1649 | +//! @attention 拡張子は"."込みで指定してください。大文字・小文字は区別しません。 | |
1650 | +bool CheckFileExtension(const char *filepath, const char *checkstr) | |
1651 | +{ | |
1652 | + if( strlen(filepath) >= MAX_PATH ){ return false; } | |
1653 | + if( strlen(checkstr) >= 16 ){ return false; } | |
1654 | + if( strlen(filepath) < strlen(checkstr) ){ return false; } | |
1655 | + | |
1656 | + char filepath2[MAX_PATH]; | |
1657 | + char checkstr2[16]; | |
1658 | + | |
1659 | + //ファイル名を小文字へ変換 | |
1660 | + for(int i=0; i<(int)strlen(filepath); i++){ | |
1661 | + filepath2[i] = (char)tolower((int)filepath[i]); | |
1662 | + } | |
1663 | + filepath2[ strlen(filepath) ] = '\0'; | |
1664 | + | |
1665 | + //拡張子名を小文字へ変換 | |
1666 | + for(int i=0; i<(int)strlen(checkstr); i++){ | |
1667 | + checkstr2[i] = (char)tolower((int)checkstr[i]); | |
1668 | + } | |
1669 | + checkstr2[ strlen(checkstr) ] = '\0'; | |
1670 | + | |
1671 | + //拡張子判定 | |
1672 | + for(int i=strlen(filepath2)-1; i>0; i--){ | |
1673 | + if( filepath2[i] == '.' ){ | |
1674 | + if( strcmp(&(filepath2[i]), checkstr2) == 0 ){ return true; } | |
1675 | + return false; | |
1676 | + } | |
1677 | + } | |
1678 | + return false; | |
1652 | 1679 | } |
\ No newline at end of file |
@@ -240,5 +240,6 @@ | ||
240 | 240 | int DeleteLinefeed(char str[]); |
241 | 241 | bool CheckFullPath(const char *path); |
242 | 242 | void GetFileDirectory(const char *path, char *dir); |
243 | +bool CheckFileExtension(const char *filepath, const char *checkstr); | |
243 | 244 | |
244 | 245 | #endif |
\ No newline at end of file |
@@ -90,9 +90,7 @@ | ||
90 | 90 | for(int param=1; param<__argc; param++){ |
91 | 91 | #ifdef ENABLE_DEBUGLOG |
92 | 92 | //"Log"が与えられていたら、ログ出力を有効化 |
93 | - if( (strcmp(__argv[param], "-Log") == 0)||(strcmp(__argv[param], "/Log") == 0)|| | |
94 | - (strcmp(__argv[param], "-log") == 0)||(strcmp(__argv[param], "/log") == 0) | |
95 | - ){ | |
93 | + if( CheckCommandParameter(__argv[param], "-Log") == true ){ | |
96 | 94 | //ログ出力を有効化 |
97 | 95 | OutputLog.EnableOutputLog(); |
98 | 96 |
@@ -103,9 +101,7 @@ | ||
103 | 101 | |
104 | 102 | #ifdef ENABLE_AUTOLOADMIF |
105 | 103 | //"Dir"が与えられていたら、カレントディレクトリ移動 |
106 | - if( (strcmp(__argv[param], "-Dir") == 0)||(strcmp(__argv[param], "/Dir") == 0)|| | |
107 | - (strcmp(__argv[param], "-dir") == 0)||(strcmp(__argv[param], "/dir") == 0) | |
108 | - ){ | |
104 | + if( CheckCommandParameter(__argv[param], "-Dir") == true ){ | |
109 | 105 | if( (param+1) < __argc ){ |
110 | 106 | chdir(__argv[param+1]); |
111 | 107 | param += 1; |
@@ -114,22 +110,15 @@ | ||
114 | 110 | } |
115 | 111 | |
116 | 112 | //"NoBriefing"が与えられていたら、(.mif指定時は)ブリーフィングを省略する |
117 | - if( (strcmp(__argv[param], "-NoBriefing") == 0)||(strcmp(__argv[param], "/NoBriefing") == 0)|| | |
118 | - (strcmp(__argv[param], "-nobriefing") == 0)||(strcmp(__argv[param], "/bobriefing") == 0) | |
119 | - ){ | |
113 | + if( CheckCommandParameter(__argv[param], "-NoBriefing") == true ){ | |
120 | 114 | NoBriefingFlag = true; |
121 | 115 | continue; |
122 | 116 | } |
123 | 117 | |
124 | - //それ以外の引数ならば拡張子を取り出してみる | |
125 | - for(int i=strlen(__argv[param])-1; i>0; i--){ | |
126 | - if( __argv[param][i] == '.' ){ | |
127 | - if( strcmp(&(__argv[param][i]), ".mif") == 0 ){ | |
128 | - //.mifであればファイルパスとして記憶 | |
129 | - strcpy(path, __argv[param]); | |
130 | - } | |
131 | - break; | |
132 | - } | |
118 | + //それ以外の引数ならば拡張子を判定してみる | |
119 | + if( CheckFileExtension(__argv[param], ".mif") == true ){ | |
120 | + //.mifであればファイルパスとして記憶 | |
121 | + strcpy(path, __argv[param]); | |
133 | 122 | } |
134 | 123 | #endif |
135 | 124 | } |
@@ -266,6 +255,36 @@ | ||
266 | 255 | return 0; |
267 | 256 | } |
268 | 257 | |
258 | +//! @brief コマンド引数判定 | |
259 | +//! @param param 元の文字列 | |
260 | +//! @param cmd 判定する引数 | |
261 | +//! @return 該当:true 非該当:false | |
262 | +//! @warning cmd引数の最初の一文字は無視されます。 | |
263 | +//! @attention 次の引数を判定します。>/[引数]、-[引数]、/[引数(小文字)]、-[引数(小文字)] | |
264 | +bool CheckCommandParameter(const char *param, const char *cmd) | |
265 | +{ | |
266 | + if( strlen(param) >= 16 ){ return false; } | |
267 | + if( strlen(cmd) >= 16 ){ return false; } | |
268 | + if( strlen(param) != strlen(cmd) ){ return false; } | |
269 | + | |
270 | + char str[16]; | |
271 | + strcpy(str, cmd); | |
272 | + | |
273 | + str[0] = '/'; | |
274 | + if( strcmp(param, str) == 0 ){ return true; } | |
275 | + str[0] = '-'; | |
276 | + if( strcmp(param, str) == 0 ){ return true; } | |
277 | + | |
278 | + for(int i=0; i<strlen(str); i++){ str[i] = (char)tolower((int)(str[i])); } | |
279 | + | |
280 | + str[0] = '/'; | |
281 | + if( strcmp(param, str) == 0 ){ return true; } | |
282 | + str[0] = '-'; | |
283 | + if( strcmp(param, str) == 0 ){ return true; } | |
284 | + | |
285 | + return false; | |
286 | +} | |
287 | + | |
269 | 288 | //! @brief 角度(ラジアン)正規化 |
270 | 289 | //! @param r 角度 |
271 | 290 | //! @return 正規化後の角度 |
@@ -157,6 +157,7 @@ | ||
157 | 157 | extern class StateMachine GameState; |
158 | 158 | extern class Config GameConfig; |
159 | 159 | |
160 | +bool CheckCommandParameter(const char *param, const char *cmd); | |
160 | 161 | float AngleNormalization(float r); |
161 | 162 | |
162 | 163 | #endif |
\ No newline at end of file |