~armagetronad-ap/armagetronad/BattleMania

« back to all changes in this revision

Viewing changes to src/engine/player.php

  • Committer: zodiacsohma1 at gmail
  • Date: 2014-03-02 08:09:55 UTC
  • Revision ID: zodiacsohma1@gmail.com-20140302080955-r5ot6eipfe0nlpww
Simplified all fields and code in all areas for better as they seem to repeat themselves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
    function ClearObject()
50
50
    {
51
 
        if (isset($this->cycle) && !is_null($this->cycle) && ($this->cycle instanceof Cycle))
 
51
        if (isset($this->cycle) && ($this->cycle instanceof Cycle))
52
52
        {
53
53
            $this->cycle->RemoveFromGrid();
54
54
        }
58
58
 
59
59
    function RemoveFromGame()
60
60
    {
61
 
        if (isset($this->cycle) && !is_null($this->cycle) && $this->cycle instanceof Cycle)
 
61
        if ((count(Base::$base->PLAYERS) > 0) && (is_array(Base::$base->PLAYERS)))
62
62
        {
63
 
            if ($this->cycle->alive)
 
63
            foreach (Base::$base->PLAYERS as $key => $p)
64
64
            {
65
 
                if ($this->human)
66
 
                    Base::$base->humans_alive--;
67
 
                else
68
 
                    Base::$base->ai_alive--;
 
65
                if (isset($p) && $p instanceof Player && ($p == $this))
 
66
                {
 
67
                    unset(Base::$base->PLAYERS[$key]);
 
68
                    break;
 
69
                }
69
70
            }
70
 
 
71
 
            $this->ClearObject();
72
71
        }
73
72
 
 
73
        $this->ClearObject();
 
74
 
74
75
        $team = $this->team;
75
 
        if (isset($this->team) && !is_null($this->team) && $this->team instanceof Team)
 
76
        if (isset($this->team) && $this->team instanceof Team)
76
77
            $this->team->removePlayer($this);
77
78
 
78
 
        if ((Base::$base->humans > 1) && !Base::$base->roundFinished && (Base::$base->game_mode == 3) && isset($this->ktk_tp) && !is_null($this->ktk_tp) && $this->ktk_tp instanceof KillTheKing)
 
79
        if (
 
80
            (Base::$base->humans > 1) && !Base::$base->roundFinished && (Base::$base->game_mode == 3) &&
 
81
            isset($this->ktk_tp) && $this->ktk_tp instanceof KillTheKing)
79
82
        {
80
83
            if ($this->ktk_tp->type == 3) //  check if this person is the king
81
84
            {
82
85
                //  reassign that team to give players new types
83
 
                if (isset($team) && !is_null($team) && $team instanceof Team)
 
86
                if (isset($team) && $team instanceof Team)
84
87
                {
85
88
                    if (!$team->ktk_tp->Assign())
86
89
                    {
101
104
    {
102
105
        foreach (Base::$base->PLAYERS as $p)
103
106
        {
104
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
107
            if (isset($p) && $p instanceof Player)
105
108
            {
106
109
                if ($p->log == $log)
107
110
                    return $p;
118
121
    {
119
122
        foreach (Base::$base->PLAYERS as $p)
120
123
        {
121
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
124
            if (isset($p) && $p instanceof Player)
122
125
            {
123
126
                if ($p->log == $log)
124
127
                    return true;
135
138
    {
136
139
        foreach (Base::$base->PLAYERS as $p)
137
140
        {
138
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
141
            if (isset($p) && $p instanceof Player)
139
142
            {
140
143
                if ($p->name == $name)
141
144
                    return true;
152
155
    {
153
156
        foreach (Base::$base->PLAYERS as $p)
154
157
        {
155
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
158
            if (isset($p) && $p instanceof Player)
156
159
            {
157
160
                if ($p->name == $name)
158
161
                    return $p;
173
176
    {
174
177
        foreach (Base::$base->PLAYERS as $p)
175
178
        {
176
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
179
            if (isset($p) && $p instanceof Player)
177
180
            {
178
181
                if (Filter($p->name) == $name)
179
182
                {
203
206
    {
204
207
        foreach (Base::$base->PLAYERS as $p)
205
208
        {
206
 
            if (isset($p) && !is_null($p) && $p instanceof Player)
 
209
            if (isset($p) && $p instanceof Player)
207
210
            {
208
211
                if (Filter($p->log) == $name)
209
212
                {
263
266
    else
264
267
    {
265
268
        $player = getPlayerByLog(Base::$base->pieces[1]);
266
 
        if (isset($player) && !is_null($player) && $player instanceof Player)
 
269
        if (isset($player) && $player instanceof Player)
267
270
        {
268
271
            $player = new Player(Base::$base->pieces[1], $display_name);
269
272
        }
270
273
    }
271
274
 
272
 
    if (isset($player) && !is_null($player) && $player instanceof Player)
 
275
    if (isset($player) && $player instanceof Player)
273
276
    {
274
277
        //! Debugging
275
278
        debugExecute("0x88ff22Added Player... 0x00ffff".$player);
297
300
    else
298
301
    {
299
302
        $player = getPlayerByLog(Base::$base->pieces[1]);
300
 
        if (isset($player) && !is_null($player) && $player instanceof Player)
 
303
        if (isset($player) && $player instanceof Player)
301
304
        {
302
305
            $player = new Player(Base::$base->pieces[1], $display_name);
303
306
        }
304
307
    }
305
308
 
306
 
    if (isset($player) && !is_null($player) && $player instanceof Player)
 
309
    if (isset($player) && $player instanceof Player)
307
310
    {
308
311
        debugExecute("0x88ff22Added AI Player... 0x00ffff".$player);
309
312
        $player->human = false;
318
321
    if (checkPlayerExistsByLog(Base::$base->pieces[1]))
319
322
    {
320
323
        $player = getPlayerByLog(Base::$base->pieces[1]);
321
 
        if (isset($player) && !is_null($player) && $player instanceof Player)
 
324
        if (isset($player) && $player instanceof Player)
322
325
        {
323
326
            $player->log = Base::$base->pieces[2];
324
327
            $player->name = BridgePieces(5, " ");
349
352
    *  Since +ap supports multiple colors in names, this is necessary for it to work.
350
353
    */
351
354
    $player = getPlayerByLog(Base::$base->pieces[1]);
352
 
    if (isset($player) && !is_null($player) && $player instanceof Player)
 
355
    if (isset($player) && $player instanceof Player)
353
356
        $player->cname = BridgePieces(2, " ");
354
357
}
355
358
 
358
361
{
359
362
 
360
363
    $player = getPlayerByLog(Base::$base->pieces[1]);
361
 
    if (isset($player) && !is_null($player) && $player instanceof Player)
 
364
    if (isset($player) && $player instanceof Player)
362
365
    {
363
366
        $player->owner_id = Base::$base->pieces[2];
364
367
        $player->color    = new Color(floatval(Base::$base->pieces[3]), floatval(Base::$base->pieces[4]), floatval(Base::$base->pieces[5]));
369
372
function PlayerLeft()
370
373
{
371
374
    $player = getPlayerByLog(Base::$base->pieces[1]);
372
 
    if (isset($player) && !is_null($player) && $player instanceof Player)
 
375
    if (isset($player) && $player instanceof Player)
373
376
    {
374
377
        if ($player->human)
375
378
            Base::$base->humans--;
380
383
            Base::$base->roundFinished = true;
381
384
 
382
385
        debugExecute("0xff9922Removed ".($player->human ? "" : "AI ")."Player... 0x00ffff".$player);
383
 
        removePlayer($player);
384
 
    }
385
 
}
386
 
 
387
 
//!< Removing a player
388
 
function removePlayer(Player $player)
389
 
{
390
 
    if ((count(Base::$base->PLAYERS) > 0) && (is_array(Base::$base->PLAYERS)))
391
 
    {
392
 
        foreach (Base::$base->PLAYERS as $key => $p)
393
 
        {
394
 
            if (isset($p) && !is_null($p) && $p instanceof Player && ($p == $player))
395
 
            {
396
 
                $player->RemoveFromGame();
397
 
                unset(Base::$base->PLAYERS[$key]);
398
 
                break;
399
 
            }
400
 
        }
 
386
        $player->RemoveFromGame();
401
387
    }
402
388
}
 
 
b'\\ No newline at end of file'