- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/World/Tiger.cs

Go to the documentation of this file.

    00001 //BSD License
    00002 //DXGfx® - http://www.eteractions.com
    00003 //Copyright (c) 2005
    00004 //by Guillaume Randon
    00005 //Permission is hereby granted, free of charge, to any person obtaining a copy of this software
    00006 //and associated documentation files (the "Software"), to deal in the Software without restriction,
    00007 //including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00008 //and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
    00009 //subject to the following conditions:
    00010 //The above copyright notice and this permission notice shall be included in all copies or substantial
    00011 //portions of the Software.
    00012 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
    00013 //INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
    00014 //AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00015 //DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00016 //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00017 using System;
    00018 using System.Collections.Generic;
    00019 using System.Text;
    00020 using Microsoft.DirectX;
    00021
    00022 namespace Game
    00023 {
    00024     // States
    00025     public enum State {Explore, Fuit, Dort, Mange, Bois};
    00026
    00027     public class Tiger : Animal
    00028     {
    00029         // Sensors
    00030         public bool Faim = false;
    00031         public double lastEat = 0;
    00032         public double angryEvery = 30;
    00033         public double fullLunch = 10;
    00034
    00035         public bool Soif = false;
    00036         public double lastDrink = 0;
    00037         public double drinkEvery = 20;
    00038         public double fullDrink = 5;
    00039
    00040         public bool ProxNourriture = false;
    00041         public Vector3 Nourriture;
    00042         public bool ProxEau = false;
    00043         public Vector3 Eau;
    00044
    00045         public bool Sommeil = false;
    00046         public double lastSleep = 0;
    00047         public double sleepEvery = 50;
    00048         public double fullSleep = 20;
    00049
    00050
    00051         public bool Bruit = false;
    00052
    00053         public State currentState = State.Explore;
    00054         public double stateTime = 0;
    00055         public bool stateJustChanged = false;
    00056
    00057         public Random rand;
    00058
    00059         public Tiger()
    00060         {
    00061             speed = 1.0f;
    00062             selectString = "Ceci est un tigre!! Grrrr";
    00063             rand = new Random();
    00064         }
    00065
    00066         public override void UpdateIA(float elapsedTime, double absTime)
    00067         {
    00068             //UpdateSensors( elapsedTime, absTime);
    00069             //if (IAKnowledgeChanged)
    00070             //{
    00071             //    base.UpdateIA(elapsedTime, absTime);
    00072             //    IAKnowledgeChanged = false;
    00073             //}
    00074             //PerformStateActions( elapsedTime,  absTime);
    00075         }
    00076
    00077         public void UpdateSensors(float elapsedTime, double absTime)
    00078         {
    00079             lastDrink += elapsedTime;
    00080
    00081             if (lastDrink > drinkEvery)
    00082             {
    00083                 Soif = true;
    00084                 IAKnowledgeChanged = true;
    00085             }
    00086
    00087             lastEat += elapsedTime;
    00088
    00089             if (lastEat > angryEvery)
    00090             {
    00091                 Faim = true;
    00092                 IAKnowledgeChanged = true;
    00093             }
    00094
    00095             lastSleep += elapsedTime;
    00096
    00097             if (lastSleep > sleepEvery)
    00098             {
    00099                 Sommeil = true;
    00100                 IAKnowledgeChanged = true;
    00101             }
    00102         }
    00103
    00104         public void PerformStateActions(float elapsedTime, double absTime)
    00105         {
    00106             switch (currentState)
    00107             {
    00108                 case State.Bois:
    00109                     Bois(elapsedTime, absTime);
    00110                     break;
    00111                 case State.Dort:
    00112                     Dort(elapsedTime, absTime);
    00113                     break;
    00114                 case State.Explore:
    00115                     Explore(elapsedTime, absTime);
    00116                     break;
    00117                 case State.Fuit:
    00118                     Fuit(elapsedTime, absTime);
    00119                     break;
    00120                 case State.Mange:
    00121                     Mange(elapsedTime, absTime);
    00122                     break;
    00123                 default:
    00124                     break;
    00125             }
    00126         }
    00127
    00128         public void Bois(float elapsedTime, double absTime)
    00129         {
    00130             if (stateJustChanged)
    00131             {
    00132                 Moving move = new Moving(this);
    00133                 move.destination = new WorldLocation(Eau);
    00134                 CurrentAction = move;
    00135                 stateJustChanged = false;
    00136             }
    00137             else
    00138             {
    00139                 stateTime += elapsedTime;
    00140             }
    00141             if (stateTime > fullDrink)
    00142             {
    00143                 Soif = false;
    00144                 IAKnowledgeChanged = true;
    00145                 currentState = State.Explore;
    00146                 lastDrink = 0;
    00147             }
    00148         }
    00149
    00150         public void Dort(float elapsedTime, double absTime)
    00151         {
    00152             if (stateJustChanged)
    00153             {
    00154                 CurrentAction = new Action();
    00155                 stateJustChanged = false;
    00156             }
    00157             else
    00158             {
    00159                 stateTime += elapsedTime;
    00160             }
    00161             if (stateTime > fullSleep)
    00162             {
    00163                 Sommeil = false;
    00164                 IAKnowledgeChanged = true;
    00165                 currentState = State.Explore;
    00166                 lastSleep = 0;
    00167             }
    00168         }
    00169
    00170         public void Explore(float elapsedTime, double absTime)
    00171         {
    00172             if (stateJustChanged)
    00173             {
    00174                 Moving move = new Moving(this);
    00175                 move.destination = new WorldLocation(sceneObj.Position + new Vector3(rand.Next(5, 20), 0.0f, rand.Next(5, 20)));
    00176                 CurrentAction = move;
    00177                 stateJustChanged = false;
    00178             }
    00179             else
    00180             {
    00181                 stateTime += elapsedTime;
    00182             }
    00183             if (stateTime > 30000)
    00184             {
    00185                 Moving move = new Moving(this);
    00186                 move.destination = new WorldLocation(sceneObj.Position + new Vector3(rand.Next(5, 20), 0.0f, rand.Next(5, 20)));
    00187                 stateTime = 0;
    00188             }
    00189         }
    00190
    00191         public void Fuit(float elapsedTime, double absTime)
    00192         {
    00193             if (stateJustChanged)
    00194             {
    00195                 Moving move = new Moving(this);
    00196                 move.destination = new WorldLocation(sceneObj.Position + new Vector3(0.0f, 0.0f, 100.0f));
    00197                 CurrentAction = move;
    00198                 stateJustChanged = false;
    00199             }
    00200             else
    00201             {
    00202                 stateTime += elapsedTime;
    00203             }
    00204         }
    00205
    00206         public void Mange(float elapsedTime, double absTime)
    00207         {
    00208             if (stateJustChanged)
    00209             {
    00210                 Moving move = new Moving(this);
    00211                 move.destination = new WorldLocation(Nourriture);
    00212                 CurrentAction = move;
    00213                 stateJustChanged = false;
    00214             }
    00215             else
    00216             {
    00217                 stateTime += elapsedTime;
    00218             }
    00219             if (stateTime > fullLunch)
    00220             {
    00221                 Faim = false;
    00222                 IAKnowledgeChanged = true;
    00223                 lastEat = 0;
    00224                 currentState = State.Explore;
    00225             }
    00226         }
    00227     }
    00228 }