~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to gnobots2/game.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
/* Exported Variables                                                 */
47
47
/**********************************************************************/
48
48
gint game_state = STATE_PLAYING;
 
49
gint arena[GAME_WIDTH][GAME_HEIGHT];
49
50
/**********************************************************************/
50
51
 
51
52
 
60
61
static gint kills = 0;
61
62
static gint score_step = 0;
62
63
static gint safe_teleports = 0;
63
 
static gboolean display_updated = 0;
64
64
static gint player_xpos = 0;
65
65
static gint player_ypos = 0;
66
66
static gint push_xpos = -1;
67
67
static gint push_ypos = -1;
68
68
static gint game_timer_id = -1;
69
 
static gint arena[GAME_WIDTH][GAME_HEIGHT];
70
 
static gint old_arena[GAME_WIDTH][GAME_HEIGHT];
71
69
static gint temp_arena[GAME_WIDTH][GAME_HEIGHT];
72
70
/**********************************************************************/
73
71
 
81
79
static void clear_arena (void);
82
80
static gint check_location (gint x, gint y);
83
81
static void generate_level (void);
84
 
static void draw_graphics (void);
85
82
static void update_arena (void);
86
83
static gint timeout_cb (void *data);
87
84
static void destroy_game_timer (void);
117
114
  GtkWidget *box;
118
115
 
119
116
  box = gtk_message_dialog_new (GTK_WINDOW (app), GTK_DIALOG_MODAL,
120
 
                                GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg);
 
117
                                GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg);
121
118
  gtk_dialog_run (GTK_DIALOG (box));
122
119
  gtk_widget_destroy (box);
123
120
}
145
142
      gtk_window_present (GTK_WINDOW (sorrydialog));
146
143
    } else {
147
144
      sorrydialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (app),
148
 
                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
149
 
                                                        GTK_MESSAGE_INFO,
150
 
                                                        GTK_BUTTONS_NONE,
151
 
                                                        "<b>%s</b>\n%s",
152
 
                                                        _
153
 
                                                        ("Game over!"),
154
 
                                                        _
155
 
                                                        ("Great work, but unfortunately your score did not make the top ten."));
 
145
                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
 
146
                                                        GTK_MESSAGE_INFO,
 
147
                                                        GTK_BUTTONS_NONE,
 
148
                                                        "<b>%s</b>\n%s",
 
149
                                                        _
 
150
                                                        ("Game over!"),
 
151
                                                        _
 
152
                                                        ("Great work, but unfortunately your score did not make the top ten."));
156
153
      gtk_dialog_add_buttons (GTK_DIALOG (sorrydialog), GTK_STOCK_QUIT,
157
 
                              GTK_RESPONSE_REJECT, _("_New Game"),
158
 
                              GTK_RESPONSE_ACCEPT, NULL);
 
154
                              GTK_RESPONSE_REJECT, _("_New Game"),
 
155
                              GTK_RESPONSE_ACCEPT, NULL);
159
156
      gtk_dialog_set_default_response (GTK_DIALOG (sorrydialog),
160
 
                                       GTK_RESPONSE_ACCEPT);
 
157
                                       GTK_RESPONSE_ACCEPT);
161
158
      gtk_window_set_title (GTK_WINDOW (sorrydialog), "");
162
159
    }
163
160
    dialog = sorrydialog;
167
164
      gtk_window_present (GTK_WINDOW (scoresdialog));
168
165
    } else {
169
166
      scoresdialog = games_scores_dialog_new (GTK_WINDOW (app), 
170
 
                                        highscores, _("Robots Scores"));
 
167
                                        highscores, _("Robots Scores"));
171
168
      games_scores_dialog_set_category_description (GAMES_SCORES_DIALOG
172
 
                                                    (scoresdialog),
173
 
                                                    _("Map:"));
 
169
                                                    (scoresdialog),
 
170
                                                    _("Map:"));
174
171
    }
175
172
 
