[svn-commits] jrose: trunk r972 - /trunk/menuselect_curses.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Nov 10 16:12:05 CST 2011


Author: jrose
Date: Thu Nov 10 16:12:01 2011
New Revision: 972

URL: http://svnview.digium.com/svn/menuselect?view=rev&rev=972
Log:
Add barriers to the menuselect easteregg

This patch adds some familiar looking barriers to hide under to the 'i' easteregg 
from cmenuselect.

(closes issue ASTERISK-18802)
Reported by: J'Len Dowdy
Patches:
	barrierupdatemerged.patch uploaded by J'Len Dowdy (license #6316)


Modified:
    trunk/menuselect_curses.c

Modified: trunk/menuselect_curses.c
URL: http://svnview.digium.com/svn/menuselect/trunk/menuselect_curses.c?view=diff&rev=972&r1=971&r2=972
==============================================================================
--- trunk/menuselect_curses.c (original)
+++ trunk/menuselect_curses.c Thu Nov 10 16:12:01 2011
@@ -566,6 +566,7 @@
 	BLIP_SHOT,
 	BLIP_BOMB,
 	BLIP_ALIEN,
+	BLIP_BARRIER,
 	BLIP_UFO
 };
 
@@ -576,6 +577,7 @@
 	int ox;
 	int oy;
 	int goingleft;
+	int health;
 	AST_LIST_ENTRY(blip) entry;
 };
 
@@ -591,10 +593,27 @@
 /*! Probability of a bomb, out of 100 */
 #define BOMB_PROB   1
 
+static int add_barrier(int x, int y)
+{
+	struct blip *cur = NULL;
+
+	cur = calloc(1,sizeof(struct blip));
+	if(!cur) {
+		return -1;
+	}
+	cur->type=BLIP_BARRIER;
+	cur->x = x;
+	cur->y=max_y - y;
+	cur->health = 1;
+	AST_LIST_INSERT_HEAD(&blips, cur,entry);
+	return 0;
+}
+
 static int init_blips(void)
 {
 	int i, j;
 	struct blip *cur;
+	int offset = 4;
 
 	srandom(time(NULL) + getpid());
 
@@ -622,7 +641,24 @@
 			num_aliens++;
 		}
 	}
-
+	for(i=0; i < 4; i++) {
+		if (i > 0)
+			offset += 5 + ((max_x) -28) / 3;
+		add_barrier(offset + 1, 6);
+		add_barrier(offset + 2, 6);
+		add_barrier(offset + 3, 6);
+
+		add_barrier(offset, 5);
+		add_barrier(offset + 1, 5);
+		add_barrier(offset + 2, 5);
+		add_barrier(offset + 3, 5);
+		add_barrier(offset + 4, 5);
+
+		add_barrier(offset, 4);
+		add_barrier(offset + 1, 4);
+		add_barrier(offset + 3, 4);
+		add_barrier(offset + 4, 4);
+	}
 	return 0;
 }
 
@@ -637,6 +673,8 @@
 		return '|';
 	case BLIP_BOMB:
 		return 'o';
+	case BLIP_BARRIER:
+		return '*';
 	case BLIP_UFO:
 		return '@';
 	default:
@@ -719,9 +757,28 @@
 	return 0;
 }
 
+static int remove_blip(struct blip *blip)
+{
+	if (!blip) {
+		return -1;
+	}
+
+	AST_LIST_REMOVE(&blips, blip, entry);
+
+	if (blip->type == BLIP_ALIEN) {
+		num_aliens--;
+	}
+	wmove(stdscr, blip->oy, blip->ox);
+	waddch(stdscr, ' ');
+	free(blip);
+
+	return 0;
+}
+
 static int move_aliens(void)
 {
 	struct blip *cur;
+	struct blip *current_barrier;
 
 	AST_LIST_TRAVERSE(&blips, cur, entry) {
 		if (cur->type != BLIP_ALIEN) {
@@ -742,6 +799,12 @@
 		/* Alien into the tank == game over */
 		if (cur->x == tank->x && cur->y == tank->y)
 			return 1;
+		AST_LIST_TRAVERSE(&blips, current_barrier, entry){
+			if(current_barrier->type!=BLIP_BARRIER)
+				continue;
+			if(cur->y == current_barrier->y && cur->x == current_barrier -> x)
+				remove_blip(current_barrier);
+		}
 		if (random() % 100 < BOMB_PROB && cur->y != max_y) {
 			struct blip *bomb = calloc(1, sizeof(struct blip));
 			if (!bomb)
@@ -759,13 +822,29 @@
 static int move_bombs(void)
 {
 	struct blip *cur;
+	struct blip *current_barrier;
 
 	AST_LIST_TRAVERSE(&blips, cur, entry) {
+		int mark = 0;
 		if (cur->type != BLIP_BOMB)
 			continue;
 		cur->y++;
-		if (cur->x == tank->x && cur->y == tank->y)
+		if (cur->x == tank->x && cur->y == tank->y) {
 			return 1;
+		}
+
+		AST_LIST_TRAVERSE(&blips, current_barrier, entry) {
+			if (current_barrier->type != BLIP_BARRIER)
+				continue;
+			if (cur->x == current_barrier->x && cur->y == current_barrier->y) {
+				mark = 1;
+				current_barrier->health--;
+				if (current_barrier->health == 0)
+					remove_blip(current_barrier);
+			}
+		}
+		if (mark){
+			remove_blip(cur);}
 	}
 
 	return 0;
@@ -782,23 +861,6 @@
 	}
 }
 
-static int remove_blip(struct blip *blip)
-{
-	if (!blip)
-		return -1;
-
-	AST_LIST_REMOVE(&blips, blip, entry);
-
-	if (blip->type == BLIP_ALIEN)
-		num_aliens--;
-
-	wmove(stdscr, blip->oy, blip->ox);
-	waddch(stdscr, ' ');
-
-	free(blip);
-
-	return 0;
-}
 
 static int ufo_action()
 {
@@ -854,17 +916,16 @@
 static int check_shot(struct blip *shot)
 {
 	struct blip *cur;
+	struct blip *current_barrier;
 
 	AST_LIST_TRAVERSE(&blips, cur, entry) {
-		if (cur->type != BLIP_ALIEN && cur->type != BLIP_UFO)
-			continue;
-		if (cur->x == shot->x && cur->y == shot->y) {
+		if ((cur->type == BLIP_ALIEN || cur->type == BLIP_UFO) && cur->x == shot->x && cur->y == shot->y){
 			if (cur->type == BLIP_UFO) {
 				score += 80;
 			}
 			score += 20;
+			remove_blip(cur);
 			remove_blip(shot);
-			remove_blip(cur);
 			respawn += 1;
 			if (!num_aliens) {
 				if(alien_sleeptime < 101) {
@@ -874,6 +935,14 @@
 					alien_sleeptime = alien_sleeptime - 100;
 					return 1;
 				}
+			}
+			break;
+		}
+		if (cur->type == BLIP_BARRIER) {
+			if (shot->x == cur->x && shot->y == cur->y) {
+				remove_blip(cur);
+				remove_blip(shot);
+				break;
 			}
 		}
 	}




More information about the svn-commits mailing list