176
173
    if (pos > 0) {
177
174
      play_sound (SOUND_VICTORY);
178
175
 
179
176
      games_scores_dialog_set_hilight (GAMES_SCORES_DIALOG (scoresdialog),
180
 
                                       pos);
 
177
                                       pos);
181
178
      message = g_strdup_printf ("<b>%s</b>\n\n%s",
182
 
                                 _("Congratulations!"),
 
179
                                 _("Congratulations!"),
183
180
                                 pos == 1 ? _("Your score is the best!") :
184
 
                                 _("Your score has made the top ten."));
 
181
                                 _("Your score has made the top ten."));
185
182
      games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
186
 
                                       message);
 
183
                                       message);
187
184
      g_free (message);
188
185
    } else {
189
186
      games_scores_dialog_set_message (GAMES_SCORES_DIALOG (scoresdialog),
190
 
                                       NULL);
 
187
                                       NULL);
191
188
    }
192
189
 
193
190
    if (endofgame) {
194
191
      games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog),
195
 
                                       GAMES_SCORES_QUIT_BUTTON |
196
 
                                       GAMES_SCORES_NEW_GAME_BUTTON);
 
192
                                       GAMES_SCORES_QUIT_BUTTON |
 
193
                                       GAMES_SCORES_NEW_GAME_BUTTON);
197
194
    } else {
198
195
      games_scores_dialog_set_buttons (GAMES_SCORES_DIALOG (scoresdialog), 0);
199
196
    }
221
218
{
222
219
  guint pos = 0;
223
220
  gchar *sbuf = NULL;
224
 
  GamesScoreValue score;
225
221
 
226
222
  if (properties_super_safe_moves ()) {
227
223
    sbuf =
228
224
      g_strdup_printf ("%s-super-safe",
229
 
                       game_config_filename (current_game_config ()));
 
225
                       game_config_filename (current_game_config ()));
230
226
  } else if (properties_safe_moves ()) {
231
227
    sbuf =
232
228
      g_strdup_printf ("%s-safe",
233
 
                       game_config_filename (current_game_config ()));
 
229
                       game_config_filename (current_game_config ()));
234
230
  } else {
235
231
    sbuf =
236
232
      g_strdup_printf ("%s", game_config_filename (current_game_config ()));
237
233
  }
238
234
 
239
235
  if (sc != 0) {
240
 
    score.plain = (guint32) sc;
241
236
    games_scores_set_category (highscores, sbuf);
242
 
    pos = games_scores_add_score (highscores, score);
 
237
    pos = games_scores_add_plain_score (highscores, (guint32) sc);
243
238
  }
244
239
  g_free (sbuf);
245
240
 
314
309
  }
315
310
 
316
311
  gnobots_statusbar_set (score, current_level + 1, safe_teleports,
317
 
                         num_robots1, num_robots2);
 
312
                         num_robots1, num_robots2);
318
313
}
319
314
 
320
315
 
332
327
  for (i = 0; i < GAME_WIDTH; ++i) {
333
328
    for (j = 0; j < GAME_HEIGHT; ++j) {
334
329
      arena[i][j] = OBJECT_NONE;
335
 
      old_arena[i][j] = OBJECT_FOO;
336
330
    }
337
331
  }
338
332
 
355
349
  for (i = 0; i < GAME_WIDTH; ++i) {
356
350
    for (j = 0; j < GAME_HEIGHT; ++j) {
357
351
      if (arena[i][j] != OBJECT_PLAYER) {
358
 
        temp_arena[i][j] = arena[i][j];
 
352
        temp_arena[i][j] = arena[i][j];
359
353
      } else {
360
 
        temp_arena[i][j] = OBJECT_NONE;
 
354
        temp_arena[i][j] = OBJECT_NONE;
361
355
      }
362
356
    }
363
357
  }
412
406
    current_level = 0;
413
407
    num_robots1 = game_config ()->initial_type1;
414
408
    message_box (_
415
 
                 ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
 
409
                 ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
416
410
    play_sound (SOUND_VICTORY);
417
411
  }
418
412
 
428
422
    num_robots1 = game_config ()->initial_type1;
429
423
    num_robots2 = game_config ()->initial_type2;
430
424
    message_box (_
431
 
                 ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
 
425
                 ("Congratulations, You Have Defeated the Robots!! \nBut Can You do it Again?"));
432
426
    play_sound (SOUND_VICTORY);
433
427
  }
434
428
 
444
438
      yp = rand () % GAME_HEIGHT;
445
439
 
446
440
      if (check_location (xp, yp) == OBJECT_NONE) {
447
 
        arena[xp][yp] = OBJECT_ROBOT1;
448
 
        break;
 
441
        arena[xp][yp] = OBJECT_ROBOT1;
 
442
        break;
449
443
      }
450
444
    }
451
445
  }
457
451
      yp = rand () % GAME_HEIGHT;
458
452
 
459
453
      if (check_location (xp, yp) == OBJECT_NONE) {
460
 
        arena[xp][yp] = OBJECT_ROBOT2;
461
 
        break;
462
 
      }
463
 
    }
464
 
  }
465
 
 
466
 
}
467
 
 
468
 
/**
469
 
 * draw_graphics
470
 
 *
471
 
 * Description:
472
 
 * Draws all of the game objects
473
 
 **/
474
 
static void
475
 
draw_graphics (void)
476
 
{
477
 
  gint i, j;
478
 
 
479
 
  for (i = 0; i < GAME_WIDTH; ++i) {
480
 
    for (j = 0; j < GAME_HEIGHT; ++j) {
481
 
      if (arena[i][j] == OBJECT_NONE) {
482
 
        if (arena[i][j] != old_arena[i][j]) {
483
 
          draw_object (i, j, arena[i][j]);
484
 
        }
485
 
      } else {
486
 
        draw_object (i, j, arena[i][j]);
487
 
      }
488
 
 
489
 
      old_arena[i][j] = arena[i][j];
490
 
    }
491
 
  }
492
 
 
493
 
  draw_bubble ();
494
 
 
495
 
  display_updated = TRUE;
496
 
}
497
 
 
 
454
        arena[xp][yp] = OBJECT_ROBOT2;
 
455
        break;
 
456
      }
 
457
    }
 
458
  }
 
459
 
 
460
}
498
461
 
499
462
/**
500
463
 * update_arena
515
478
 
516
479
 
517
480
      if ((temp_arena[i][j] == OBJECT_HEAP) &&
518
 
          (push_xpos == i) && (push_ypos == j)) {
519
 
        if (arena[i][j] == OBJECT_ROBOT1) {
520
 
          add_splat_bubble (i, j);
521
 
          play_sound (SOUND_SPLAT);
522
 
          push_xpos = push_ypos = -1;
523
 
          score += game_config ()->score_type1_splatted;
524
 
        }
525
 
        if (arena[i][j] == OBJECT_ROBOT2) {
526
 
          add_splat_bubble (i, j);
527
 
          play_sound (SOUND_SPLAT);
528
 
          push_xpos = push_ypos = -1;
529
 
          score += game_config ()->score_type2_splatted;
530
 
        }
 
481
          (push_xpos == i) && (push_ypos == j)) {
 
482
        if (arena[i][j] == OBJECT_ROBOT1) {
 
483
          add_splat_bubble (i, j);
 
484
          play_sound (SOUND_SPLAT);
 
485
          push_xpos = push_ypos = -1;
 
486
          score += game_config ()->score_type1_splatted;
 
487
        }
 
488
        if (arena[i][j] == OBJECT_ROBOT2) {
 
489
          add_splat_bubble (i, j);
 
490
          play_sound (SOUND_SPLAT);
 
491
          push_xpos = push_ypos = -1;
 
492
          score += game_config ()->score_type2_splatted;
 
493
        }
531
494
      }
532
495
 
533
496
 
534
497
      arena[i][j] = temp_arena[i][j];
535
498
      if (arena[i][j] == OBJECT_ROBOT1) {
536
 
        num_robots1 += 1;
 
499
        num_robots1 += 1;
537
500
      } else if (arena[i][j] == OBJECT_ROBOT2) {
538
 
        num_robots2 += 1;
 
501
        num_robots2 += 1;
539
502
      }
540
503
    }
541
504
  }
556
519
    }
557
520
  }
558
521
 
559
 
  display_updated = FALSE;
560
 
 
561
522
  gnobots_statusbar_set (score, current_level + 1, safe_teleports,
562
 
                         num_robots1, num_robots2);
 
523
                         num_robots1, num_robots2);
563
524
 
564
525
}
565
526
 
578
539
 
579
540
  animate_game_graphics ();
580
541
 
581
 
  draw_graphics ();
 
542
  clear_game_area ();
582
543
 
583
544
  if ((game_state == STATE_TYPE2) || (game_state == STATE_WTYPE2)) {
584
 
    if (display_updated) {
585
 
      move_type2_robots ();
586
 
      update_arena ();
587
 
      if (game_state == STATE_TYPE2) {
588
 
        game_state = STATE_PLAYING;
589
 
      } else if (game_state == STATE_WTYPE2) {
590
 
        game_state = STATE_WAITING;
591
 
      }
 
545
    move_type2_robots ();
 
546
    update_arena ();
 
547
    if (game_state == STATE_TYPE2) {
 
548
      game_state = STATE_PLAYING;
 
549
    } else if (game_state == STATE_WTYPE2) {
 
550
      game_state = STATE_WAITING;
592
551
    }
593
552
  } else if (game_state == STATE_WAITING) {
594
 
    if (display_updated) {
595
 
      remove_splat_bubble ();
596
 
      move_robots ();
597
 
    }
 
553
    remove_splat_bubble ();
 
554
    move_robots ();
598
555
  } else if (game_state == STATE_COMPLETE) {
599
556
    ++endlev_counter;
600
557
    if (endlev_counter >= CHANGE_DELAY) {
606
563
      game_state = STATE_PLAYING;
607
564
      set_move_menu_sensitivity (TRUE);
608
565
      gnobots_statusbar_set (score, current_level + 1, safe_teleports,
609
 
                             num_robots1, num_robots2);
 
566
                             num_robots1, num_robots2);
610
567
    }
611
568
  } else if (game_state == STATE_DEAD) {
612
569
    ++endlev_counter;
613
570
    if (endlev_counter >= DEAD_DELAY) {
614
571
      if (score > 0) {
615
 
        sp = log_score (score);
 
572
        sp = log_score (score);
616
573
        if (show_scores (sp, TRUE) == GTK_RESPONSE_REJECT) {
617
574
          quit_game ();
618
575
        }
669
626
{
670
627
  create_game_timer ();
671
628
 
672
 
  g_signal_connect (GTK_OBJECT (app), "key_press_event",
673
 
                    G_CALLBACK (keyboard_cb), 0);
 
629
  g_signal_connect (GTK_WIDGET (app), "key_press_event",
 
630
                    G_CALLBACK (keyboard_cb), 0);
674
631
 
675
632
  start_new_game ();
676
633
}
727
684
  game_state = STATE_PLAYING;
728
685
 
729
686
  gnobots_statusbar_set (score, current_level + 1, safe_teleports,
730
 
                         num_robots1, num_robots2);
 
687
                         num_robots1, num_robots2);
731
688
  set_move_menu_sensitivity (TRUE);
732
689
}
733
690
 
747
704
  for (i = 0; i < GAME_WIDTH; ++i) {
748
705
    for (j = 0; j < GAME_HEIGHT; ++j) {
749
706
      if ((arena[i][j] == OBJECT_PLAYER) || (arena[i][j] == OBJECT_HEAP)) {
750
 
        temp_arena[i][j] = arena[i][j];
 
707
        temp_arena[i][j] = arena[i][j];
751
708
      } else {
752
 
        temp_arena[i][j] = OBJECT_NONE;
 
709
        temp_arena[i][j] = OBJECT_NONE;
753
710
      }
754
711
    }
755
712
  }
757
714
  for (i = 0; i < GAME_WIDTH; ++i) {
758
715
    for (j = 0; j < GAME_HEIGHT; ++j) {
759
716
      if ((arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_ROBOT2)) {
760
 
        nx = i;
761
 
        ny = j;
762
 
        if (player_xpos < nx)
763
 
          nx -= 1;
764
 
        if (player_xpos > nx)
765
 
          nx += 1;
766
 
        if (player_ypos < ny)
767
 
          ny -= 1;
768
 
        if (player_ypos > ny)
769
 
          ny += 1;
 
717
        nx = i;
 
718
        ny = j;
 
719
        if (player_xpos < nx)
 
720
          nx -= 1;
 
721
        if (player_xpos > nx)
 
722
          nx += 1;
 
723
        if (player_ypos < ny)
 
724
          ny -= 1;
 
725
        if (player_ypos > ny)
 
726
          ny += 1;
770
727
 
771
 
        if (temp_arena[nx][ny] == OBJECT_HEAP) {
772
 
          add_kill (arena[i][j]);
773
 
        } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
774
 
                   (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
775
 
          add_kill (arena[i][j]);
776
 
          add_kill (temp_arena[nx][ny]);
777
 
          temp_arena[nx][ny] = OBJECT_HEAP;
778
 
        } else {
779
 
          temp_arena[nx][ny] = arena[i][j];
780
 
        }
 
728
        if (temp_arena[nx][ny] == OBJECT_HEAP) {
 
729
          add_kill (arena[i][j]);
 
730
        } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
 
731
                   (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
 
732
          add_kill (arena[i][j]);
 
733
          add_kill (temp_arena[nx][ny]);
 
734
          temp_arena[nx][ny] = OBJECT_HEAP;
 
735
        } else {
 
736
          temp_arena[nx][ny] = arena[i][j];
 
737
        }
781
738
      }
782
739
    }
783
740
  }
800
757
  for (i = 0; i < GAME_WIDTH; ++i) {
801
758
    for (j = 0; j < GAME_HEIGHT; ++j) {
802
759
      if ((arena[i][j] == OBJECT_PLAYER) ||
803
 
          (arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_HEAP)) {
804
 
        temp_arena[i][j] = arena[i][j];
 
760
          (arena[i][j] == OBJECT_ROBOT1) || (arena[i][j] == OBJECT_HEAP)) {
 
761
        temp_arena[i][j] = arena[i][j];
805
762
      } else {
806
 
        temp_arena[i][j] = OBJECT_NONE;
 
763
        temp_arena[i][j] = OBJECT_NONE;
807
764
      }
808
765
    }
809
766
  }
811
768
  for (i = 0; i < GAME_WIDTH; ++i) {
812
769
    for (j = 0; j < GAME_HEIGHT; ++j) {
813
770
      if (arena[i][j] == OBJECT_ROBOT2) {
814
 
        nx = i;
815
 
        ny = j;
816
 
        if (player_xpos < nx)
817
 
          nx -= 1;
818
 
        if (player_xpos > nx)
819
 
          nx += 1;
820
 
        if (player_ypos < ny)
821
 
          ny -= 1;
822
 
        if (player_ypos > ny)
823
 
          ny += 1;
 
771
        nx = i;
 
772
        ny = j;
 
773
        if (player_xpos < nx)
 
774
          nx -= 1;
 
775
        if (player_xpos > nx)
 
776
          nx += 1;
 
777
        if (player_ypos < ny)
 
778
          ny -= 1;
 
779
        if (player_ypos > ny)
 
780
          ny += 1;
824
781
 
825
 
        if (temp_arena[nx][ny] == OBJECT_HEAP) {
826
 
          add_kill (arena[i][j]);
827
 
        } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
828
 
                   (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
829
 
          add_kill (arena[i][j]);
830
 
          add_kill (temp_arena[nx][ny]);
831
 
          temp_arena[nx][ny] = OBJECT_HEAP;
832
 
        } else {
833
 
          temp_arena[nx][ny] = arena[i][j];
834
 
        }
 
782
        if (temp_arena[nx][ny] == OBJECT_HEAP) {
 
783
          add_kill (arena[i][j]);
 
784
        } else if ((temp_arena[nx][ny] == OBJECT_ROBOT1) ||
 
785
                   (temp_arena[nx][ny] == OBJECT_ROBOT2)) {
 
786
          add_kill (arena[i][j]);
 
787
          add_kill (temp_arena[nx][ny]);
 
788
          temp_arena[nx][ny] = OBJECT_HEAP;
 
789
        } else {
 
790
          temp_arena[nx][ny] = arena[i][j];
 
791
        }
835
792
      }
836
793
    }
837
794
  }
887
844
  for (i = 0; i < GAME_WIDTH; ++i) {
888
845
    for (j = 0; j < GAME_HEIGHT; ++j) {
889
846
      if ((temp_arena[i][j] == OBJECT_PLAYER) ||
890
 
          (temp_arena[i][j] == OBJECT_HEAP)) {
891
 
        temp2_arena[i][j] = temp_arena[i][j];
 
847
          (temp_arena[i][j] == OBJECT_HEAP)) {
 
848
        temp2_arena[i][j] = temp_arena[i][j];
892
849
      } else {
893
 
        temp2_arena[i][j] = OBJECT_NONE;
 
850
        temp2_arena[i][j] = OBJECT_NONE;
894
851
      }
895
852
    }
896
853
  }
898
855
  for (i = 0; i < GAME_WIDTH; ++i) {
899
856
    for (j = 0; j < GAME_HEIGHT; ++j) {
900
857
      if ((temp_arena[i][j] == OBJECT_ROBOT1) ||
901
 
          (temp_arena[i][j] == OBJECT_ROBOT2)) {
902
 
        nx = i;
903
 
        ny = j;
904
 
        if (x < nx)
905
 
          nx -= 1;
906
 
        if (x > nx)
907
 
          nx += 1;
908
 
        if (y < ny)
909
 
          ny -= 1;
910
 
        if (y > ny)
911
 
          ny += 1;
 
858
          (temp_arena[i][j] == OBJECT_ROBOT2)) {
 
859
        nx = i;
 
860
        ny = j;
 
861
        if (x < nx)
 
862
          nx -= 1;
 
863
        if (x > nx)
 
864
          nx += 1;
 
865
        if (y < ny)
 
866
          ny -= 1;
 
867
        if (y > ny)
 
868
          ny += 1;
912
869
 
913
 
        if ((temp2_arena[nx][ny] == OBJECT_ROBOT1) ||
914
 
            (temp2_arena[nx][ny] == OBJECT_ROBOT2) ||
915
 
            (temp2_arena[nx][ny] == OBJECT_HEAP)) {
916
 
          temp2_arena[nx][ny] = OBJECT_HEAP;
917
 
        } else {
918
 
          temp2_arena[nx][ny] = temp_arena[i][j];
919
 
        }
 
870
        if ((temp2_arena[nx][ny] == OBJECT_ROBOT1) ||
 
871
            (temp2_arena[nx][ny] == OBJECT_ROBOT2) ||
 
872
            (temp2_arena[nx][ny] == OBJECT_HEAP)) {
 
873
          temp2_arena[nx][ny] = OBJECT_HEAP;
 
874
        } else {
 
875
          temp2_arena[nx][ny] = temp_arena[i][j];
 
876
        }
920
877
      }
921
878
    }
922
879
  }
927
884
  for (i = 0; i < GAME_WIDTH; ++i) {
928
885
    for (j = 0; j < GAME_HEIGHT; ++j) {
929
886
      if ((temp2_arena[i][j] == OBJECT_PLAYER) ||
930
 
          (temp2_arena[i][j] == OBJECT_HEAP)) {
931
 
        temp3_arena[i][j] = temp2_arena[i][j];
 
887
          (temp2_arena[i][j] == OBJECT_HEAP)) {
 
888
        temp3_arena[i][j] = temp2_arena[i][j];
932
889
      } else {
933
 
        temp3_arena[i][j] = OBJECT_NONE;
 
890
        temp3_arena[i][j] = OBJECT_NONE;
934
891
      }
935
892
    }
936
893
  }
938
895
  for (i = 0; i < GAME_WIDTH; ++i) {
939
896
    for (j = 0; j < GAME_HEIGHT; ++j) {
940
897
      if (temp2_arena[i][j] == OBJECT_ROBOT2) {
941
 
        nx = i;
942
 
        ny = j;
943
 
        if (x < nx)
944
 
          nx -= 1;
945
 
        if (x > nx)
946
 
          nx += 1;
947
 
        if (y < ny)
948
 
          ny -= 1;
949
 
        if (y > ny)
950
 
          ny += 1;
 
898
        nx = i;
 
899
        ny = j;
 
900
        if (x < nx)
 
901
          nx -= 1;
 
902
        if (x > nx)
 
903
          nx += 1;
 
904
        if (y < ny)
 
905
          ny -= 1;
 
906
        if (y > ny)
 
907
          ny += 1;
951
908
 
952
 
        if ((temp3_arena[nx][ny] == OBJECT_ROBOT1) ||
953
 
            (temp3_arena[nx][ny] == OBJECT_ROBOT2) ||
954
 
            (temp3_arena[nx][ny] == OBJECT_HEAP)) {
955
 
          temp3_arena[nx][ny] = OBJECT_HEAP;
956
 
        } else {
957
 
          temp3_arena[nx][ny] = temp2_arena[i][j];
958
 
        }
 
909
        if ((temp3_arena[nx][ny] == OBJECT_ROBOT1) ||
 
910
            (temp3_arena[nx][ny] == OBJECT_ROBOT2) ||
 
911
            (temp3_arena[nx][ny] == OBJECT_HEAP)) {
 
912
          temp3_arena[nx][ny] = OBJECT_HEAP;
 
913
        } else {
 
914
          temp3_arena[nx][ny] = temp2_arena[i][j];
 
915
        }
959
916
      }
960
917
    }
961
918
  }
1033
990
  if (temp_arena[nx][ny] == OBJECT_HEAP) {
1034
991
    if (game_config ()->moveable_heaps) {
1035
992
      if (!push_heap (nx, ny, dx, dy)) {
1036
 
        push_xpos = push_ypos = -1;
1037
 
        return FALSE;
 
993
        push_xpos = push_ypos = -1;
 
994
        return FALSE;
1038
995
      }
1039
996
    } else {
1040
997
      return FALSE;
1127
1084
  for (x = 0; x < GAME_WIDTH; x++) {
1128
1085
    for (y = 0; y < GAME_HEIGHT; y++) {
1129
1086
      if (check_safe (x, y))
1130
 
        return TRUE;
 
1087
        return TRUE;
1131
1088
    }
1132
1089
  }
1133
1090
 
1163
1120
      return FALSE;
1164
1121
    } else {
1165
1122
      if (!check_safe (nx, ny)) {
1166
 
        if (properties_super_safe_moves () || safe_move_available ()) {
1167
 
          play_sound (SOUND_BAD);
1168
 
          return FALSE;
1169
 
        }
 
1123
        if (properties_super_safe_moves () || safe_move_available ()) {
 
1124
          play_sound (SOUND_BAD);
 
1125
          return FALSE;
 
1126
        }
1170
1127
      }
1171
1128
    }
1172
1129
  } else {
1211
1168
  for (i = 0; i < GAME_WIDTH; ++i) {
1212
1169
    for (j = 0; j < GAME_HEIGHT; ++j) {
1213
1170
      if (arena[i][j] != OBJECT_PLAYER) {
1214
 
        temp_arena[i][j] = arena[i][j];
 
1171
        temp_arena[i][j] = arena[i][j];
1215
1172
      } else {
1216
 
        temp_arena[i][j] = OBJECT_NONE;
 
1173
        temp_arena[i][j] = OBJECT_NONE;
1217
1174
      }
1218
1175
    }
1219
1176
  }
1239
1196
      xp = 0;
1240
1197
      ++yp;
1241
1198
      if (yp >= GAME_HEIGHT) {
1242
 
        yp = 0;
 
1199
        yp = 0;
1243
1200
      }
1244
1201
    }
1245
1202
 
1284
1241
  for (i = 0; i < GAME_WIDTH; ++i) {
1285
1242
    for (j = 0; j < GAME_HEIGHT; ++j) {
1286
1243
      if (arena[i][j] != OBJECT_PLAYER) {
1287
 
        temp_arena[i][j] = arena[i][j];
 
1244
        temp_arena[i][j] = arena[i][j];
1288
1245
      } else {
1289
 
        temp_arena[i][j] = OBJECT_NONE;
 
1246
        temp_arena[i][j] = OBJECT_NONE;
1290
1247
      }
1291
1248
    }
1292
1249
  }
1314
1271
      xp = 0;
1315
1272
      ++yp;
1316
1273
      if (yp >= GAME_HEIGHT) {
1317
 
        yp = 0;
 
1274
        yp = 0;
1318
1275
      }
1319
1276
    }
1320
1277
  }
1336
1293
void
1337
1294
game_keypress (gint key)
1338
1295
{
1339
 
  if (!display_updated)
1340
 
    return;
1341
 
 
1342
1296
  if (game_state == STATE_PLAYING) {
1343
1297
    switch (key) {
1344
1298
    case KBD_NW:
1345
1299
      if (player_move (-1, -1)) {
1346
 
        move_robots ();
 
1300
        move_robots ();
1347
1301
      }
1348
1302
      break;
1349
1303
    case KBD_N:
1350
1304
      if (player_move (0, -1)) {
1351
 
        move_robots ();
 
1305
        move_robots ();
1352
1306
      }
1353
1307
      break;
1354
1308
    case KBD_NE:
1355
1309
      if (player_move (1, -1)) {
1356
 
        move_robots ();
 
1310
        move_robots ();
1357
1311
      }
1358
1312
      break;
1359
1313
    case KBD_W:
1360
1314
      if (player_move (-1, 0)) {
1361
 
        move_robots ();
 
1315
        move_robots ();
1362
1316
      }
1363
1317
      break;
1364
1318
    case KBD_STAY:
1365
1319
      if (player_move (0, 0)) {
1366
 
        move_robots ();
 
1320
        move_robots ();
1367
1321
      }
1368
1322
      break;
1369
1323
    case KBD_E:
1370
1324
      if (player_move (1, 0)) {
1371
 
        move_robots ();
 
1325
        move_robots ();
1372
1326
      }
1373
1327
      break;
1374
1328
    case KBD_SW:
1375
1329
      if (player_move (-1, 1)) {
1376
 
        move_robots ();
 
1330
        move_robots ();
1377
1331
      }
1378
1332
      break;
1379
1333
    case KBD_S:
1380
1334
      if (player_move (0, 1)) {
1381
 
        move_robots ();
 
1335
        move_robots ();
1382
1336
      }
1383
1337
      break;
1384
1338
    case KBD_SE:
1385
1339
      if (player_move (1, 1)) {
1386
 
        move_robots ();
 
1340
        move_robots ();
1387
1341
      }
1388
1342
      break;
1389
1343
    case KBD_TELE:
1390
1344
      if (safe_teleport ()) {
1391
 
        move_robots ();
 
1345
        move_robots ();
1392
1346
      }
1393
1347
      break;
1394
1348
    case KBD_RTEL:
1395
1349
      if (random_teleport ()) {
1396
 
        move_robots ();
 
1350
        move_robots ();
1397
1351
      }
1398
1352
      break;
1399
1353
    case KBD_WAIT: